OSDN Git Service

dispose of dynamic resolution of GetLongPathNameW and GetShortPathNameW
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Mon, 21 Mar 2011 19:34:39 +0000 (20:34 +0100)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Mon, 21 Mar 2011 20:11:40 +0000 (21:11 +0100)
everything links to kernel32 anyway

src/libs/utils/winutils.cpp
src/libs/utils/winutils.h
src/plugins/projectexplorer/applicationlauncher_win.cpp
src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp

index 80ea371..2c4bb30 100644 (file)
@@ -132,66 +132,34 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
     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())
         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.
     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)
         return name;
     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);
     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())
         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);
+    const DWORD length = GetLongPathNameW(nameC, NULL, 0);
     if (length == 0)
         return name;
     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);
     return rc;
 }
index b32c88c..817717d 100644 (file)
@@ -55,12 +55,10 @@ QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t,
                                                 QString *errorMessage);
 
 // Return the short (8.3) file name
-QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name,
-                                                QString *errorMessage);
+QTCREATOR_UTILS_EXPORT QString getShortPathName(const QString &name);
 
 // Returns long name
-QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name,
-                                               QString *errorMessage);
+QTCREATOR_UTILS_EXPORT QString getLongPathName(const QString &name);
 
 QTCREATOR_UTILS_EXPORT unsigned long winQPidToPid(const Q_PID qpid);
 
index d383ec9..56c53ed 100644 (file)
@@ -71,11 +71,9 @@ ApplicationLauncher::~ApplicationLauncher()
 
 void ApplicationLauncher::setWorkingDirectory(const QString &dir)
 {
-    QString fixedPath = dir;
-    QString error;
-
     // 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())
         fixedPath = longPath;
 
index e513673..6106a97 100644 (file)
@@ -188,12 +188,11 @@ QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName)
     QString canonicalPath = QFileInfo(fileName).canonicalFilePath();
 
 #if defined(Q_OS_WIN32)
-    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);
+    QString path = Utils::getShortPathName(canonicalPath);
     if (!path.isEmpty())
-        path = Utils::getLongPathName(canonicalPath, &error);
+        path = Utils::getLongPathName(canonicalPath);
     if (!path.isEmpty())
         canonicalPath = path;
 #endif