From 889e5ed5e2cd6a6862b21293d8d1e7b643f5e391 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 25 Feb 2015 14:36:04 +0100 Subject: [PATCH] fixed path handling on windows --- mix/FileIo.cpp | 47 +++++++++++++++++++----------------- mix/FileIo.h | 1 + mix/qml/NewProjectDialog.qml | 2 ++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mix/FileIo.cpp b/mix/FileIo.cpp index 506715767..78eb6c9da 100644 --- a/mix/FileIo.cpp +++ b/mix/FileIo.cpp @@ -37,21 +37,34 @@ using namespace dev; using namespace dev::crypto; using namespace dev::mix; -void FileIo::makeDir(QString const& _url) +QString FileIo::pathFromUrl(QString const& _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()) dirPath.mkpath(dirPath.path()); } QString FileIo::readFile(QString const& _url) { - QUrl url(_url); - QString path(url.path()); - if (url.scheme() == "qrc") - path = ":" + path; - QFile file(path); + QFile file(pathFromUrl(_url)); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); @@ -65,8 +78,7 @@ QString FileIo::readFile(QString const& _url) void FileIo::writeFile(QString const& _url, QString const& _data) { - QUrl url(_url); - QFile file(url.path()); + QFile file(pathFromUrl(_url)); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&file); @@ -84,9 +96,7 @@ void FileIo::copyFile(QString const& _sourceUrl, QString const& _destUrl) return; } - QUrl sourceUrl(_sourceUrl); - QUrl destUrl(_destUrl); - if (!QFile::copy(sourceUrl.path(), destUrl.path())) + if (!QFile::copy(pathFromUrl(_sourceUrl), pathFromUrl(_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) { - QUrl sourceUrl(_sourceUrl); - QUrl destUrl(_destUrl); - if (!QFile::rename(sourceUrl.path(), destUrl.path())) + if (!QFile::rename(pathFromUrl(_sourceUrl), pathFromUrl(_destUrl))) error(tr("Error moving file %1 to %2").arg(_sourceUrl).arg(_destUrl)); } bool FileIo::fileExists(QString const& _url) { - QUrl url(_url); - QFile file(url.path()); + QFile file(pathFromUrl(_url)); return file.exists(); } QStringList FileIo::makePackage(QString const& _deploymentFolder) { - Json::Value manifest; Json::Value entries(Json::arrayValue); - QUrl folder(_deploymentFolder); - QString path(folder.path()); - QDir deployDir = QDir(path); - + QDir deployDir = QDir(pathFromUrl(_deploymentFolder)); dev::RLPStream rlpStr; int k = 1; std::vector files; diff --git a/mix/FileIo.h b/mix/FileIo.h index 3646627b8..624b1d921 100644 --- a/mix/FileIo.h +++ b/mix/FileIo.h @@ -58,6 +58,7 @@ public: private: QString getHomePath() const; + QString pathFromUrl(QString const& _url); }; } diff --git a/mix/qml/NewProjectDialog.qml b/mix/qml/NewProjectDialog.qml index 4fcb524b2..1ec53e1d9 100644 --- a/mix/qml/NewProjectDialog.qml +++ b/mix/qml/NewProjectDialog.qml @@ -101,6 +101,8 @@ Window { var u = createProjectFileDialog.fileUrl.toString(); if (u.indexOf("file://") == 0) u = u.substring(7, u.length) + if (Qt.platform.os == "windows" && u.indexOf("/") == 0) + u = u.substring(1, u.length); pathField.text = u; } }