From 7f3bcbedb7a7f85d9328fcd23cbb01a8f17829bd Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 9 Sep 2012 23:05:00 +0200 Subject: [PATCH] Improved lamexp_get_os_version() function. --- src/Config.h | 2 +- src/Global.cpp | 54 +++++++++++++++++++++++++++++++--------- src/Global.h | 16 +++++++++--- src/Model_FileSystem.cpp | 2 +- src/Tool_Abstract.cpp | 2 +- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/Config.h b/src/Config.h index 1264695a..4da57f0f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 5 #define VER_LAMEXP_TYPE Final #define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 1102 +#define VER_LAMEXP_BUILD 1103 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Global.cpp b/src/Global.cpp index aa426c7b..966e57fd 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -245,6 +245,15 @@ static struct } g_lamexp_argv; +//CLI Arguments +static struct +{ + bool bInitialized; + lamexp_os_version_t version; + QReadWriteLock lock; +} +g_lamexp_os_version; + //Shared memory static const struct { @@ -376,11 +385,21 @@ const QDate &lamexp_version_date(void) /* * Get the native operating system version */ -DWORD lamexp_get_os_version(void) +const lamexp_os_version_t *lamexp_get_os_version(void) { - static DWORD osVersion = 0; + QReadLocker readLock(&g_lamexp_os_version.lock); + + //Already initialized? + if(g_lamexp_os_version.bInitialized) + { + return &g_lamexp_os_version.version; + } - if(!osVersion) + readLock.unlock(); + QWriteLocker writeLock(&g_lamexp_os_version.lock); + + //Detect OS version + if(!g_lamexp_os_version.bInitialized) { OSVERSIONINFO osVerInfo; memset(&osVerInfo, 0, sizeof(OSVERSIONINFO)); @@ -388,21 +407,27 @@ DWORD lamexp_get_os_version(void) if(GetVersionEx(&osVerInfo) == TRUE) { - if(osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) + if(osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { - throw "Ouuups: Not running under Windows NT. This is not supposed to happen!"; + g_lamexp_os_version.version.versionMajor = osVerInfo.dwMajorVersion; + g_lamexp_os_version.version.versionMinor = osVerInfo.dwMinorVersion; + } + else + { + qWarning("lamexp_get_os_version: Not running under Windows NT, this is not supposed to happen!"); + g_lamexp_os_version.version.versionMajor = 0; + g_lamexp_os_version.version.versionMinor = 0; } - const DWORD osVerHi = (DWORD)(((DWORD)(osVerInfo.dwMajorVersion)) << 16); - const DWORD osVerLo = (DWORD)(((DWORD)(osVerInfo.dwMinorVersion)) & ((DWORD)(0xffff))); - osVersion = (DWORD)(((DWORD)(osVerHi)) | ((DWORD)(osVerLo))); } else { throw "GetVersionEx() has failed. This is not supposed to happen!"; } + + g_lamexp_os_version.bInitialized = true; } - return osVersion; + return &g_lamexp_os_version.version; } /* @@ -1131,15 +1156,19 @@ bool lamexp_init_qt(int argc, char* argv[]) break; default: { - DWORD osVersionNo = lamexp_get_os_version(); - if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 2)) + const lamexp_os_version_t *osVersionNo = lamexp_get_os_version(); + if(osVersionNo->versionMajor < 5) + { + qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(executableName).toLatin1().constData()); + } + else if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 2)) { qDebug("Running on Windows 8 or Windows Server 2012\n"); lamexp_check_compatibility_mode(NULL, executableName); } else { - qWarning("Running on an unknown/untested WinNT-based OS (v%u.%u).\n", HIWORD(osVersionNo), LOWORD(osVersionNo)); + qWarning("Running on an unknown/untested WinNT-based OS (v%u.%u).\n", osVersionNo->versionMajor, osVersionNo->versionMinor); } } break; @@ -2222,6 +2251,7 @@ extern "C" LAMEXP_ZERO_MEMORY(g_lamexp_translation); LAMEXP_ZERO_MEMORY(g_lamexp_folder); LAMEXP_ZERO_MEMORY(g_lamexp_ipc_ptr); + LAMEXP_ZERO_MEMORY(g_lamexp_os_version); //Make sure we will pass the check g_lamexp_entry_check_flag = ~g_lamexp_entry_check_flag; diff --git a/src/Global.h b/src/Global.h index 241fd4b7..00aa7eed 100644 --- a/src/Global.h +++ b/src/Global.h @@ -83,6 +83,14 @@ typedef enum } lamexp_event_t; +//OS version number +typedef struct +{ + unsigned int versionMajor; + unsigned int versionMinor; +} +lamexp_os_version_t; + //LameXP version info unsigned int lamexp_version_major(void); unsigned int lamexp_version_minor(void); @@ -100,7 +108,7 @@ unsigned int lamexp_toolver_qaacenc(void); unsigned int lamexp_toolver_coreaudio(void); const char *lamexp_website_url(void); const char *lamexp_support_url(void); -DWORD lamexp_get_os_version(void); +const lamexp_os_version_t *lamexp_get_os_version(void); bool lamexp_detect_wine(void); //Public functions @@ -156,9 +164,9 @@ SIZE_T lamexp_dbg_private_bytes(void); #define LAMEXP_DELETE_ARRAY(PTR) do { if(PTR) { delete [] PTR; PTR = NULL; } } while(0) #define LAMEXP_SAFE_FREE(PTR) do { if(PTR) { free((void*) PTR); PTR = NULL; } } while(0) #define LAMEXP_CLOSE(HANDLE) do { if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } } while(0) -#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 LAMEXP_MAX_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) < (VER_MAJ)) || ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) <= (VER_MIN)))) -#define LAMEXP_EQL_OS_VER(VER_INFO, VER_MAJ, VER_MIN) ((HIWORD(VER_INFO) == (VER_MAJ)) && (LOWORD(VER_INFO) == (VER_MIN))) +#define LAMEXP_MIN_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor > (VER_MAJ)) || (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor >= (VER_MIN)))) +#define LAMEXP_MAX_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor < (VER_MAJ)) || (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor <= (VER_MIN)))) +#define LAMEXP_EQL_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor == (VER_MIN))) #define QWCHAR(STR) reinterpret_cast(STR.utf16()) #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast(STR)) #define LAMEXP_BOOL2STR(X) (X ? "1" : "0") diff --git a/src/Model_FileSystem.cpp b/src/Model_FileSystem.cpp index 3c71e7d8..e42dfdec 100644 --- a/src/Model_FileSystem.cpp +++ b/src/Model_FileSystem.cpp @@ -268,7 +268,7 @@ bool QFileSystemModelEx::hasSubfolders(const QString &path) if(kernel32Lib.load()) { FindFirstFileExPtr = kernel32Lib.resolve("FindFirstFileExW"); - DWORD osVersionNo = lamexp_get_os_version(); + const lamexp_os_version_t *osVersionNo = lamexp_get_os_version(); FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1); } FindFirstFileExInitialized = true; diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index 23195c6a..2a0f315c 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -63,7 +63,7 @@ AbstractTool::AbstractTool(void) if(s_jobObjRefCount < 1U) { - DWORD osVersionNo = lamexp_get_os_version(); + const lamexp_os_version_t *osVersionNo = lamexp_get_os_version(); if(LAMEXP_MIN_OS_VER(osVersionNo, 5, 1)) { if((!CreateJobObjectPtr) || (!SetInformationJobObjectPtr))