summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-10-23 22:07:46 +0300
committerOrgad Shaneh <orgads@gmail.com>2013-10-24 10:38:36 +0200
commit4de3b9484051483f6f0329f1ec0c3feef325045c (patch)
treeee0c140cfc40fa45b0ea5c1213dd5e03213fc489
parentbc81930f17f5fe897fd0ede57169a52751b72f73 (diff)
downloadqt-creator-4de3b9484051483f6f0329f1ec0c3feef325045c.tar.gz
Crossify normalizePathName
Denoise usages get{Short|Long}PathName are now static. They're not used anywhere except in normalizePathName. Change-Id: Ief277b6d828faadd98ec7faa39dd682bfaa8805f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
-rw-r--r--src/libs/utils/fileutils.cpp58
-rw-r--r--src/libs/utils/fileutils.h1
-rw-r--r--src/libs/utils/winutils.cpp48
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.cpp10
-rw-r--r--src/plugins/debugger/cdb/cdbengine.cpp6
-rw-r--r--src/plugins/debugger/debuggerrunner.cpp9
-rw-r--r--src/plugins/projectexplorer/applicationlauncher.cpp15
-rw-r--r--src/plugins/projectexplorer/msvcparser.cpp10
-rw-r--r--src/plugins/projectexplorer/projectwelcomepage.cpp14
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp10
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp12
-rw-r--r--src/plugins/qtsupport/gettingstartedwelcomepage.cpp5
-rw-r--r--src/plugins/welcome/welcomeplugin.cpp13
13 files changed, 83 insertions, 128 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index 80ef5bc5ff..ef3b5c5e77 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 0cf1db64b1..0b19a913fb 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 cf54a24d4f..59daad82df 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 ff69f7746a..b720645032 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 52331b4e18..5376b4c914 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 a7d33fdb5e..74a1d7efbf 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 a3667fbece..e04b94731d 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 0bc41b7b84..653d9e30f7 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 db71fccfa8..fa2b24a995 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 05b2511778..67376a966b 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 f133d802b9..2d17f24d5b 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 a514b0d3b0..54d4ea1123 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 202645a5d4..da1aa21fb3 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()