Commit 2c4ae8c1 authored by Kai Koehne's avatar Kai Koehne

QmlProject: Fix compilation on cygwin

Move use of windows API to winutils.
parent e624c3fb
......@@ -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<LPCTSTR>(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<const ushort *>(buffer), length);
delete [] buffer;
return rc;
}
QTCREATOR_UTILS_EXPORT unsigned long winQPidToPid(const Q_PID qpid)
{
const PROCESS_INFORMATION *processInfo = reinterpret_cast<const PROCESS_INFORMATION*>(qpid);
......
......@@ -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
......@@ -46,7 +46,7 @@
#include <qt4projectmanager/qt4projectmanagerconstants.h>
#ifdef Q_OS_WIN32
#include <Windows.h>
#include <utils/winutils.h>
#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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment