mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #193 from Learath2/pr_IHATEWINXP
Add os_compare_version. Check for WinXP.
This commit is contained in:
commit
1299ecb7f9
|
@ -2352,16 +2352,36 @@ int pid()
|
||||||
|
|
||||||
void shell_execute(const char *file)
|
void shell_execute(const char *file)
|
||||||
{
|
{
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
ShellExecute(NULL, NULL, file, NULL, NULL, SW_SHOWDEFAULT);
|
ShellExecute(NULL, NULL, file, NULL, NULL, SW_SHOWDEFAULT);
|
||||||
#elif defined(CONF_FAMILY_UNIX)
|
#elif defined(CONF_FAMILY_UNIX)
|
||||||
char* argv[2];
|
char* argv[2];
|
||||||
argv[0] = (char*) file;
|
argv[0] = (char*) file;
|
||||||
argv[1] = NULL;
|
argv[1] = NULL;
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if(!pid)
|
if(!pid)
|
||||||
execv(file, argv);
|
execv(file, argv);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int os_compare_version(int major, int minor)
|
||||||
|
{
|
||||||
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
|
OSVERSIONINFO ver;
|
||||||
|
mem_zero(&ver, sizeof(OSVERSIONINFO));
|
||||||
|
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||||
|
GetVersionEx(&ver);
|
||||||
|
if(ver.dwMajorVersion > major && ver.dwMinorVersion > minor)
|
||||||
|
return 1;
|
||||||
|
else if(ver.dwMajorVersion == major && ver.dwMinorVersion == minor)
|
||||||
|
return 0;
|
||||||
|
else if(ver.dwMajorVersion < major && ver.dwMinorVersion < minor)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return -2;
|
||||||
|
#else
|
||||||
|
#error not implemented
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SECURE_RANDOM_DATA
|
struct SECURE_RANDOM_DATA
|
||||||
|
|
|
@ -1327,8 +1327,27 @@ int str_utf8_check(const char *str);
|
||||||
|
|
||||||
int pid();
|
int pid();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: shell_execute
|
||||||
|
Executes a given file.
|
||||||
|
*/
|
||||||
void shell_execute(const char *file);
|
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.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
1 - OS version higher.
|
||||||
|
0 - OS version same.
|
||||||
|
-1 - OS version lower.
|
||||||
|
*/
|
||||||
|
int os_compare_version(int major, int minor);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: secure_random_init
|
Function: secure_random_init
|
||||||
Initializes the secure random module.
|
Initializes the secure random module.
|
||||||
|
|
|
@ -25,6 +25,7 @@ void CAutoUpdate::Init()
|
||||||
m_pClient = Kernel()->RequestInterface<IClient>();
|
m_pClient = Kernel()->RequestInterface<IClient>();
|
||||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||||
m_pFetcher = Kernel()->RequestInterface<IFetcher>();
|
m_pFetcher = Kernel()->RequestInterface<IFetcher>();
|
||||||
|
m_IsWinXP = (os_compare_version(5, 0) == 1 && os_compare_version(6, 0) == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAutoUpdate::ProgressCallback(CFetchTask *pTask, void *pUser)
|
void CAutoUpdate::ProgressCallback(CFetchTask *pTask, void *pUser)
|
||||||
|
@ -54,8 +55,12 @@ void CAutoUpdate::CompletionCallback(CFetchTask *pTask, void *pUser)
|
||||||
pUpdate->ReplaceServer();
|
pUpdate->ReplaceServer();
|
||||||
if(pUpdate->m_pClient->State() == IClient::STATE_ONLINE || pUpdate->m_pClient->EditorHasUnsavedData())
|
if(pUpdate->m_pClient->State() == IClient::STATE_ONLINE || pUpdate->m_pClient->EditorHasUnsavedData())
|
||||||
pUpdate->m_State = NEED_RESTART;
|
pUpdate->m_State = NEED_RESTART;
|
||||||
else
|
else{
|
||||||
pUpdate->m_pClient->Restart();
|
if(!pUpdate->m_IsWinXP)
|
||||||
|
pUpdate->m_pClient->Restart();
|
||||||
|
else
|
||||||
|
pUpdate->WinXpRestart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(pTask->State() == CFetchTask::STATE_ERROR)
|
else if(pTask->State() == CFetchTask::STATE_ERROR)
|
||||||
pUpdate->m_State = FAIL;
|
pUpdate->m_State = FAIL;
|
||||||
|
@ -113,11 +118,12 @@ void CAutoUpdate::ReplaceClient()
|
||||||
dbg_msg("autoupdate", "Replacing " PLAT_CLIENT_EXEC);
|
dbg_msg("autoupdate", "Replacing " PLAT_CLIENT_EXEC);
|
||||||
|
|
||||||
//Replace running executable by renaming twice...
|
//Replace running executable by renaming twice...
|
||||||
#if !defined(WINXP)
|
if(m_IsWinXP)
|
||||||
|
{
|
||||||
m_pStorage->RemoveBinaryFile("DDNet.old");
|
m_pStorage->RemoveBinaryFile("DDNet.old");
|
||||||
m_pStorage->RenameBinaryFile(PLAT_CLIENT_EXEC, "DDNet.old");
|
m_pStorage->RenameBinaryFile(PLAT_CLIENT_EXEC, "DDNet.old");
|
||||||
m_pStorage->RenameBinaryFile("DDNet.tmp", PLAT_CLIENT_EXEC);
|
m_pStorage->RenameBinaryFile("DDNet.tmp", PLAT_CLIENT_EXEC);
|
||||||
#endif
|
}
|
||||||
#if !defined(CONF_FAMILY_WINDOWS)
|
#if !defined(CONF_FAMILY_WINDOWS)
|
||||||
char aPath[512];
|
char aPath[512];
|
||||||
m_pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aPath, sizeof aPath);
|
m_pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aPath, sizeof aPath);
|
||||||
|
@ -227,3 +233,17 @@ void CAutoUpdate::PerformUpdate()
|
||||||
if(m_ClientUpdate)
|
if(m_ClientUpdate)
|
||||||
FetchFile(PLAT_CLIENT_DOWN, "DDNet.tmp");
|
FetchFile(PLAT_CLIENT_DOWN, "DDNet.tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAutoUpdate::WinXpRestart()
|
||||||
|
{
|
||||||
|
char aBuf[512];
|
||||||
|
IOHANDLE bhFile = io_open(m_pStorage->GetBinaryPath("du.bat", aBuf, sizeof aBuf), IOFLAG_WRITE);
|
||||||
|
if(!bhFile)
|
||||||
|
return;
|
||||||
|
char bBuf[512];
|
||||||
|
str_format(bBuf, sizeof(bBuf), ":_R\r\ndel \"DDNet.exe\"\r\nif exist \"DDNet.exe\" goto _R\r\nrename \"DDNet.tmp\" \"DDNet.exe\"\r\n:_T\r\nif not exist \"DDNet.exe\" goto _T\r\nstart DDNet.exe\r\ndel \"du.bat\"\r\n");
|
||||||
|
io_write(bhFile, bBuf, str_length(bBuf));
|
||||||
|
io_close(bhFile);
|
||||||
|
shell_execute(aBuf);
|
||||||
|
m_pClient->Quit();
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ class CAutoUpdate : public IAutoUpdate
|
||||||
class IStorage *m_pStorage;
|
class IStorage *m_pStorage;
|
||||||
class IFetcher *m_pFetcher;
|
class IFetcher *m_pFetcher;
|
||||||
|
|
||||||
|
bool m_IsWinXP;
|
||||||
|
|
||||||
int m_State;
|
int m_State;
|
||||||
char m_Status[256];
|
char m_Status[256];
|
||||||
int m_Percent;
|
int m_Percent;
|
||||||
|
@ -71,7 +73,7 @@ public:
|
||||||
virtual void InitiateUpdate();
|
virtual void InitiateUpdate();
|
||||||
void Init();
|
void Init();
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
void Restart();
|
void WinXpRestart();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1032,20 +1032,8 @@ void CClient::DebugRender()
|
||||||
void CClient::Restart()
|
void CClient::Restart()
|
||||||
{
|
{
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
#if defined(WINXP)
|
shell_execute(Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
||||||
IOHANDLE bhFile = io_open(Storage()->GetBinaryPath("du.bat", aBuf, sizeof aBuf);, IOFLAG_WRITE);
|
Quit();
|
||||||
if(!bhFile)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char bBuf[512];
|
|
||||||
str_format(bBuf, sizeof(bBuf), ":_R\r\ndel \"DDNet.exe\"\r\nif exist \"DDNet.exe\" goto _R\r\nrename \"DDNet.tmp\" \"DDNet.exe\"\r\n:_T\r\nif not exist \"DDNet.exe\" goto _T\r\nstart DDNet.exe\r\ndel \"du.bat\"\r\n");
|
|
||||||
io_write(bhFile, bBuf, str_length(bBuf));
|
|
||||||
io_close(bhFile);
|
|
||||||
ShellExecuteA(0, 0, aBuf, 0, 0, SW_HIDE);
|
|
||||||
#else
|
|
||||||
shell_execute(Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
|
||||||
Quit();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::Quit()
|
void CClient::Quit()
|
||||||
|
|
Loading…
Reference in a new issue