# # # patch "src/util/Platform.cpp" # from [cc0eeb3a58a73ae489790b8190b4e3e9efaae15a] # to [7f879b0a786869e1df2472adcc6136e252ceca8b] # # patch "src/util/Platform.h" # from [7f8f1005a264dc6ab04856b6ff944d59897486eb] # to [62d37fa2758d2e842282e5d5daceba20e8fb49b6] # ============================================================ --- src/util/Platform.cpp cc0eeb3a58a73ae489790b8190b4e3e9efaae15a +++ src/util/Platform.cpp 7f879b0a786869e1df2472adcc6136e252ceca8b @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef Q_WS_WIN #include @@ -228,3 +229,53 @@ QString Platform::getUsername() return username; } +bool Platform::mkpath(const QString & path) +{ + if (path.indexOf(QRegExp("(^|[\\/])\\.\\.([\\/]|$)")) != -1) + { + W("no support for relative paths"); + return false; + } + + // default to the application's current directory if we get a + // relative filename on all platforms + QString prefixPath(QDir::currentPath()); + QString actualPath(path); + +#ifdef Q_WS_WIN + if (path.left(2) == "\\\\") + { + W("UNC paths are not supported"); + return false; + } + if (path.mid(1, 2) == ":\\" || path.mid(1, 2) == ":/") + { + actualPath = path.mid(3); + prefixPath = path.left(3).replace('\\', '/').toUpper(); + bool driveFound = false; + foreach (QFileInfo drive, QDir::drives()) + { + if (prefixPath == drive.absolutePath()) + { + driveFound = true; + break; + } + } + if (!driveFound) + { + W(QString("drive %1 not found").arg(prefixPath)); + return false; + } + } +#else + if (path.left(1) == "/") + { + prefixPath = "/"; + actualPath = path.mid(1); + } +#endif + + QDir dir(prefixPath); + return dir.mkpath(actualPath); +} + ============================================================ --- src/util/Platform.h 7f8f1005a264dc6ab04856b6ff944d59897486eb +++ src/util/Platform.h 62d37fa2758d2e842282e5d5daceba20e8fb49b6 @@ -33,6 +33,10 @@ public: * Returns the name of the currently logged in user of the system */ static QString getUsername(); + /** + * Creates all unknown directries along the given path + */ + static bool mkpath(const QString & path); }; #endif