forked from qt-creator/qt-creator
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:
committed by
Orgad Shaneh
parent
bc81930f17
commit
4de3b94840
@@ -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());
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
|
@@ -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.
|
||||
|
@@ -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())
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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,11 +222,8 @@ 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
|
||||
const QString resourcePath = Utils::FileUtils::normalizePathName(Core::ICore::resourcePath());
|
||||
return QUrl::fromLocalFile(resourcePath + QLatin1String("/welcomescreen/develop.qml"));
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user