diff options
author | Friedemann Kleint <[email protected]> | 2013-12-04 15:24:33 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-12-10 04:52:20 +0100 |
commit | 6868fd8c2dc2abf1b69ec8cb9202b1107a9b0c84 (patch) | |
tree | 31adc74a936fac4f3092e53bb63a197c86333b09 /src | |
parent | 3297ccddf5f5234de5691f073507a5d88ccfeb04 (diff) |
Windows: Use Shell API for checking file case correctness.
The old method of converting to short 8.3 name and back does
not work for drives where this is disabled.
Change-Id: Ia0a46331a31eeb61578c31ba063a80665d5fc25c
Reviewed-by: Michael Brasser <[email protected]>
Reviewed-by: Alan Alpert <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml.pro | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 34 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/qml/qml.pro b/src/qml/qml.pro index 294983b95b..b0ea93e9fb 100644 --- a/src/qml/qml.pro +++ b/src/qml/qml.pro @@ -5,6 +5,7 @@ DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS +win32:!wince*:!winrt:LIBS += -lshell32 solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 MODULE_PLUGIN_TYPES = \ diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 1f45cba732..83ed627339 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -101,6 +101,9 @@ #ifdef Q_OS_WIN // for %APPDATA% #include <qt_windows.h> +# if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +# include <shlobj.h> +# endif #include <qlibrary.h> #include <windows.h> @@ -2285,6 +2288,28 @@ bool QQmlEnginePrivate::isScriptLoaded(const QUrl &url) const return typeLoader.isScriptLoaded(url); } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +// Normalize a file name using Shell API. As opposed to converting it +// to a short 8.3 name and back, this also works for drives where 8.3 notation +// is disabled (see 8dot3name options of fsutil.exe). +static inline QString shellNormalizeFileName(const QString &name) +{ + const QString nativeSeparatorName(QDir::toNativeSeparators(name)); + const LPCTSTR nameC = reinterpret_cast<LPCTSTR>(nativeSeparatorName.utf16()); + PIDLIST_ABSOLUTE file; + if (FAILED(SHParseDisplayName(nameC, NULL, &file, 0, NULL))) + return name; + TCHAR buffer[MAX_PATH]; + if (!SHGetPathFromIDList(file, buffer)) + return name; + QString canonicalName = QString::fromWCharArray(buffer); + // Upper case drive letter + if (canonicalName.size() > 2 && canonicalName.at(1) == QLatin1Char(':')) + canonicalName[0] = canonicalName.at(0).toUpper(); + return QDir::cleanPath(canonicalName); +} +#endif // Q_OS_WIN && !Q_OS_WINCE && !Q_OS_WINRT + bool QQml_isFileCaseCorrect(const QString &fileName, int lengthIn /* = -1 */) { #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -2294,14 +2319,7 @@ bool QQml_isFileCaseCorrect(const QString &fileName, int lengthIn /* = -1 */) #if defined(Q_OS_MAC) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) const QString canonical = info.canonicalFilePath(); #elif defined(Q_OS_WIN) - wchar_t buffer[1024]; - - DWORD rv = ::GetShortPathName((wchar_t*)absolute.utf16(), buffer, 1024); - if (rv == 0 || rv >= 1024) return true; - rv = ::GetLongPathName(buffer, buffer, 1024); - if (rv == 0 || rv >= 1024) return true; - - const QString canonical = QString::fromWCharArray(buffer); + const QString canonical = shellNormalizeFileName(absolute); #endif const int absoluteLength = absolute.length(); |