diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-12-04 15:24:33 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-10 04:52:20 +0100 |
commit | 6868fd8c2dc2abf1b69ec8cb9202b1107a9b0c84 (patch) | |
tree | 31adc74a936fac4f3092e53bb63a197c86333b09 /src/qml/qml/qqmlengine.cpp | |
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 <michael.brasser@live.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src/qml/qml/qqmlengine.cpp')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
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(); |