diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 80ef5bc5ff3b7b1a45729fd765f461946a29cc40..ef3b5c5e7788aad08bf9cdfea78fc22509b6fa3a 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -38,6 +38,10 @@ #include <QDateTime> #include <QMessageBox> +#ifdef Q_OS_WIN +#include <qt_windows.h> +#endif + namespace Utils { /*! \class Utils::FileUtils @@ -237,6 +241,60 @@ bool FileUtils::makeWritable(const FileName &path) return QFile::setPermissions(fileName, QFile::permissions(fileName) | QFile::WriteUser); } +#ifdef Q_OS_WIN +static QString getShortPathName(const QString &name) +{ + if (name.isEmpty()) + return name; + + // Determine length, then convert. + const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW + const DWORD length = GetShortPathNameW(nameC, NULL, 0); + if (length == 0) + return name; + QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]); + GetShortPathNameW(nameC, buffer.data(), length); + const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1); + return rc; +} + +static QString getLongPathName(const QString &name) +{ + if (name.isEmpty()) + return name; + + // Determine length, then convert. + const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW + const DWORD length = GetLongPathNameW(nameC, NULL, 0); + if (length == 0) + return name; + QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]); + GetLongPathNameW(nameC, buffer.data(), length); + const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1); + return rc; +} +#endif // Q_OS_WIN + +// makes sure that capitalization of directories is canonical on Windows. +// This mimics the logic in QDeclarative_isFileCaseCorrect +QString FileUtils::normalizePathName(const QString &name) +{ +#ifdef Q_OS_WIN + QString canonicalName = getShortPathName(name); + if (canonicalName.isEmpty()) + return name; + canonicalName = getLongPathName(canonicalName); + if (canonicalName.isEmpty()) + return name; + // Upper case drive letter + if (canonicalName.size() > 2 && canonicalName.at(1) == QLatin1Char(':')) + canonicalName[0] = canonicalName.at(0).toUpper(); + return canonicalName; +#else // Filesystem is case-insensitive only on Windows + return name; +#endif +} + QByteArray FileReader::fetchQrc(const QString &fileName) { QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray()); diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h index 0cf1db64b1812088cd16130cef2935812bda18a9..0b19a913fbd1262a0c011ef474d681311915f5fd 100644 --- a/src/libs/utils/fileutils.h +++ b/src/libs/utils/fileutils.h @@ -98,6 +98,7 @@ public: static QString shortNativePath(const FileName &path); static QString fileSystemFriendlyName(const QString &name); static bool makeWritable(const FileName &path); + static QString normalizePathName(const QString &name); }; class QTCREATOR_UTILS_EXPORT FileReader diff --git a/src/libs/utils/winutils.cpp b/src/libs/utils/winutils.cpp index cf54a24d4f359f2c57b5f285fa0ae043265a0bf9..59daad82df95d52ad5dbc0435d9b0903332b2fe8 100644 --- a/src/libs/utils/winutils.cpp +++ b/src/libs/utils/winutils.cpp @@ -129,54 +129,6 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t, return rc; } -QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name) -{ - if (name.isEmpty()) - return name; - - // Determine length, then convert. - const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW - const DWORD length = GetShortPathNameW(nameC, NULL, 0); - if (length == 0) - return name; - QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]); - GetShortPathNameW(nameC, buffer.data(), length); - const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1); - return rc; -} - -QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name) -{ - if (name.isEmpty()) - return name; - - // Determine length, then convert. - const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW - const DWORD length = GetLongPathNameW(nameC, NULL, 0); - if (length == 0) - return name; - QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]); - GetLongPathNameW(nameC, buffer.data(), length); - const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1); - return rc; -} - -// makes sure that capitalization of directories is canonical. -// This mimics the logic in QDeclarative_isFileCaseCorrect -QTCREATOR_UTILS_EXPORT QString normalizePathName(const QString &name) -{ - QString canonicalName = getShortPathName(name); - if (canonicalName.isEmpty()) - return name; - canonicalName = getLongPathName(canonicalName); - if (canonicalName.isEmpty()) - return name; - // Upper case drive letter - if (canonicalName.size() > 2 && canonicalName.at(1) == QLatin1Char(':')) - canonicalName[0] = canonicalName.at(0).toUpper(); - return canonicalName; -} - QTCREATOR_UTILS_EXPORT bool winIs64BitSystem() { SYSTEM_INFO systemInfo; diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index ff69f7746ae7aeeb735889efc4058c2673ff3b39..b72064503263f27620899afefe94229068a3e6df 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -51,11 +51,9 @@ #include <coreplugin/vcsmanager.h> #include <cppeditor/cppeditorconstants.h> +#include <utils/fileutils.h> #include <utils/hostosinfo.h> #include <utils/qtcassert.h> -#ifdef Q_OS_WIN -#include <utils/winutils.h> -#endif #include <QtPlugin> #include <QFileInfo> @@ -352,11 +350,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) foreach (const QString &candidateDir, candidateDirs) { foreach (const QString &candidateFileName, candidateFileNames) { const QString candidateFilePath = candidateDir + QLatin1Char('/') + candidateFileName; -#ifdef Q_OS_WIN - const QString normalized = Utils::normalizePathName(candidateFilePath); -#else - const QString normalized = candidateFilePath; -#endif + const QString normalized = Utils::FileUtils::normalizePathName(candidateFilePath); const QFileInfo candidateFi(normalized); if (candidateFi.isFile()) { m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath(); diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 52331b4e185ca39907c95d8712a9bf12551f896b..5376b4c9143d15d5b51e60b47fba9a998a6334ec 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -2879,11 +2879,7 @@ CdbEngine::NormalizedSourceFileName CdbEngine::sourceMapNormalizeFileNameFromDeb const QString fileName = cdbSourcePathMapping(QDir::toNativeSeparators(f), m_sourcePathMappings, DebuggerToSource); // Up/lower case normalization according to Windows. -#ifdef Q_OS_WIN - QString normalized = Utils::normalizePathName(fileName); -#else - QString normalized = fileName; -#endif + const QString normalized = Utils::FileUtils::normalizePathName(fileName); if (debugSourceMapping) qDebug(" sourceMapNormalizeFileNameFromDebugger %s->%s", qPrintable(fileName), qPrintable(normalized)); // Check if it really exists, that is normalize worked and QFileInfo confirms it. diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index a7d33fdb5ec3173eca4352de7d847807890980c3..74a1d7efbf8f9152333bc1510b15ed15d20fccdf 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -43,7 +43,6 @@ #ifdef Q_OS_WIN # include "shared/peutils.h" -# include <utils/winutils.h> #endif #include <projectexplorer/localapplicationrunconfiguration.h> // For LocalApplication* @@ -55,6 +54,7 @@ #include <projectexplorer/taskhub.h> #include <utils/checkablemessagebox.h> +#include <utils/fileutils.h> #include <utils/qtcassert.h> #include <utils/qtcprocess.h> #include <coreplugin/icore.h> @@ -344,12 +344,9 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu if (!fillParameters(&sp, kit, errorMessage)) return sp; sp.environment = environment->environment(); - sp.workingDirectory = rc->workingDirectory(); -#if defined(Q_OS_WIN) - // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) - sp.workingDirectory = normalizePathName(sp.workingDirectory); -#endif + // Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...) + sp.workingDirectory = FileUtils::normalizePathName(rc->workingDirectory()); sp.executable = rc->executable(); if (sp.executable.isEmpty()) diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index a3667fbeceb2d9d54fec7f5b77fa5b7bd38af14d..e04b94731d85aec9b1220794e937b10b8b58ba19 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -35,10 +35,8 @@ #include <coreplugin/icore.h> #include <utils/consoleprocess.h> +#include <utils/fileutils.h> #include <utils/qtcprocess.h> -#ifdef Q_OS_WIN -#include <utils/winutils.h> -#endif #include <QTextCodec> @@ -131,19 +129,10 @@ ApplicationLauncher::~ApplicationLauncher() void ApplicationLauncher::setWorkingDirectory(const QString &dir) { -#ifdef Q_OS_WIN // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) - const QString fixedPath = Utils::normalizePathName(dir); -#else -# define fixedPath dir -#endif - + const QString fixedPath = Utils::FileUtils::normalizePathName(dir); d->m_guiProcess.setWorkingDirectory(fixedPath); d->m_consoleProcess.setWorkingDirectory(fixedPath); - -#ifndef Q_OS_WIN -# undef fixedPath -#endif } void ApplicationLauncher::setEnvironment(const Utils::Environment &env) diff --git a/src/plugins/projectexplorer/msvcparser.cpp b/src/plugins/projectexplorer/msvcparser.cpp index 0bc41b7b842b7184b036f2747c01ee7e934bb929..653d9e30f7c4baa10439e2db38e634aad9ad4d06 100644 --- a/src/plugins/projectexplorer/msvcparser.cpp +++ b/src/plugins/projectexplorer/msvcparser.cpp @@ -31,9 +31,7 @@ #include "projectexplorerconstants.h" #include <utils/qtcassert.h> -#ifdef Q_OS_WIN -#include <utils/winutils.h> -#endif +#include <utils/fileutils.h> static const char FILE_POS_PATTERN[] = "(cl|LINK|.+) : "; static const char ERROR_PATTERN[] = "[A-Z]+\\d\\d\\d\\d ?:"; @@ -58,11 +56,7 @@ static QPair<Utils::FileName, int> parseFileName(const QString &input) } } } -#ifdef Q_OS_WIN - const QString normalized = Utils::normalizePathName(fileName); -#else - const QString normalized = fileName; -#endif + const QString normalized = Utils::FileUtils::normalizePathName(fileName); return qMakePair(Utils::FileName::fromUserInput(normalized), linenumber); } diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp index db71fccfa868bb2072c5a683534831981229fba3..fa2b24a99590cdb426f2a1f58e370467a733710f 100644 --- a/src/plugins/projectexplorer/projectwelcomepage.cpp +++ b/src/plugins/projectexplorer/projectwelcomepage.cpp @@ -29,8 +29,6 @@ #include "projectwelcomepage.h" -#include <utils/stringutils.h> - #include <QQmlContext> #include <QQmlEngine> #include <QFileInfo> @@ -42,9 +40,8 @@ #include <projectexplorer/projectexplorer.h> #include <projectexplorer/sessiondialog.h> -#ifdef Q_OS_WIN -#include <utils/winutils.h> -#endif +#include <utils/fileutils.h> +#include <utils/stringutils.h> namespace ProjectExplorer { namespace Internal { @@ -225,12 +222,9 @@ void ProjectWelcomePage::facilitateQml(QQmlEngine *engine) QUrl ProjectWelcomePage::pageLocation() const { - QString resourcePath = Core::ICore::resourcePath(); -#ifdef Q_OS_WIN // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows - resourcePath = Utils::normalizePathName(resourcePath); -#endif - return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/develop.qml")); + const QString resourcePath = Utils::FileUtils::normalizePathName(Core::ICore::resourcePath()); + return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/develop.qml")); } ProjectWelcomePage::Id ProjectWelcomePage::id() const diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 05b2511778b71fed3206a28e1b3729c5d3dfe987..67376a966b9d3a32e3fb52585fd6886e7493f758 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -44,9 +44,7 @@ #include <qmljs/qmljssimplereader.h> -#ifdef Q_OS_WIN -#include <utils/winutils.h> -#endif +#include <utils/fileutils.h> enum { debug = false @@ -95,12 +93,8 @@ static QObject *variantToQObject(const QVariant &value) static QString applicationDirPath() { -#ifdef Q_OS_WIN // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows - return Utils::normalizePathName(QCoreApplication::applicationDirPath()); -#else - return QCoreApplication::applicationDirPath(); -#endif + return Utils::FileUtils::normalizePathName(QCoreApplication::applicationDirPath()); } #ifdef Q_OS_MAC diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index f133d802b9d83959edd8179329c46c4beeda81c7..2d17f24d5b07e92ea5e234f9cb5de49331e1d9b9 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -37,11 +37,13 @@ #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/icore.h> #include <projectexplorer/target.h> -#include <utils/qtcprocess.h> #include <qtsupport/qtkitinformation.h> #include <qtsupport/qtoutputformatter.h> #include <qtsupport/qtsupportconstants.h> +#include <utils/fileutils.h> +#include <utils/qtcprocess.h> + #ifdef Q_OS_WIN #include <utils/winutils.h> #endif @@ -159,13 +161,7 @@ QString QmlProjectRunConfiguration::workingDirectory() const is exactly like the capitalization on disk.*/ QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName) { - QString canonicalPath = QFileInfo(fileName).canonicalFilePath(); - -#if defined(Q_OS_WIN) - canonicalPath = Utils::normalizePathName(canonicalPath); -#endif - - return canonicalPath; + return Utils::FileUtils::normalizePathName(QFileInfo(fileName).canonicalFilePath()); } diff --git a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp index a514b0d3b0b8e78b33886f4001b0c25bceff0d3c..54d4ea1123daa73877c824ec491e45afe292b2cc 100644 --- a/src/plugins/qtsupport/gettingstartedwelcomepage.cpp +++ b/src/plugins/qtsupport/gettingstartedwelcomepage.cpp @@ -241,11 +241,8 @@ QString ExamplesWelcomePage::title() const QUrl ExamplesWelcomePage::pageLocation() const { - QString resourcePath = Core::ICore::resourcePath(); -#ifdef Q_OS_WIN // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows - resourcePath = Utils::normalizePathName(resourcePath); -#endif + const QString resourcePath = Utils::FileUtils::normalizePathName(Core::ICore::resourcePath()); if (m_showExamples) return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/examples.qml")); else diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index 202645a5d4384e7e28fe4b65a61f929e41db02c0..da1aa21fb38c70248ee8dbf03c85e3e701828451 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -40,6 +40,7 @@ #include <projectexplorer/projectexplorer.h> +#include <utils/fileutils.h> #include <utils/hostosinfo.h> #include <utils/styledbar.h> #include <utils/iwelcomepage.h> @@ -208,22 +209,14 @@ void WelcomeMode::facilitateQml(QQmlEngine * /*engine*/) static QString applicationDirPath() { -#ifdef Q_OS_WIN // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows - return Utils::normalizePathName(QCoreApplication::applicationDirPath()); -#else - return QCoreApplication::applicationDirPath(); -#endif + return Utils::FileUtils::normalizePathName(QCoreApplication::applicationDirPath()); } static QString resourcePath() { -#ifdef Q_OS_WIN // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows - return Utils::normalizePathName(Core::ICore::resourcePath()); -#else - return Core::ICore::resourcePath(); -#endif + return Utils::FileUtils::normalizePathName(Core::ICore::resourcePath()); } void WelcomeMode::initPlugins()