2015-04-18 19:17:27 +00:00
|
|
|
#ifndef ENGINE_CLIENT_UPDATER_H
|
|
|
|
#define ENGINE_CLIENT_UPDATER_H
|
2014-12-31 14:29:34 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/updater.h>
|
2015-08-29 20:41:29 +00:00
|
|
|
#include <map>
|
2014-12-31 14:29:34 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
#define CLIENT_EXEC "DDNet"
|
|
|
|
#define SERVER_EXEC "DDNet-Server"
|
|
|
|
|
|
|
|
#if defined(CONF_FAMILY_WINDOWS)
|
2020-09-26 19:41:58 +00:00
|
|
|
#define PLAT_EXT ".exe"
|
|
|
|
#define PLAT_NAME CONF_PLATFORM_STRING
|
2015-03-13 14:13:19 +00:00
|
|
|
#elif defined(CONF_FAMILY_UNIX)
|
2020-09-26 19:41:58 +00:00
|
|
|
#define PLAT_EXT ""
|
|
|
|
#if defined(CONF_ARCH_IA32)
|
|
|
|
#define PLAT_NAME CONF_PLATFORM_STRING "-x86"
|
|
|
|
#elif defined(CONF_ARCH_AMD64)
|
|
|
|
#define PLAT_NAME CONF_PLATFORM_STRING "-x86_64"
|
|
|
|
#else
|
|
|
|
#define PLAT_NAME CONF_PLATFORM_STRING "-unsupported"
|
|
|
|
#endif
|
2015-03-14 10:31:06 +00:00
|
|
|
#else
|
2020-09-26 19:41:58 +00:00
|
|
|
#define PLAT_EXT ""
|
|
|
|
#define PLAT_NAME "unsupported-unsupported"
|
2015-03-13 14:13:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PLAT_CLIENT_DOWN CLIENT_EXEC "-" PLAT_NAME PLAT_EXT
|
|
|
|
#define PLAT_SERVER_DOWN SERVER_EXEC "-" PLAT_NAME PLAT_EXT
|
|
|
|
|
|
|
|
#define PLAT_CLIENT_EXEC CLIENT_EXEC PLAT_EXT
|
|
|
|
#define PLAT_SERVER_EXEC SERVER_EXEC PLAT_EXT
|
|
|
|
|
2015-04-18 19:17:27 +00:00
|
|
|
class CUpdater : public IUpdater
|
2014-12-31 14:29:34 +00:00
|
|
|
{
|
2017-11-23 14:47:38 +00:00
|
|
|
friend class CUpdaterFetchTask;
|
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
class IClient *m_pClient;
|
|
|
|
class IStorage *m_pStorage;
|
2017-11-23 14:47:38 +00:00
|
|
|
class IEngine *m_pEngine;
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
LOCK m_Lock;
|
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
int m_State;
|
2020-12-02 18:11:19 +00:00
|
|
|
char m_aStatus[256] GUARDED_BY(m_Lock);
|
|
|
|
int m_Percent GUARDED_BY(m_Lock);
|
2015-03-13 14:13:19 +00:00
|
|
|
char m_aLastFile[256];
|
2020-02-12 21:39:37 +00:00
|
|
|
char m_aClientExecTmp[64];
|
|
|
|
char m_aServerExecTmp[64];
|
2015-03-13 14:13:19 +00:00
|
|
|
|
|
|
|
bool m_ClientUpdate;
|
|
|
|
bool m_ServerUpdate;
|
|
|
|
|
2015-08-29 20:41:29 +00:00
|
|
|
std::map<std::string, bool> m_FileJobs;
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
void AddFileJob(const char *pFile, bool Job);
|
2015-03-13 14:13:19 +00:00
|
|
|
void FetchFile(const char *pFile, const char *pDestPath = 0);
|
2019-04-04 19:38:52 +00:00
|
|
|
bool MoveFile(const char *pFile);
|
2015-03-13 14:13:19 +00:00
|
|
|
|
|
|
|
void ParseUpdate();
|
|
|
|
void PerformUpdate();
|
2015-08-29 20:41:29 +00:00
|
|
|
void CommitUpdate();
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2019-04-04 19:38:52 +00:00
|
|
|
bool ReplaceClient();
|
|
|
|
bool ReplaceServer();
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2022-05-28 00:14:46 +00:00
|
|
|
void SetCurrentState(int NewState) REQUIRES(!m_Lock);
|
2017-11-23 14:47:38 +00:00
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
public:
|
2015-04-18 19:17:27 +00:00
|
|
|
CUpdater();
|
2017-11-23 14:47:38 +00:00
|
|
|
~CUpdater();
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2022-05-28 00:14:46 +00:00
|
|
|
int GetCurrentState() override REQUIRES(!m_Lock);
|
|
|
|
void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock);
|
|
|
|
int GetCurrentPercent() override REQUIRES(!m_Lock);
|
2015-03-13 14:13:19 +00:00
|
|
|
|
2022-05-17 20:13:44 +00:00
|
|
|
void InitiateUpdate() override;
|
2015-03-13 14:13:19 +00:00
|
|
|
void Init();
|
2022-05-17 20:13:44 +00:00
|
|
|
void Update() override;
|
2014-12-31 14:29:34 +00:00
|
|
|
};
|
|
|
|
|
2015-03-13 14:13:19 +00:00
|
|
|
#endif
|