Browse Source

Merge pull request #1139 from arkpar/msvc

mix: Fixed path handling on windows
cl-refactor
Arkadiy Paronyan 10 years ago
parent
commit
712d34caea
  1. 47
      mix/FileIo.cpp
  2. 1
      mix/FileIo.h
  3. 2
      mix/qml/NewProjectDialog.qml

47
mix/FileIo.cpp

@ -37,21 +37,34 @@ using namespace dev;
using namespace dev::crypto; using namespace dev::crypto;
using namespace dev::mix; using namespace dev::mix;
void FileIo::makeDir(QString const& _url) QString FileIo::pathFromUrl(QString const& _url)
{ {
QUrl url(_url); QUrl url(_url);
QDir dirPath(url.path()); QString path(url.path());
if (url.scheme() == "qrc")
path = ":" + path;
#ifdef WIN32
if (url.scheme() == "file")
{
if (path.startsWith("/"))
path = path.right(path.length() - 1);
if (!url.host().isEmpty())
path = url.host() + ":/" + path;
}
#endif
return path;
}
void FileIo::makeDir(QString const& _url)
{
QDir dirPath(pathFromUrl(_url));
if (!dirPath.exists()) if (!dirPath.exists())
dirPath.mkpath(dirPath.path()); dirPath.mkpath(dirPath.path());
} }
QString FileIo::readFile(QString const& _url) QString FileIo::readFile(QString const& _url)
{ {
QUrl url(_url); QFile file(pathFromUrl(_url));
QString path(url.path());
if (url.scheme() == "qrc")
path = ":" + path;
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QTextStream stream(&file); QTextStream stream(&file);
@ -65,8 +78,7 @@ QString FileIo::readFile(QString const& _url)
void FileIo::writeFile(QString const& _url, QString const& _data) void FileIo::writeFile(QString const& _url, QString const& _data)
{ {
QUrl url(_url); QFile file(pathFromUrl(_url));
QFile file(url.path());
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
QTextStream stream(&file); QTextStream stream(&file);
@ -84,9 +96,7 @@ void FileIo::copyFile(QString const& _sourceUrl, QString const& _destUrl)
return; return;
} }
QUrl sourceUrl(_sourceUrl); if (!QFile::copy(pathFromUrl(_sourceUrl), pathFromUrl(_destUrl)))
QUrl destUrl(_destUrl);
if (!QFile::copy(sourceUrl.path(), destUrl.path()))
error(tr("Error copying file %1 to %2").arg(_sourceUrl).arg(_destUrl)); error(tr("Error copying file %1 to %2").arg(_sourceUrl).arg(_destUrl));
} }
@ -97,29 +107,22 @@ QString FileIo::getHomePath() const
void FileIo::moveFile(QString const& _sourceUrl, QString const& _destUrl) void FileIo::moveFile(QString const& _sourceUrl, QString const& _destUrl)
{ {
QUrl sourceUrl(_sourceUrl); if (!QFile::rename(pathFromUrl(_sourceUrl), pathFromUrl(_destUrl)))
QUrl destUrl(_destUrl);
if (!QFile::rename(sourceUrl.path(), destUrl.path()))
error(tr("Error moving file %1 to %2").arg(_sourceUrl).arg(_destUrl)); error(tr("Error moving file %1 to %2").arg(_sourceUrl).arg(_destUrl));
} }
bool FileIo::fileExists(QString const& _url) bool FileIo::fileExists(QString const& _url)
{ {
QUrl url(_url); QFile file(pathFromUrl(_url));
QFile file(url.path());
return file.exists(); return file.exists();
} }
QStringList FileIo::makePackage(QString const& _deploymentFolder) QStringList FileIo::makePackage(QString const& _deploymentFolder)
{ {
Json::Value manifest; Json::Value manifest;
Json::Value entries(Json::arrayValue); Json::Value entries(Json::arrayValue);
QUrl folder(_deploymentFolder); QDir deployDir = QDir(pathFromUrl(_deploymentFolder));
QString path(folder.path());
QDir deployDir = QDir(path);
dev::RLPStream rlpStr; dev::RLPStream rlpStr;
int k = 1; int k = 1;
std::vector<bytes> files; std::vector<bytes> files;

1
mix/FileIo.h

@ -58,6 +58,7 @@ public:
private: private:
QString getHomePath() const; QString getHomePath() const;
QString pathFromUrl(QString const& _url);
}; };
} }

2
mix/qml/NewProjectDialog.qml

@ -101,6 +101,8 @@ Window {
var u = createProjectFileDialog.fileUrl.toString(); var u = createProjectFileDialog.fileUrl.toString();
if (u.indexOf("file://") == 0) if (u.indexOf("file://") == 0)
u = u.substring(7, u.length) u = u.substring(7, u.length)
if (Qt.platform.os == "windows" && u.indexOf("/") == 0)
u = u.substring(1, u.length);
pathField.text = u; pathField.text = u;
} }
} }

Loading…
Cancel
Save