From be9cf2564558c12ab3b61bb0af6e3e891c4b5a97 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 20 Oct 2013 19:12:00 +0200 Subject: [PATCH] Improved Windows version detection code. --- etc/Translation/Blank.ts | 55 +++++++++-------- etc/Translation/LameXP_PL.ts | 55 +++++++++-------- etc/Translation/LameXP_SV.ts | 55 +++++++++-------- etc/Translation/release.bat | 11 ---- src/Config.h | 2 +- src/Global.cpp | 113 ++++++++++++++++++++--------------- src/Global.h | 24 ++++++-- src/Model_FileSystem.cpp | 4 +- 8 files changed, 169 insertions(+), 150 deletions(-) delete mode 100644 etc/Translation/release.bat diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index 4deb9d0a..9c03919e 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -3290,23 +3290,22 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. - + Executable '%1' requires Qt v%2, but found Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. - - + Executable '%1' requires Windows XP or later. @@ -3375,105 +3374,105 @@ - - + + Build - + Unknown - + Testing your internet connection, please wait... - - + + It appears that the computer currently is offline! - - + + Please make sure your computer is connected to the internet and try again. - + Network connectivity test has failed! - + Please make sure your internet connection is working properly and try again. - + Checking for new updates online, please wait... - + Failed to fetch update information from server! - + Sorry, the update server might be busy at this time. Plase try again later. - + More information available at: - + A new version of LameXP is available! - + We highly recommend all users to install this update as soon as possible. - + No new updates available at this time. - + Your version of LameXP is still up-to-date. Please check for updates regularly! - + Your version appears to be newer than the latest release. - + This usually indicates your are currently using a pre-release version of LameXP. - + Update is being downloaded, please be patient... - + Update ready to install. Applicaion will quit... - + Update failed. Please try again or download manually! diff --git a/etc/Translation/LameXP_PL.ts b/etc/Translation/LameXP_PL.ts index d38376c0..163d3517 100644 --- a/etc/Translation/LameXP_PL.ts +++ b/etc/Translation/LameXP_PL.ts @@ -3327,23 +3327,22 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. Plik wykonywalny '%1' nie działa w trybie kompatybilności z Windows. - + Executable '%1' requires Qt v%2, but found Qt v%3. Plik wykonywalny '%1' wymaga Qt v%2, znaleziono jednak Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. Plik wykonywalny "%1" został skompilowany dla Qt "%2", znaleziono "%3". - - + Executable '%1' requires Windows XP or later. @@ -3412,105 +3411,105 @@ Zamknij - - + + Build Build - + Unknown Nieznana - + Testing your internet connection, please wait... Testowanie połączenia internetowego, prosze czekać... - - + + It appears that the computer currently is offline! LameXP wykrył brak dostępu do internetu! - - + + Please make sure your computer is connected to the internet and try again. Upewnij się że komputer jest podłączony do internetu i spróbuj ponownie. - + Network connectivity test has failed! Test połączenia internetowego zakończony niepowodzeniem! - + Please make sure your internet connection is working properly and try again. Upewnij się że połączenie internetowe działa prawidłowo i spróbuj ponownie. - + Checking for new updates online, please wait... Sprawdzanie aktualizacji online, prosze czekać... - + Failed to fetch update information from server! Pobieranie informacji z serwera zakończone niepowodzeniem! - + Sorry, the update server might be busy at this time. Plase try again later. Serwer aktualizacji wydaje się nie odpowiadać w tej chwili. Prosze spróbować później. - + More information available at: Więcej informacji tutaj: - + A new version of LameXP is available! Dostępna nowa wersja LameXP! - + We highly recommend all users to install this update as soon as possible. Jest wysoce zalecane aby zainstalować tę aktualizację jak najszybciej. - + No new updates available at this time. Nie ma nowych aktualizacji w tej chwili. - + Your version of LameXP is still up-to-date. Please check for updates regularly! Posiadasz najnowszą wersję LameXP. Sprawdzaj aktualizacje regularnie! - + Your version appears to be newer than the latest release. Posiadasz nowszą wersję LameXP niż ostatnie wydanie. - + This usually indicates your are currently using a pre-release version of LameXP. To wskazuje na to, że posiadasz wersję alfa LameXP. - + Update is being downloaded, please be patient... Pobieranie aktualizacji w toku, prosze czekać... - + Update ready to install. Applicaion will quit... Aktualizacja gotowa do instalacji. Teraz program zostanie zamknięty... - + Update failed. Please try again or download manually! Aktualizacja zakończona niepowodzeniem. Prosze spróbować ponownie lub zainstalować ręcznie! diff --git a/etc/Translation/LameXP_SV.ts b/etc/Translation/LameXP_SV.ts index b2ae07b0..5747317f 100644 --- a/etc/Translation/LameXP_SV.ts +++ b/etc/Translation/LameXP_SV.ts @@ -3310,23 +3310,22 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. EXE-filen '%1' stöder inte Windows kompatibilitetsläge. - + Executable '%1' requires Qt v%2, but found Qt v%3. EXE-filen '%1' kräver Qt v%2, du har Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. EXE-filen '%1' är byggd för Qt '%2', du har Qt '%3'. - - + Executable '%1' requires Windows XP or later. @@ -3395,105 +3394,105 @@ Stäng - - + + Build Build - + Unknown Okänd - + Testing your internet connection, please wait... Kontrollerar iInternetanslutningen, vänta... - - + + It appears that the computer currently is offline! Datorn verkar inte vara ansluten till Internet! - - + + Please make sure your computer is connected to the internet and try again. Tillse att datorn är ansluten till Internet och försök igen. - + Network connectivity test has failed! Anslutningskontrollen misslyckades! - + Please make sure your internet connection is working properly and try again. Tillse att Internetuppkopplingen fungerar korrekt och försök igen. - + Checking for new updates online, please wait... Söker nya uppdateringar, vänta... - + Failed to fetch update information from server! Kunde inte hämta uppdateringsinformation från servern! - + Sorry, the update server might be busy at this time. Plase try again later. Uppdateringsservern kan vara upptagen. Försök senare. - + More information available at: Mer information hittas på: - + A new version of LameXP is available! En ny version av LameXP finns tillgänglig! - + We highly recommend all users to install this update as soon as possible. Vi rekommenderar alla användare att installera denna uppdatering så snart som möjligt. - + No new updates available at this time. Det finns inga nya uppdateringar. - + Your version of LameXP is still up-to-date. Please check for updates regularly! Din version av LameXP är uppdaterad. Kontrollera regelbundet! - + Your version appears to be newer than the latest release. Din version verkar vara nyare än senaste 'Release'. - + This usually indicates your are currently using a pre-release version of LameXP. Det innebär normalt att du använder en beta-version av LameXP. - + Update is being downloaded, please be patient... Uppdatering laddas ner, vänta... - + Update ready to install. Applicaion will quit... Uppdatering klar att installeras. Programmet kommer att avslutas... - + Update failed. Please try again or download manually! Uppdateringen misslyckades. Försök igen, eller ladda ner manuellt! diff --git a/etc/Translation/release.bat b/etc/Translation/release.bat deleted file mode 100644 index bceb6d6a..00000000 --- a/etc/Translation/release.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -REM --------------------------- -call "..\Deployment\_paths.bat" -if exist "%PATH_QTMSVC%\bin\qtenv2.bat" call "%PATH_QTMSVC%\bin\qtenv2.bat" -if exist "%PATH_QTMSVC%\bin\qtvars.bat" call "%PATH_QTMSVC%\bin\qtvars.bat" -REM --------------------------- -for %%f in (LameXP_??.ts) do ( - lrelease.exe %%f -qm ..\..\res\localization\%%~nf.qm -) -REM --------------------------- -pause diff --git a/src/Config.h b/src/Config.h index b6d57d77..5b21da28 100644 --- a/src/Config.h +++ b/src/Config.h @@ -34,7 +34,7 @@ #define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 3 -#define VER_LAMEXP_BUILD 1403 +#define VER_LAMEXP_BUILD 1407 #define VER_LAMEXP_CONFG 1348 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Global.cpp b/src/Global.cpp index dc60a29c..71036816 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -291,6 +291,15 @@ static FILE *g_lamexp_log_file = NULL; const char* LAMEXP_DEFAULT_LANGID = "en"; const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm"; +//Known Windows versions - maps marketing names to the actual Windows NT versions +const lamexp_os_version_t lamexp_winver_win2k = {5,0}; +const lamexp_os_version_t lamexp_winver_winxp = {5,1}; +const lamexp_os_version_t lamexp_winver_xpx64 = {5,2}; +const lamexp_os_version_t lamexp_winver_vista = {6,0}; +const lamexp_os_version_t lamexp_winver_win70 = {6,1}; +const lamexp_os_version_t lamexp_winver_win80 = {6,2}; +const lamexp_os_version_t lamexp_winver_win81 = {6,3}; + /////////////////////////////////////////////////////////////////////////////// // COMPILER INFO /////////////////////////////////////////////////////////////////////////////// @@ -492,27 +501,25 @@ const QDate &lamexp_version_date(void) return g_lamexp_version_date; } -static bool lamexp_verify_os_version(const DWORD major, const DWORD minor, const BYTE opMajor, const BYTE opMinor) +static bool lamexp_verify_os_version(const DWORD major, const DWORD minor) { - qDebug("checkOsVersion %u.%u (%u,%u)\n", major, minor, (unsigned int)opMajor, (unsigned int)opMinor); - - OSVERSIONINFOEX osvi; + OSVERSIONINFOEXW osvi; DWORDLONG dwlConditionMask = 0; - //Initialize the OSVERSIONINFOEX structure. - memset(&osvi, 0, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + //Initialize the OSVERSIONINFOEX structure + memset(&osvi, 0, sizeof(OSVERSIONINFOEXW)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); osvi.dwMajorVersion = major; osvi.dwMinorVersion = minor; osvi.dwPlatformId = VER_PLATFORM_WIN32_NT; //Initialize the condition mask - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, opMajor); - VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, opMinor); + VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, VER_EQUAL); // Perform the test - const BOOL ret = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_PLATFORMID, dwlConditionMask); + const BOOL ret = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_PLATFORMID, dwlConditionMask); //Error checking if(!ret) @@ -531,54 +538,62 @@ static bool lamexp_verify_os_version(const DWORD major, const DWORD minor, const */ static bool lamexp_get_real_os_version(unsigned int *major, unsigned int *minor) { - *major = *minor = UINT_MAX; + *major = *minor = 0; - //Determine the *major* version first - for(DWORD i = 3; i < 100; i++) + //Initialize local variables + OSVERSIONINFOEXW osvi; + memset(&osvi, 0, sizeof(OSVERSIONINFOEXW)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); + + //Try GetVersionEx() first + if(GetVersionExW((LPOSVERSIONINFOW)&osvi) != FALSE) { - if(lamexp_verify_os_version(i, 0, VER_GREATER_EQUAL, VER_GREATER_EQUAL)) + if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { - *major = i; + *major = osvi.dwMajorVersion; + *minor = osvi.dwMinorVersion; + } + } + + //Determine the real *major* version first + forever + { + const DWORD nextMajor = (*major) + 1; + if(lamexp_verify_os_version(nextMajor, 0)) + { + *major = nextMajor; + *minor = 0; continue; } break; } - //Now also determine the *minor* version - if((*major) != UINT_MAX) + //Now also determine the real *minor* version + forever { - for(DWORD i = 0; i < 100; i++) + const DWORD nextMinor = (*minor) + 1; + if(lamexp_verify_os_version((*major), nextMinor)) { - if(lamexp_verify_os_version((*major), i, VER_EQUAL, VER_GREATER_EQUAL)) - { - *minor = i; - continue; - } - break; + *minor = nextMinor; + continue; } + break; } - //Check for completeness - if(((*major) == UINT_MAX) || ((*minor) == UINT_MAX)) - { - *major = *minor = 0; - return false; - } - - return true; + return ((*major) > 0); } /* * Get the native operating system version */ -const lamexp_os_version_t *lamexp_get_os_version(void) +const lamexp_os_version_t &lamexp_get_os_version(void) { QReadLocker readLock(&g_lamexp_os_version.lock); //Already initialized? if(g_lamexp_os_version.bInitialized) { - return &g_lamexp_os_version.version; + return g_lamexp_os_version.version; } readLock.unlock(); @@ -600,7 +615,7 @@ const lamexp_os_version_t *lamexp_get_os_version(void) } } - return &g_lamexp_os_version.version; + return g_lamexp_os_version.version; } /* @@ -1262,44 +1277,48 @@ bool lamexp_init_qt(int argc, char* argv[]) #endif //Check the Windows version - const lamexp_os_version_t *osVersionNo = lamexp_get_os_version(); - if(LAMEXP_MAX_OS_VER(osVersionNo, 5, 0)) + const lamexp_os_version_t &osVersionNo = lamexp_get_os_version(); + if(osVersionNo < lamexp_winver_winxp) { qFatal("%s", QApplication::tr("Executable '%1' requires Windows XP or later.").arg(executableName).toLatin1().constData()); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 5, 1)) + + //Check for compat mode + if(osVersionNo == lamexp_winver_winxp) { qDebug("Running on Windows XP.\n"); lamexp_check_compatibility_mode("GetLargePageMinimum", executableName); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 5, 2)) + else if(osVersionNo == lamexp_winver_xpx64) { qDebug("Running on Windows Server 2003 or Windows XP x64-Edition.\n"); lamexp_check_compatibility_mode("GetLocaleInfoEx", executableName); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 0)) + else if(osVersionNo == lamexp_winver_vista) { qDebug("Running on Windows Vista or Windows Server 2008.\n"); lamexp_check_compatibility_mode("CreateRemoteThreadEx", executableName); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 1)) + else if(osVersionNo == lamexp_winver_win70) { qDebug("Running on Windows 7 or Windows Server 2008 R2.\n"); lamexp_check_compatibility_mode("CreateFile2", executableName); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 2)) + else if(osVersionNo == lamexp_winver_win80) { qDebug("Running on Windows 8 or Windows Server 2012.\n"); - lamexp_check_compatibility_mode(NULL, executableName); + lamexp_check_compatibility_mode("FindPackagesByPackageFamily", executableName); } - else if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 3)) + else if(osVersionNo == lamexp_winver_win81) { qDebug("Running on Windows 8.1 or Windows Server 2012 R2.\n"); lamexp_check_compatibility_mode(NULL, executableName); } else { - qWarning("Running on an unknown/untested WindowsNT-based OS (v%u.%u).\n", osVersionNo->versionMajor, osVersionNo->versionMinor); + const QString message = QString().sprintf("Running on an unknown WindowsNT-based system (v%u.%u).", osVersionNo.versionMajor, osVersionNo.versionMinor); + qWarning("%s\n", message.toUtf8().constData()); + MessageBoxW(NULL, QWCHAR(message), L"LameXP", MB_OK | MB_TOPMOST | MB_ICONWARNING); } //Check for Wine @@ -2196,8 +2215,8 @@ bool lamexp_themes_enabled(void) if(!g_lamexp_themes_enabled.bInitialized) { g_lamexp_themes_enabled.bThemesEnabled = false; - const lamexp_os_version_t * osVersion = lamexp_get_os_version(); - if(LAMEXP_MIN_OS_VER(osVersion, 5, 1)) + const lamexp_os_version_t &osVersion = lamexp_get_os_version(); + if(osVersion >= lamexp_winver_winxp) { IsAppThemedFun IsAppThemedPtr = NULL; QLibrary uxTheme(QString("%1/UxTheme.dll").arg(lamexp_known_folder(lamexp_folder_systemfolder))); diff --git a/src/Global.h b/src/Global.h index c863037b..811a64ba 100644 --- a/src/Global.h +++ b/src/Global.h @@ -81,13 +81,30 @@ typedef enum lamexp_event_t; //OS version number -typedef struct +typedef struct _lamexp_os_version_t { unsigned int versionMajor; unsigned int versionMinor; + + //comparision operators + inline bool operator== (const _lamexp_os_version_t &rhs) const { return (versionMajor == rhs.versionMajor) && (versionMinor == rhs.versionMinor); } + inline bool operator!= (const _lamexp_os_version_t &rhs) const { return (versionMajor != rhs.versionMajor) || (versionMinor != rhs.versionMinor); } + inline bool operator> (const _lamexp_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor > rhs.versionMinor)); } + inline bool operator>= (const _lamexp_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >= rhs.versionMinor)); } + inline bool operator< (const _lamexp_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor < rhs.versionMinor)); } + inline bool operator<= (const _lamexp_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <= rhs.versionMinor)); } } lamexp_os_version_t; +//Known Windows versions +extern const lamexp_os_version_t lamexp_winver_win2k; +extern const lamexp_os_version_t lamexp_winver_winxp; +extern const lamexp_os_version_t lamexp_winver_xpx64; +extern const lamexp_os_version_t lamexp_winver_vista; +extern const lamexp_os_version_t lamexp_winver_win70; +extern const lamexp_os_version_t lamexp_winver_win80; +extern const lamexp_os_version_t lamexp_winver_win81; + //Beep types typedef enum { @@ -125,7 +142,7 @@ unsigned int lamexp_toolver_coreaudio(void); const char *lamexp_website_url(void); const char *lamexp_mulders_url(void); const char *lamexp_support_url(void); -const lamexp_os_version_t *lamexp_get_os_version(void); +const lamexp_os_version_t &lamexp_get_os_version(void); bool lamexp_detect_wine(void); //Public functions @@ -209,9 +226,6 @@ unsigned long 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) (((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 d66dbb52..7658dfc9 100644 --- a/src/Model_FileSystem.cpp +++ b/src/Model_FileSystem.cpp @@ -264,8 +264,8 @@ bool QFileSystemModelEx::hasSubfolders(const QString &path) { if(s_findFirstFileExInfoLevel == INT_MAX) { - const lamexp_os_version_t *osVersionNo = lamexp_get_os_version(); - s_findFirstFileExInfoLevel = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1) ? FindExInfoBasic : FindExInfoStandard; + const lamexp_os_version_t &osVersionNo = lamexp_get_os_version(); + s_findFirstFileExInfoLevel = (osVersionNo >= lamexp_winver_win70) ? FindExInfoBasic : FindExInfoStandard; } WIN32_FIND_DATAW findData;