diff --git a/src/Config.h b/src/Config.h index 6672ae56..da830f33 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 11 -#define VER_LAMEXP_BUILD 942 +#define VER_LAMEXP_BUILD 944 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Global.h b/src/Global.h index 7eca9d39..c502ccc3 100644 --- a/src/Global.h +++ b/src/Global.h @@ -151,6 +151,7 @@ SIZE_T lamexp_dbg_private_bytes(void); #define LAMEXP_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; } #define LAMEXP_SAFE_FREE(PTR) if(PTR) { free((void*) PTR); PTR = NULL; } #define LAMEXP_CLOSE(HANDLE) if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } +#define LAMEXP_MIN_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) > (VER_MAJ)) || ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) >= (VER_MIN)))) #define QWCHAR(STR) reinterpret_cast(STR.utf16()) #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast(STR)) #define LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast(SRC); } catch(std::bad_cast) { OUT = NULL; } diff --git a/src/Model_FileSystem.cpp b/src/Model_FileSystem.cpp index de1b5af8..a1354080 100644 --- a/src/Model_FileSystem.cpp +++ b/src/Model_FileSystem.cpp @@ -212,6 +212,10 @@ QModelIndex QFileSystemModelEx::index(const QString &path, int column) const QHash QFileSystemModelEx::s_hasSubfolderCache; QMutex QFileSystemModelEx::s_hasSubfolderMutex; +void *QFileSystemModelEx::FindFirstFileExPtr = NULL; +bool QFileSystemModelEx::FindFirstFileExInitialized = false; +bool QFileSystemModelEx::FindFirstFileExInfoBasicOK = false; + bool QFileSystemModelEx::hasSubfoldersCached(const QString &path) { QMutexLocker lock(&s_hasSubfolderMutex); @@ -234,23 +238,22 @@ void QFileSystemModelEx::removeFromCache(const QString &path) bool QFileSystemModelEx::hasSubfolders(const QString &path) { - static bool FindFirstFileExInitialized = false; - static FindFirstFileExFun FindFirstFileExPtr = NULL; - if(!FindFirstFileExInitialized) { QLibrary Kernel32Lib("kernel32.dll"); - FindFirstFileExPtr = (FindFirstFileExFun) Kernel32Lib.resolve("FindFirstFileExW"); + FindFirstFileExPtr = Kernel32Lib.resolve("FindFirstFileExW"); + DWORD osVersionNo = lamexp_get_os_version(); + FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1); FindFirstFileExInitialized = true; } - + WIN32_FIND_DATAW findData; bool bChildren = false; HANDLE h = (FindFirstFileExPtr) - ? FindFirstFileExPtr(QWCHAR(QDir::toNativeSeparators(path + "/*")), FindExInfoStandard, &findData, FindExSearchLimitToDirectories, NULL, 0) + ? reinterpret_cast(FindFirstFileExPtr)(QWCHAR(QDir::toNativeSeparators(path + "/*")), (FindFirstFileExInfoBasicOK ? FindExInfoBasic : FindExInfoStandard), &findData, FindExSearchLimitToDirectories, NULL, 0) : FindFirstFileW(QWCHAR(QDir::toNativeSeparators(path + "/*")), &findData); - + if(h != INVALID_HANDLE_VALUE) { if(NO_DOT_OR_DOTDOT(findData.cFileName)) @@ -266,5 +269,14 @@ bool QFileSystemModelEx::hasSubfolders(const QString &path) } FindClose(h); } + else + { + DWORD err = GetLastError(); + if((err == ERROR_NOT_SUPPORTED) || (err == ERROR_INVALID_PARAMETER)) + { + qWarning("%s failed with error code #%u", FindFirstFileExPtr ? "FindFirstFileEx" : "FindFirstFile", err); + } + } + return bChildren; } diff --git a/src/Model_FileSystem.h b/src/Model_FileSystem.h index 65539bd5..8e7412a1 100644 --- a/src/Model_FileSystem.h +++ b/src/Model_FileSystem.h @@ -43,6 +43,10 @@ private: static QHash s_hasSubfolderCache; static QMutex s_hasSubfolderMutex; + static void *FindFirstFileExPtr; + static bool FindFirstFileExInitialized; + static bool FindFirstFileExInfoBasicOK; + static bool hasSubfolders(const QString &path); static bool hasSubfoldersCached(const QString &path); static void removeFromCache(const QString &path); diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index ff8935e8..5a71890d 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -69,7 +69,7 @@ AbstractTool::AbstractTool(void) if(m_jobObjRefCount < 1U) { DWORD osVersionNo = lamexp_get_os_version(); - if(((HIWORD(osVersionNo) == 5) && (LOWORD(osVersionNo) >= 1)) || (HIWORD(osVersionNo) > 5)) + if(LAMEXP_MIN_OS_VER(osVersionNo, 5, 1)) { if((!CreateJobObjectPtr) || (!SetInformationJobObjectPtr)) {