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>
This commit is contained in:
Orgad Shaneh
2013-10-23 22:07:46 +03:00
committed by Orgad Shaneh
parent bc81930f17
commit 4de3b94840
13 changed files with 83 additions and 128 deletions

View File

@@ -38,6 +38,10 @@
#include <QDateTime> #include <QDateTime>
#include <QMessageBox> #include <QMessageBox>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
namespace Utils { namespace Utils {
/*! \class Utils::FileUtils /*! \class Utils::FileUtils
@@ -237,6 +241,60 @@ bool FileUtils::makeWritable(const FileName &path)
return QFile::setPermissions(fileName, QFile::permissions(fileName) | QFile::WriteUser); 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) QByteArray FileReader::fetchQrc(const QString &fileName)
{ {
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray()); QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray());

View File

@@ -98,6 +98,7 @@ public:
static QString shortNativePath(const FileName &path); static QString shortNativePath(const FileName &path);
static QString fileSystemFriendlyName(const QString &name); static QString fileSystemFriendlyName(const QString &name);
static bool makeWritable(const FileName &path); static bool makeWritable(const FileName &path);
static QString normalizePathName(const QString &name);
}; };
class QTCREATOR_UTILS_EXPORT FileReader class QTCREATOR_UTILS_EXPORT FileReader

View File

@@ -129,54 +129,6 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
return rc; 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() QTCREATOR_UTILS_EXPORT bool winIs64BitSystem()
{ {
SYSTEM_INFO systemInfo; SYSTEM_INFO systemInfo;

View File

@@ -51,11 +51,9 @@
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#ifdef Q_OS_WIN
#include <utils/winutils.h>
#endif
#include <QtPlugin> #include <QtPlugin>
#include <QFileInfo> #include <QFileInfo>
@@ -352,11 +350,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
foreach (const QString &candidateDir, candidateDirs) { foreach (const QString &candidateDir, candidateDirs) {
foreach (const QString &candidateFileName, candidateFileNames) { foreach (const QString &candidateFileName, candidateFileNames) {
const QString candidateFilePath = candidateDir + QLatin1Char('/') + candidateFileName; const QString candidateFilePath = candidateDir + QLatin1Char('/') + candidateFileName;
#ifdef Q_OS_WIN const QString normalized = Utils::FileUtils::normalizePathName(candidateFilePath);
const QString normalized = Utils::normalizePathName(candidateFilePath);
#else
const QString normalized = candidateFilePath;
#endif
const QFileInfo candidateFi(normalized); const QFileInfo candidateFi(normalized);
if (candidateFi.isFile()) { if (candidateFi.isFile()) {
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath(); m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();

View File

@@ -2879,11 +2879,7 @@ CdbEngine::NormalizedSourceFileName CdbEngine::sourceMapNormalizeFileNameFromDeb
const QString fileName = cdbSourcePathMapping(QDir::toNativeSeparators(f), m_sourcePathMappings, const QString fileName = cdbSourcePathMapping(QDir::toNativeSeparators(f), m_sourcePathMappings,
DebuggerToSource); DebuggerToSource);
// Up/lower case normalization according to Windows. // Up/lower case normalization according to Windows.
#ifdef Q_OS_WIN const QString normalized = Utils::FileUtils::normalizePathName(fileName);
QString normalized = Utils::normalizePathName(fileName);
#else
QString normalized = fileName;
#endif
if (debugSourceMapping) if (debugSourceMapping)
qDebug(" sourceMapNormalizeFileNameFromDebugger %s->%s", qPrintable(fileName), qPrintable(normalized)); qDebug(" sourceMapNormalizeFileNameFromDebugger %s->%s", qPrintable(fileName), qPrintable(normalized));
// Check if it really exists, that is normalize worked and QFileInfo confirms it. // Check if it really exists, that is normalize worked and QFileInfo confirms it.

View File

@@ -43,7 +43,6 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# include "shared/peutils.h" # include "shared/peutils.h"
# include <utils/winutils.h>
#endif #endif
#include <projectexplorer/localapplicationrunconfiguration.h> // For LocalApplication* #include <projectexplorer/localapplicationrunconfiguration.h> // For LocalApplication*
@@ -55,6 +54,7 @@
#include <projectexplorer/taskhub.h> #include <projectexplorer/taskhub.h>
#include <utils/checkablemessagebox.h> #include <utils/checkablemessagebox.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -344,12 +344,9 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
if (!fillParameters(&sp, kit, errorMessage)) if (!fillParameters(&sp, kit, errorMessage))
return sp; return sp;
sp.environment = environment->environment(); sp.environment = environment->environment();
sp.workingDirectory = rc->workingDirectory();
#if defined(Q_OS_WIN) // Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...)
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) sp.workingDirectory = FileUtils::normalizePathName(rc->workingDirectory());
sp.workingDirectory = normalizePathName(sp.workingDirectory);
#endif
sp.executable = rc->executable(); sp.executable = rc->executable();
if (sp.executable.isEmpty()) if (sp.executable.isEmpty())

View File

@@ -35,10 +35,8 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/consoleprocess.h> #include <utils/consoleprocess.h>
#include <utils/fileutils.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#ifdef Q_OS_WIN
#include <utils/winutils.h>
#endif
#include <QTextCodec> #include <QTextCodec>
@@ -131,19 +129,10 @@ ApplicationLauncher::~ApplicationLauncher()
void ApplicationLauncher::setWorkingDirectory(const QString &dir) void ApplicationLauncher::setWorkingDirectory(const QString &dir)
{ {
#ifdef Q_OS_WIN
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
const QString fixedPath = Utils::normalizePathName(dir); const QString fixedPath = Utils::FileUtils::normalizePathName(dir);
#else
# define fixedPath dir
#endif
d->m_guiProcess.setWorkingDirectory(fixedPath); d->m_guiProcess.setWorkingDirectory(fixedPath);
d->m_consoleProcess.setWorkingDirectory(fixedPath); d->m_consoleProcess.setWorkingDirectory(fixedPath);
#ifndef Q_OS_WIN
# undef fixedPath
#endif
} }
void ApplicationLauncher::setEnvironment(const Utils::Environment &env) void ApplicationLauncher::setEnvironment(const Utils::Environment &env)

View File

@@ -31,9 +31,7 @@
#include "projectexplorerconstants.h" #include "projectexplorerconstants.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#ifdef Q_OS_WIN #include <utils/fileutils.h>
#include <utils/winutils.h>
#endif
static const char FILE_POS_PATTERN[] = "(cl|LINK|.+) : "; static const char FILE_POS_PATTERN[] = "(cl|LINK|.+) : ";
static const char ERROR_PATTERN[] = "[A-Z]+\\d\\d\\d\\d ?:"; 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::FileUtils::normalizePathName(fileName);
const QString normalized = Utils::normalizePathName(fileName);
#else
const QString normalized = fileName;
#endif
return qMakePair(Utils::FileName::fromUserInput(normalized), linenumber); return qMakePair(Utils::FileName::fromUserInput(normalized), linenumber);
} }

View File

@@ -29,8 +29,6 @@
#include "projectwelcomepage.h" #include "projectwelcomepage.h"
#include <utils/stringutils.h>
#include <QQmlContext> #include <QQmlContext>
#include <QQmlEngine> #include <QQmlEngine>
#include <QFileInfo> #include <QFileInfo>
@@ -42,9 +40,8 @@
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/sessiondialog.h> #include <projectexplorer/sessiondialog.h>
#ifdef Q_OS_WIN #include <utils/fileutils.h>
#include <utils/winutils.h> #include <utils/stringutils.h>
#endif
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { namespace Internal {
@@ -225,11 +222,8 @@ void ProjectWelcomePage::facilitateQml(QQmlEngine *engine)
QUrl ProjectWelcomePage::pageLocation() const 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 // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
resourcePath = Utils::normalizePathName(resourcePath); const QString resourcePath = Utils::FileUtils::normalizePathName(Core::ICore::resourcePath());
#endif
return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/develop.qml")); return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/develop.qml"));
} }

View File

@@ -44,9 +44,7 @@
#include <qmljs/qmljssimplereader.h> #include <qmljs/qmljssimplereader.h>
#ifdef Q_OS_WIN #include <utils/fileutils.h>
#include <utils/winutils.h>
#endif
enum { enum {
debug = false debug = false
@@ -95,12 +93,8 @@ static QObject *variantToQObject(const QVariant &value)
static QString applicationDirPath() static QString applicationDirPath()
{ {
#ifdef Q_OS_WIN
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
return Utils::normalizePathName(QCoreApplication::applicationDirPath()); return Utils::FileUtils::normalizePathName(QCoreApplication::applicationDirPath());
#else
return QCoreApplication::applicationDirPath();
#endif
} }
#ifdef Q_OS_MAC #ifdef Q_OS_MAC

View File

@@ -37,11 +37,13 @@
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/qtcprocess.h>
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtoutputformatter.h> #include <qtsupport/qtoutputformatter.h>
#include <qtsupport/qtsupportconstants.h> #include <qtsupport/qtsupportconstants.h>
#include <utils/fileutils.h>
#include <utils/qtcprocess.h>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <utils/winutils.h> #include <utils/winutils.h>
#endif #endif
@@ -159,13 +161,7 @@ QString QmlProjectRunConfiguration::workingDirectory() const
is exactly like the capitalization on disk.*/ is exactly like the capitalization on disk.*/
QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName) QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName)
{ {
QString canonicalPath = QFileInfo(fileName).canonicalFilePath(); return Utils::FileUtils::normalizePathName(QFileInfo(fileName).canonicalFilePath());
#if defined(Q_OS_WIN)
canonicalPath = Utils::normalizePathName(canonicalPath);
#endif
return canonicalPath;
} }

