forked from qt-creator/qt-creator
QmlProject: Fix compilation on cygwin
Move use of windows API to winutils.
This commit is contained in:
@@ -165,6 +165,39 @@ QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name, QString *er
|
|||||||
return rc;
|
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)
|
QTCREATOR_UTILS_EXPORT unsigned long winQPidToPid(const Q_PID qpid)
|
||||||
{
|
{
|
||||||
const PROCESS_INFORMATION *processInfo = reinterpret_cast<const PROCESS_INFORMATION*>(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,
|
QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name,
|
||||||
QString *errorMessage);
|
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 unsigned long winQPidToPid(const Q_PID qpid);
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT bool winIs64BitSystem();
|
QTCREATOR_UTILS_EXPORT bool winIs64BitSystem();
|
||||||
@@ -65,5 +69,7 @@ QTCREATOR_UTILS_EXPORT bool winIs64BitSystem();
|
|||||||
// Check for a 64bit binary.
|
// Check for a 64bit binary.
|
||||||
QTCREATOR_UTILS_EXPORT bool winIs64BitBinary(const QString &binary);
|
QTCREATOR_UTILS_EXPORT bool winIs64BitBinary(const QString &binary);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
#endif // WINUTILS_H
|
#endif // WINUTILS_H
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
#include <qt4projectmanager/qt4projectmanagerconstants.h>
|
#include <qt4projectmanager/qt4projectmanagerconstants.h>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
#include <Windows.h>
|
#include <utils/winutils.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using Core::EditorManager;
|
using Core::EditorManager;
|
||||||
@@ -186,18 +186,14 @@ QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName)
|
|||||||
QString canonicalPath = QFileInfo(fileName).canonicalFilePath();
|
QString canonicalPath = QFileInfo(fileName).canonicalFilePath();
|
||||||
|
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
wchar_t *buffer = 0;
|
QString error;
|
||||||
do {
|
// don't know whether the shortpath step is really needed,
|
||||||
long length = ::GetLongPathName((wchar_t*)fileName.utf16(), NULL, 0);
|
// but we do this in QtDeclarative too.
|
||||||
if (!length)
|
QString path = Utils::getShortPathName(canonicalPath, &error);
|
||||||
break;
|
if (!path.isEmpty())
|
||||||
buffer = new wchar_t[length];
|
path = Utils::getLongPathName(canonicalPath, &error);
|
||||||
DWORD rv = ::GetLongPathName((wchar_t*)fileName.utf16(), buffer, length);
|
if (!path.isEmpty())
|
||||||
if (!rv)
|
canonicalPath = path;
|
||||||
break;
|
|
||||||
canonicalPath = QString((QChar*)buffer);
|
|
||||||
} while (false);
|
|
||||||
delete buffer;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return canonicalPath;
|
return canonicalPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user