OSDN Git Service

Use the 'FindExInfoBasic' information level on supported OS (Windows 7 and later...
authorlordmulder <mulder2@gmx.de>
Sat, 31 Mar 2012 14:27:37 +0000 (16:27 +0200)
committerlordmulder <mulder2@gmx.de>
Sat, 31 Mar 2012 14:27:37 +0000 (16:27 +0200)
src/Config.h
src/Global.h
src/Model_FileSystem.cpp
src/Model_FileSystem.h
src/Tool_Abstract.cpp

index 6672ae5..da830f3 100644 (file)
@@ -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!)
index 7eca9d3..c502ccc 100644 (file)
@@ -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<const wchar_t*>(STR.utf16())
 #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast<const unsigned short*>(STR))
 #define        LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast<CLASS>(SRC); } catch(std::bad_cast) { OUT = NULL; }
index de1b5af..a135408 100644 (file)
@@ -212,6 +212,10 @@ QModelIndex QFileSystemModelEx::index(const QString &path, int column) const
 QHash<const QString, bool> 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<FindFirstFileExFun>(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;
 }
index 65539bd..8e7412a 100644 (file)
@@ -43,6 +43,10 @@ private:
        static QHash<const QString, bool> 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);
index ff8935e..5a71890 100644 (file)
@@ -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))
                        {