2015-04-18 19:17:27 +00:00
|
|
|
#include "updater.h"
|
2022-06-03 10:10:05 +00:00
|
|
|
#include <base/lock_scope.h>
|
2014-12-31 14:29:34 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
#include <engine/client.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/engine.h>
|
2014-12-31 14:29:34 +00:00
|
|
|
#include <engine/external/json-parser/json.h>
|
2022-05-29 13:51:38 +00:00
|
|
|
#include <engine/shared/http.h>
|
2020-01-01 19:07:04 +00:00
|
|
|
#include <engine/shared/json.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/storage.h>
|
2014-12-31 14:29:34 +00:00
|
|
|
|
2022-02-14 23:22:52 +00:00
|
|
|
#include <cstdlib> // system
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2015-08-29 20:41:29 +00:00
|
|
|
using std::map;
|
2020-09-26 19:41:58 +00:00
|
|
|
using std::string;
|
2014-12-31 14:29:34 +00:00
|
|
|
|
2022-05-05 12:49:25 +00:00
|
|
|
class CUpdaterFetchTask : public CHttpRequest
|
2017-11-23 14:47:38 +00:00
|
|
|
{
|
|
|
|
char m_aBuf[256];
|
|
|
|
char m_aBuf2[256];
|
|
|
|
CUpdater *m_pUpdater;
|
|
|
|
|
2022-05-17 18:33:27 +00:00
|
|
|
void OnProgress() override;
|
2020-09-24 07:52:11 +00:00
|
|
|
|
|
|
|
protected:
|
2022-05-17 18:33:27 +00:00
|
|
|
int OnCompletion(int State) override;
|
2017-11-23 14:47:38 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CUpdaterFetchTask(CUpdater *pUpdater, const char *pFile, const char *pDestPath);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *GetUpdaterUrl(char *pBuf, int BufSize, const char *pFile)
|
|
|
|
{
|
2020-08-19 15:50:36 +00:00
|
|
|
str_format(pBuf, BufSize, "https://update6.ddnet.tw/%s", pFile);
|
2017-11-23 14:47:38 +00:00
|
|
|
return pBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *GetUpdaterDestPath(char *pBuf, int BufSize, const char *pFile, const char *pDestPath)
|
|
|
|
{
|
|
|
|
if(!pDestPath)
|
|
|
|
{
|
|
|
|
pDestPath = pFile;
|
|
|
|
}
|
|
|
|
str_format(pBuf, BufSize, "update/%s", pDestPath);
|
|
|
|
return pBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
CUpdaterFetchTask::CUpdaterFetchTask(CUpdater *pUpdater, const char *pFile, const char *pDestPath) :
|
2022-05-05 12:49:25 +00:00
|
|
|
CHttpRequest(GetUpdaterUrl(m_aBuf, sizeof(m_aBuf), pFile)),
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pUpdater(pUpdater)
|
|
|
|
{
|
2022-05-05 12:49:25 +00:00
|
|
|
WriteToFile(pUpdater->m_pStorage, GetUpdaterDestPath(m_aBuf2, sizeof(m_aBuf2), pFile, pDestPath), -2);
|
2017-11-23 14:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUpdaterFetchTask::OnProgress()
|
|
|
|
{
|
2022-06-03 10:10:05 +00:00
|
|
|
CLockScope ls(m_pUpdater->m_Lock);
|
2017-11-23 14:47:38 +00:00
|
|
|
str_copy(m_pUpdater->m_aStatus, Dest(), sizeof(m_pUpdater->m_aStatus));
|
|
|
|
m_pUpdater->m_Percent = Progress();
|
|
|
|
}
|
|
|
|
|
2020-09-24 07:52:11 +00:00
|
|
|
int CUpdaterFetchTask::OnCompletion(int State)
|
2017-11-23 14:47:38 +00:00
|
|
|
{
|
2022-05-05 12:49:25 +00:00
|
|
|
State = CHttpRequest::OnCompletion(State);
|
2020-09-24 07:52:11 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
const char *b = 0;
|
|
|
|
for(const char *a = Dest(); *a; a++)
|
|
|
|
if(*a == '/')
|
|
|
|
b = a + 1;
|
|
|
|
b = b ? b : Dest();
|
|
|
|
if(!str_comp(b, "update.json"))
|
|
|
|
{
|
2020-09-24 07:52:11 +00:00
|
|
|
if(State == HTTP_DONE)
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pUpdater->SetCurrentState(IUpdater::GOT_MANIFEST);
|
2020-09-24 07:52:11 +00:00
|
|
|
else if(State == HTTP_ERROR)
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pUpdater->SetCurrentState(IUpdater::FAIL);
|
|
|
|
}
|
|
|
|
else if(!str_comp(b, m_pUpdater->m_aLastFile))
|
|
|
|
{
|
2020-09-24 07:52:11 +00:00
|
|
|
if(State == HTTP_DONE)
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pUpdater->SetCurrentState(IUpdater::MOVE_FILES);
|
2020-09-24 07:52:11 +00:00
|
|
|
else if(State == HTTP_ERROR)
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pUpdater->SetCurrentState(IUpdater::FAIL);
|
|
|
|
}
|
2020-09-24 07:52:11 +00:00
|
|
|
|
|
|
|
return State;
|
2017-11-23 14:47:38 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
CUpdater::CUpdater()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2015-03-13 14:13:19 +00:00
|
|
|
m_pClient = NULL;
|
|
|
|
m_pStorage = NULL;
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pEngine = NULL;
|
2015-03-13 14:13:19 +00:00
|
|
|
m_State = CLEAN;
|
|
|
|
m_Percent = 0;
|
2017-11-23 14:47:38 +00:00
|
|
|
m_Lock = lock_create();
|
2020-02-12 21:39:37 +00:00
|
|
|
|
2021-12-20 14:00:21 +00:00
|
|
|
IStorage::FormatTmpPath(m_aClientExecTmp, sizeof(m_aClientExecTmp), CLIENT_EXEC);
|
|
|
|
IStorage::FormatTmpPath(m_aServerExecTmp, sizeof(m_aServerExecTmp), SERVER_EXEC);
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::Init()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2015-03-13 14:13:19 +00:00
|
|
|
m_pClient = Kernel()->RequestInterface<IClient>();
|
|
|
|
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pEngine = Kernel()->RequestInterface<IEngine>();
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
CUpdater::~CUpdater()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2017-11-23 14:47:38 +00:00
|
|
|
lock_destroy(m_Lock);
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
void CUpdater::SetCurrentState(int NewState)
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2022-06-03 10:10:05 +00:00
|
|
|
CLockScope ls(m_Lock);
|
2017-11-23 14:47:38 +00:00
|
|
|
m_State = NewState;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CUpdater::GetCurrentState()
|
|
|
|
{
|
2022-06-03 10:10:05 +00:00
|
|
|
CLockScope ls(m_Lock);
|
|
|
|
return m_State;
|
2017-11-23 14:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUpdater::GetCurrentFile(char *pBuf, int BufSize)
|
|
|
|
{
|
2022-06-03 10:10:05 +00:00
|
|
|
CLockScope ls(m_Lock);
|
2017-11-23 14:47:38 +00:00
|
|
|
str_copy(pBuf, m_aStatus, BufSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CUpdater::GetCurrentPercent()
|
|
|
|
{
|
2022-06-03 10:10:05 +00:00
|
|
|
CLockScope ls(m_Lock);
|
|
|
|
return m_Percent;
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::FetchFile(const char *pFile, const char *pDestPath)
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2017-11-23 14:47:38 +00:00
|
|
|
m_pEngine->AddJob(std::make_shared<CUpdaterFetchTask>(this, pFile, pDestPath));
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
2017-02-21 16:10:08 +00:00
|
|
|
|
2019-04-04 19:38:52 +00:00
|
|
|
bool CUpdater::MoveFile(const char *pFile)
|
2015-08-29 20:41:29 +00:00
|
|
|
{
|
|
|
|
char aBuf[256];
|
|
|
|
size_t len = str_length(pFile);
|
2019-04-04 19:38:52 +00:00
|
|
|
bool Success = true;
|
2016-05-01 12:20:55 +00:00
|
|
|
|
2019-07-31 16:00:48 +00:00
|
|
|
#if !defined(CONF_FAMILY_WINDOWS)
|
|
|
|
if(!str_comp_nocase(pFile + len - 4, ".dll"))
|
|
|
|
return Success;
|
|
|
|
#endif
|
|
|
|
|
2021-02-12 09:21:23 +00:00
|
|
|
#if !defined(CONF_PLATFORM_LINUX)
|
2021-06-14 05:47:54 +00:00
|
|
|
if(!str_comp_nocase(pFile + len - 3, ".so"))
|
2021-02-12 09:21:23 +00:00
|
|
|
return Success;
|
|
|
|
#endif
|
|
|
|
|
2020-08-26 08:41:47 +00:00
|
|
|
if(!str_comp_nocase(pFile + len - 4, ".dll") || !str_comp_nocase(pFile + len - 4, ".ttf") || !str_comp_nocase(pFile + len - 3, ".so"))
|
2015-08-29 20:41:29 +00:00
|
|
|
{
|
|
|
|
str_format(aBuf, sizeof(aBuf), "%s.old", pFile);
|
2020-08-11 12:06:35 +00:00
|
|
|
m_pStorage->RenameBinaryFile(pFile, aBuf);
|
2015-08-29 20:41:29 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "update/%s", pFile);
|
2019-04-04 19:38:52 +00:00
|
|
|
Success &= m_pStorage->RenameBinaryFile(aBuf, pFile);
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str_format(aBuf, sizeof(aBuf), "update/%s", pFile);
|
2019-04-04 19:38:52 +00:00
|
|
|
Success &= m_pStorage->RenameBinaryFile(aBuf, pFile);
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
2019-04-04 19:38:52 +00:00
|
|
|
|
|
|
|
return Success;
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::Update()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2015-03-13 14:13:19 +00:00
|
|
|
switch(m_State)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
case IUpdater::GOT_MANIFEST:
|
|
|
|
PerformUpdate();
|
|
|
|
break;
|
|
|
|
case IUpdater::MOVE_FILES:
|
|
|
|
CommitUpdate();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
void CUpdater::AddFileJob(const char *pFile, bool Job)
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2017-11-23 14:47:38 +00:00
|
|
|
m_FileJobs[string(pFile)] = Job;
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 19:38:52 +00:00
|
|
|
bool CUpdater::ReplaceClient()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2016-05-02 19:35:32 +00:00
|
|
|
dbg_msg("updater", "replacing " PLAT_CLIENT_EXEC);
|
2019-04-04 19:38:52 +00:00
|
|
|
bool Success = true;
|
2021-09-13 08:06:34 +00:00
|
|
|
char aPath[IO_MAX_PATH_LENGTH];
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2017-11-23 02:10:15 +00:00
|
|
|
// Replace running executable by renaming twice...
|
2021-08-23 10:05:01 +00:00
|
|
|
m_pStorage->RemoveBinaryFile(CLIENT_EXEC ".old");
|
|
|
|
Success &= m_pStorage->RenameBinaryFile(PLAT_CLIENT_EXEC, CLIENT_EXEC ".old");
|
|
|
|
str_format(aPath, sizeof(aPath), "update/%s", m_aClientExecTmp);
|
|
|
|
Success &= m_pStorage->RenameBinaryFile(aPath, PLAT_CLIENT_EXEC);
|
2020-09-26 19:41:58 +00:00
|
|
|
#if !defined(CONF_FAMILY_WINDOWS)
|
|
|
|
m_pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aPath, sizeof aPath);
|
|
|
|
char aBuf[512];
|
|
|
|
str_format(aBuf, sizeof aBuf, "chmod +x %s", aPath);
|
|
|
|
if(system(aBuf))
|
|
|
|
{
|
|
|
|
dbg_msg("updater", "ERROR: failed to set client executable bit");
|
|
|
|
Success = false;
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-04 19:38:52 +00:00
|
|
|
return Success;
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
2015-02-27 21:09:04 +00:00
|
|
|
|
2019-04-04 19:38:52 +00:00
|
|
|
bool CUpdater::ReplaceServer()
|
2015-03-13 14:13:19 +00:00
|
|
|
{
|
2016-05-02 19:35:32 +00:00
|
|
|
dbg_msg("updater", "replacing " PLAT_SERVER_EXEC);
|
2019-04-04 19:38:52 +00:00
|
|
|
bool Success = true;
|
2021-09-13 08:06:34 +00:00
|
|
|
char aPath[IO_MAX_PATH_LENGTH];
|
2015-03-13 14:13:19 +00:00
|
|
|
|
|
|
|
//Replace running executable by renaming twice...
|
2020-02-12 21:39:37 +00:00
|
|
|
m_pStorage->RemoveBinaryFile(SERVER_EXEC ".old");
|
|
|
|
Success &= m_pStorage->RenameBinaryFile(PLAT_SERVER_EXEC, SERVER_EXEC ".old");
|
|
|
|
str_format(aPath, sizeof(aPath), "update/%s", m_aServerExecTmp);
|
|
|
|
Success &= m_pStorage->RenameBinaryFile(aPath, PLAT_SERVER_EXEC);
|
2020-09-26 19:41:58 +00:00
|
|
|
#if !defined(CONF_FAMILY_WINDOWS)
|
|
|
|
m_pStorage->GetBinaryPath(PLAT_SERVER_EXEC, aPath, sizeof aPath);
|
|
|
|
char aBuf[512];
|
|
|
|
str_format(aBuf, sizeof aBuf, "chmod +x %s", aPath);
|
|
|
|
if(system(aBuf))
|
|
|
|
{
|
|
|
|
dbg_msg("updater", "ERROR: failed to set server executable bit");
|
|
|
|
Success = false;
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-04 19:38:52 +00:00
|
|
|
return Success;
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::ParseUpdate()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2021-09-13 08:06:34 +00:00
|
|
|
char aPath[IO_MAX_PATH_LENGTH];
|
2022-06-14 18:55:39 +00:00
|
|
|
void *pBuf;
|
|
|
|
unsigned Length;
|
|
|
|
if(!m_pStorage->ReadFile(m_pStorage->GetBinaryPath("update/update.json", aPath, sizeof aPath), IStorage::TYPE_ABSOLUTE, &pBuf, &Length))
|
2017-07-08 11:38:27 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-14 18:55:39 +00:00
|
|
|
json_value *pVersions = json_parse((json_char *)pBuf, Length);
|
2020-06-24 22:09:11 +00:00
|
|
|
free(pBuf);
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2017-07-08 11:38:27 +00:00
|
|
|
if(pVersions && pVersions->type == json_array)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < json_array_length(pVersions); i++)
|
2015-03-13 14:13:19 +00:00
|
|
|
{
|
2017-07-08 11:38:27 +00:00
|
|
|
const json_value *pTemp;
|
|
|
|
const json_value *pCurrent = json_array_get(pVersions, i);
|
2019-03-06 20:02:06 +00:00
|
|
|
if(str_comp(json_string_get(json_object_get(pCurrent, "version")), GAME_RELEASE_VERSION))
|
2015-03-13 14:13:19 +00:00
|
|
|
{
|
2017-07-08 11:38:27 +00:00
|
|
|
if(json_boolean_get(json_object_get(pCurrent, "client")))
|
|
|
|
m_ClientUpdate = true;
|
|
|
|
if(json_boolean_get(json_object_get(pCurrent, "server")))
|
|
|
|
m_ServerUpdate = true;
|
|
|
|
if((pTemp = json_object_get(pCurrent, "download"))->type == json_array)
|
|
|
|
{
|
|
|
|
for(int j = 0; j < json_array_length(pTemp); j++)
|
|
|
|
AddFileJob(json_string_get(json_array_get(pTemp, j)), true);
|
|
|
|
}
|
|
|
|
if((pTemp = json_object_get(pCurrent, "remove"))->type == json_array)
|
2015-03-13 14:13:19 +00:00
|
|
|
{
|
2017-07-08 11:38:27 +00:00
|
|
|
for(int j = 0; j < json_array_length(pTemp); j++)
|
|
|
|
AddFileJob(json_string_get(json_array_get(pTemp, j)), false);
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-08 11:38:27 +00:00
|
|
|
else
|
|
|
|
break;
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::InitiateUpdate()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2015-03-13 14:13:19 +00:00
|
|
|
m_State = GETTING_MANIFEST;
|
|
|
|
FetchFile("update.json");
|
2014-12-31 14:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
void CUpdater::PerformUpdate()
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2015-03-13 14:13:19 +00:00
|
|
|
m_State = PARSING_UPDATE;
|
2016-05-02 19:35:32 +00:00
|
|
|
dbg_msg("updater", "parsing update.json");
|
2015-03-13 14:13:19 +00:00
|
|
|
ParseUpdate();
|
|
|
|
m_State = DOWNLOADING;
|
|
|
|
|
2020-02-12 21:39:37 +00:00
|
|
|
const char *pLastFile;
|
|
|
|
pLastFile = "";
|
2017-03-04 14:43:49 +00:00
|
|
|
for(map<string, bool>::reverse_iterator it = m_FileJobs.rbegin(); it != m_FileJobs.rend(); ++it)
|
|
|
|
{
|
|
|
|
if(it->second)
|
|
|
|
{
|
2020-02-12 21:39:37 +00:00
|
|
|
pLastFile = it->first.c_str();
|
2015-08-29 20:41:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
2015-08-29 20:41:29 +00:00
|
|
|
|
2020-10-26 14:14:07 +00:00
|
|
|
for(auto &FileJob : m_FileJobs)
|
2015-03-13 14:13:19 +00:00
|
|
|
{
|
2020-10-26 14:14:07 +00:00
|
|
|
if(FileJob.second)
|
2015-08-29 20:41:29 +00:00
|
|
|
{
|
2020-10-26 14:14:07 +00:00
|
|
|
const char *pFile = FileJob.first.c_str();
|
2016-05-01 11:11:51 +00:00
|
|
|
size_t len = str_length(pFile);
|
|
|
|
if(!str_comp_nocase(pFile + len - 4, ".dll"))
|
|
|
|
{
|
|
|
|
#if defined(CONF_FAMILY_WINDOWS)
|
|
|
|
char aBuf[512];
|
|
|
|
str_copy(aBuf, pFile, sizeof(aBuf)); // SDL
|
|
|
|
str_copy(aBuf + len - 4, "-" PLAT_NAME, sizeof(aBuf) - len + 4); // -win32
|
|
|
|
str_append(aBuf, pFile + len - 4, sizeof(aBuf)); // .dll
|
|
|
|
FetchFile(aBuf, pFile);
|
2020-08-26 08:41:47 +00:00
|
|
|
#endif
|
|
|
|
// Ignore DLL downloads on other platforms
|
|
|
|
}
|
|
|
|
else if(!str_comp_nocase(pFile + len - 3, ".so"))
|
|
|
|
{
|
|
|
|
#if defined(CONF_PLATFORM_LINUX)
|
|
|
|
char aBuf[512];
|
|
|
|
str_copy(aBuf, pFile, sizeof(aBuf)); // libsteam_api
|
|
|
|
str_copy(aBuf + len - 3, "-" PLAT_NAME, sizeof(aBuf) - len + 3); // -linux-x86_64
|
|
|
|
str_append(aBuf, pFile + len - 3, sizeof(aBuf)); // .so
|
|
|
|
FetchFile(aBuf, pFile);
|
2016-05-01 11:11:51 +00:00
|
|
|
#endif
|
|
|
|
// Ignore DLL downloads on other platforms, on Linux we statically link anyway
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FetchFile(pFile);
|
|
|
|
}
|
2020-02-12 21:39:37 +00:00
|
|
|
pLastFile = pFile;
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
|
|
|
else
|
2020-10-26 14:14:07 +00:00
|
|
|
m_pStorage->RemoveBinaryFile(FileJob.first.c_str());
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|
2015-08-29 20:41:29 +00:00
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
if(m_ServerUpdate)
|
2015-08-29 20:41:29 +00:00
|
|
|
{
|
2020-02-12 21:39:37 +00:00
|
|
|
FetchFile(PLAT_SERVER_DOWN, m_aServerExecTmp);
|
|
|
|
pLastFile = m_aServerExecTmp;
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
2015-03-13 14:13:19 +00:00
|
|
|
if(m_ClientUpdate)
|
2015-08-29 20:41:29 +00:00
|
|
|
{
|
2020-02-12 21:39:37 +00:00
|
|
|
FetchFile(PLAT_CLIENT_DOWN, m_aClientExecTmp);
|
|
|
|
pLastFile = m_aClientExecTmp;
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 21:39:37 +00:00
|
|
|
str_copy(m_aLastFile, pLastFile, sizeof(m_aLastFile));
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUpdater::CommitUpdate()
|
|
|
|
{
|
2019-04-04 19:38:52 +00:00
|
|
|
bool Success = true;
|
|
|
|
|
2020-10-26 14:14:07 +00:00
|
|
|
for(auto &FileJob : m_FileJobs)
|
|
|
|
if(FileJob.second)
|
|
|
|
Success &= MoveFile(FileJob.first.c_str());
|
2015-08-29 20:41:29 +00:00
|
|
|
|
|
|
|
if(m_ClientUpdate)
|
2019-04-04 19:38:52 +00:00
|
|
|
Success &= ReplaceClient();
|
2015-08-29 20:41:29 +00:00
|
|
|
if(m_ServerUpdate)
|
2019-04-04 19:38:52 +00:00
|
|
|
Success &= ReplaceServer();
|
|
|
|
if(!Success)
|
|
|
|
m_State = FAIL;
|
|
|
|
else if(m_pClient->State() == IClient::STATE_ONLINE || m_pClient->EditorHasUnsavedData())
|
2015-08-29 20:41:29 +00:00
|
|
|
m_State = NEED_RESTART;
|
|
|
|
else
|
|
|
|
{
|
2021-08-23 10:05:01 +00:00
|
|
|
m_pClient->Restart();
|
2015-08-29 20:41:29 +00:00
|
|
|
}
|
2015-03-13 14:13:19 +00:00
|
|
|
}
|