forked from qt-creator/qt-creator
dispose of dynamic resolution of GetLongPathNameW and GetShortPathNameW
everything links to kernel32 anyway
This commit is contained in:
@@ -132,66 +132,34 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name, QString *errorMessage)
|
QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name)
|
||||||
{
|
{
|
||||||
typedef DWORD (APIENTRY *GetShortPathNameProtoType)(LPCTSTR, LPTSTR, DWORD);
|
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return name;
|
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
|
|
||||||
GetShortPathNameProtoType getShortPathNameW = (GetShortPathNameProtoType)(kernel32Lib.resolve("GetShortPathNameW"));
|
|
||||||
if (!getShortPathNameW) {
|
|
||||||
*errorMessage = msgCannotResolve(kernel32DLLC);
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
// Determine length, then convert.
|
// Determine length, then convert.
|
||||||
const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW
|
const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW
|
||||||
const DWORD length = (*getShortPathNameW)(nameC, NULL, 0);
|
const DWORD length = GetShortPathNameW(nameC, NULL, 0);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return name;
|
return name;
|
||||||
QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]);
|
QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]);
|
||||||
(*getShortPathNameW)(nameC, buffer.data(), length);
|
GetShortPathNameW(nameC, buffer.data(), length);
|
||||||
const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1);
|
const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name, QString *errorMessage)
|
QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name)
|
||||||
{
|
{
|
||||||
typedef DWORD (APIENTRY *GetLongPathNameProtoType)(LPCTSTR, LPTSTR, DWORD);
|
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return name;
|
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.
|
// Determine length, then convert.
|
||||||
const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW
|
const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(name.utf16()); // MinGW
|
||||||
const DWORD length = (*getLongPathNameW)(nameC, NULL, 0);
|
const DWORD length = GetLongPathNameW(nameC, NULL, 0);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return name;
|
return name;
|
||||||
QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]);
|
QScopedArrayPointer<TCHAR> buffer(new TCHAR[length]);
|
||||||
(*getLongPathNameW)(nameC, buffer.data(), length);
|
GetLongPathNameW(nameC, buffer.data(), length);
|
||||||
const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1);
|
const QString rc = QString::fromUtf16(reinterpret_cast<const ushort *>(buffer.data()), length - 1);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,12 +55,10 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
|
|||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
|
|
||||||
// Return the short (8.3) file name
|
// Return the short (8.3) file name
|
||||||
QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name,
|
QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name);
|
||||||
QString *errorMessage);
|
|
||||||
|
|
||||||
// Returns long name
|
// Returns long name
|
||||||
QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &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);
|
||||||
|
|
||||||
|
|||||||
@@ -71,11 +71,9 @@ ApplicationLauncher::~ApplicationLauncher()
|
|||||||
|
|
||||||
void ApplicationLauncher::setWorkingDirectory(const QString &dir)
|
void ApplicationLauncher::setWorkingDirectory(const QString &dir)
|
||||||
{
|
{
|
||||||
QString fixedPath = dir;
|
|
||||||
QString error;
|
|
||||||
|
|
||||||
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
|
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
|
||||||
const QString longPath = Utils::getLongPathName(dir, &error);
|
QString fixedPath = dir;
|
||||||
|
const QString longPath = Utils::getLongPathName(dir);
|
||||||
if (!longPath.isEmpty())
|
if (!longPath.isEmpty())
|
||||||
fixedPath = longPath;
|
fixedPath = longPath;
|
||||||
|
|
||||||
|
|||||||
@@ -188,12 +188,11 @@ 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)
|
||||||
QString error;
|
|
||||||
// don't know whether the shortpath step is really needed,
|
// don't know whether the shortpath step is really needed,
|
||||||
// but we do this in QtDeclarative too.
|
// but we do this in QtDeclarative too.
|
||||||
QString path = Utils::getShortPathName(canonicalPath, &error);
|
QString path = Utils::getShortPathName(canonicalPath);
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
path = Utils::getLongPathName(canonicalPath, &error);
|
path = Utils::getLongPathName(canonicalPath);
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
canonicalPath = path;
|
canonicalPath = path;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user