View File

@@ -241,11 +241,8 @@ QString ExamplesWelcomePage::title() const
QUrl ExamplesWelcomePage::pageLocation() 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 // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
resourcePath = Utils::normalizePathName(resourcePath); const QString resourcePath = Utils::FileUtils::normalizePathName(Core::ICore::resourcePath());
#endif
if (m_showExamples) if (m_showExamples)
return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/examples.qml")); return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/examples.qml"));
else else

View File

@@ -40,6 +40,7 @@
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <utils/iwelcomepage.h> #include <utils/iwelcomepage.h>
@@ -208,22 +209,14 @@ void WelcomeMode::facilitateQml(QQmlEngine * /*engine*/)
static QString applicationDirPath() static QString applicationDirPath()
{ {
#ifdef Q_OS_WIN
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
return Utils::normalizePathName(QCoreApplication::applicationDirPath()); return Utils::FileUtils::normalizePathName(QCoreApplication::applicationDirPath());
#else
return QCoreApplication::applicationDirPath();
#endif
} }
static QString resourcePath() static QString resourcePath()
{ {
#ifdef Q_OS_WIN
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
return Utils::normalizePathName(Core::ICore::resourcePath()); return Utils::FileUtils::normalizePathName(Core::ICore::resourcePath());
#else
return Core::ICore::resourcePath();
#endif
} }
void WelcomeMode::initPlugins() void WelcomeMode::initPlugins()