From 2c4ae8c1b855021cdf92b8f3604a30ce07899b5b Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 5 Jan 2011 14:44:52 +0100 Subject: [PATCH] QmlProject: Fix compilation on cygwin Move use of windows API to winutils. --- src/libs/utils/winutils.cpp | 33 +++++++++++++++++++ src/libs/utils/winutils.h | 6 ++++ .../qmlprojectrunconfiguration.cpp | 24 ++++++-------- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/libs/utils/winutils.cpp b/src/libs/utils/winutils.cpp index b4cbf6bc403..098ea63fd54 100644 --- a/src/libs/utils/winutils.cpp +++ b/src/libs/utils/winutils.cpp @@ -165,6 +165,39 @@ QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name, QString *er return rc; } +QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name, QString *errorMessage) +{ + typedef DWORD (APIENTRY *GetLongPathNameProtoType)(LPCTSTR, LPTSTR, DWORD); + + if (name.isEmpty()) + return name; + + const char *kernel32DLLC = "kernel32.dll"; + + QLibrary kernel32Lib(kernel32DLLC, 0); + if (!kernel32Lib.isLoaded() && !kernel32Lib.load()) { + *errorMessage = msgCannotLoad(kernel32DLLC, kernel32Lib.errorString()); + return QString(); + } + + // MinGW requires old-style casts + GetLongPathNameProtoType getLongPathNameW = (GetLongPathNameProtoType)(kernel32Lib.resolve("GetLongPathNameW")); + if (!getLongPathNameW) { + *errorMessage = msgCannotResolve(kernel32DLLC); + return QString(); + } + // Determine length, then convert. + const LPCTSTR nameC = reinterpret_cast(name.utf16()); // MinGW + const DWORD length = (*getLongPathNameW)(nameC, NULL, 0); + if (length == 0) + return name; + TCHAR *buffer = new TCHAR[length]; + (*getLongPathNameW)(nameC, buffer, length); + const QString rc = QString::fromUtf16(reinterpret_cast(buffer), length); + delete [] buffer; + return rc; +} + QTCREATOR_UTILS_EXPORT unsigned long winQPidToPid(const Q_PID qpid) { const PROCESS_INFORMATION *processInfo = reinterpret_cast(qpid); diff --git a/src/libs/utils/winutils.h b/src/libs/utils/winutils.h index 3ad9eabf5c8..2c235d25695 100644 --- a/src/libs/utils/winutils.h +++ b/src/libs/utils/winutils.h @@ -58,6 +58,10 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t, QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name, QString *errorMessage); +// Returns long name +QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name, + QString *errorMessage); + QTCREATOR_UTILS_EXPORT unsigned long winQPidToPid(const Q_PID qpid); QTCREATOR_UTILS_EXPORT bool winIs64BitSystem(); @@ -65,5 +69,7 @@ QTCREATOR_UTILS_EXPORT bool winIs64BitSystem(); // Check for a 64bit binary. QTCREATOR_UTILS_EXPORT bool winIs64BitBinary(const QString &binary); + + } // namespace Utils #endif // WINUTILS_H diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index 9f5a4687f9e..6438bbd2772 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -46,7 +46,7 @@ #include #ifdef Q_OS_WIN32 -#include +#include #endif using Core::EditorManager; @@ -69,7 +69,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(QmlProjectTarget *parent) { ctor(); updateQtVersions(); -} +} QmlProjectRunConfiguration::QmlProjectRunConfiguration(QmlProjectTarget *parent, QmlProjectRunConfiguration *source) : @@ -186,18 +186,14 @@ QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName) QString canonicalPath = QFileInfo(fileName).canonicalFilePath(); #if defined(Q_OS_WIN32) - wchar_t *buffer = 0; - do { - long length = ::GetLongPathName((wchar_t*)fileName.utf16(), NULL, 0); - if (!length) - break; - buffer = new wchar_t[length]; - DWORD rv = ::GetLongPathName((wchar_t*)fileName.utf16(), buffer, length); - if (!rv) - break; - canonicalPath = QString((QChar*)buffer); - } while (false); - delete buffer; + QString error; + // don't know whether the shortpath step is really needed, + // but we do this in QtDeclarative too. + QString path = Utils::getShortPathName(canonicalPath, &error); + if (!path.isEmpty()) + path = Utils::getLongPathName(canonicalPath, &error); + if (!path.isEmpty()) + canonicalPath = path; #endif return canonicalPath;