Improved lamexp_get_os_version() function.
This commit is contained in:
parent
e5f493a822
commit
7f3bcbedb7
@ -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!)
|
||||
|
@ -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;
|
||||
|
16
src/Global.h
16
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<const wchar_t*>(STR.utf16())
|
||||
#define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast<const unsigned short*>(STR))
|
||||
#define LAMEXP_BOOL2STR(X) (X ? "1" : "0")
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user