Change os_compare_version to os_is_winxp_or_lower

This stops leaking OS details in non-`system.c` files.
This commit is contained in:
heinrich5991 2017-11-23 03:10:15 +01:00
parent 27722633a3
commit f0c647dba5
4 changed files with 14 additions and 29 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -25,11 +25,7 @@ void CUpdater::Init()
m_pClient = Kernel()->RequestInterface<IClient>();
m_pStorage = Kernel()->RequestInterface<IStorage>();
m_pFetcher = Kernel()->RequestInterface<IFetcher>();
#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");