diff --git a/src/base/system.c b/src/base/system.c index 94c031155..aacc2b7e1 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -2760,21 +2760,19 @@ void shell_execute(const char *file) #endif } -int os_compare_version(unsigned int major, unsigned int minor) +int os_is_winxp_or_lower(unsigned int major, unsigned int minor) { #if defined(CONF_FAMILY_WINDOWS) + static const DWORD WINXP_MAJOR = 5; + static const DWORD WINXP_MINOR = 1; OSVERSIONINFO ver; mem_zero(&ver, sizeof(OSVERSIONINFO)); ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&ver); - if(ver.dwMajorVersion > major || (ver.dwMajorVersion == major && ver.dwMinorVersion > minor)) - return 1; - else if(ver.dwMajorVersion == major && ver.dwMinorVersion == minor) - return 0; - else - return -1; + return ver.dwMajorVersion < WINXP_MAJOR + || (ver.dwMajorVersion == WINXP_MAJOR && ver.dwMinorVersion <= WINXP_MINOR); #else - return 0; // unimplemented + return 0; #endif } diff --git a/src/base/system.h b/src/base/system.h index a86d7b679..10471fd53 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1512,19 +1512,14 @@ int pid(); void shell_execute(const char *file); /* - Function: os_compare_version - Compares the OS version to a given major and minor. - - Parameters: - major - Major version to compare to. - minor - Minor version to compare to. + Function: os_is_winxp_or_lower + Checks whether the program runs on Windows XP or lower. Returns: - 1 - OS version higher. - 0 - OS version same. - -1 - OS version lower. + 1 - Windows XP or lower. + 0 - Higher Windows version, Linux, macOS, etc. */ -int os_compare_version(unsigned int major, unsigned int minor); +int os_is_winxp_or_lower(); /* Function: generate_password diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index c24be91e6..b61906024 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3623,11 +3623,7 @@ bool CClient::RaceRecord_IsRecording() void CClient::RequestDDNetInfo() { char aUrl[256]; - #if defined(CONF_FAMILY_WINDOWS) - static bool s_IsWinXP = os_compare_version(5U, 1U) <= 0; - #else - static bool s_IsWinXP = false; - #endif + static bool s_IsWinXP = os_is_winxp_or_lower(); if(s_IsWinXP) str_copy(aUrl, "http://info.ddnet.tw/info", sizeof(aUrl)); else diff --git a/src/engine/client/updater.cpp b/src/engine/client/updater.cpp index a14d9004b..55478809c 100644 --- a/src/engine/client/updater.cpp +++ b/src/engine/client/updater.cpp @@ -25,11 +25,7 @@ void CUpdater::Init() m_pClient = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); m_pFetcher = Kernel()->RequestInterface(); - #if defined(CONF_FAMILY_WINDOWS) - m_IsWinXP = os_compare_version(5U, 1U) <= 0; - #else - m_IsWinXP = false; - #endif + m_IsWinXP = os_is_winxp_or_lower(); } void CUpdater::ProgressCallback(IFetchTask *pTask, void *pUser) @@ -117,7 +113,7 @@ void CUpdater::ReplaceClient() { dbg_msg("updater", "replacing " PLAT_CLIENT_EXEC); - //Replace running executable by renaming twice... + // Replace running executable by renaming twice... if(!m_IsWinXP) { m_pStorage->RemoveBinaryFile("DDNet.old");