DDraceNetwork Docs
updater.h
Go to the documentation of this file.
1#ifndef ENGINE_CLIENT_UPDATER_H
2#define ENGINE_CLIENT_UPDATER_H
3
4#include <base/detect.h>
5#include <base/lock.h>
6
7#include <engine/updater.h>
8
9#include <forward_list>
10#include <memory>
11#include <string>
12
13#define CLIENT_EXEC "DDNet"
14#define SERVER_EXEC "DDNet-Server"
15
16#if defined(CONF_FAMILY_WINDOWS)
17#define PLAT_EXT ".exe"
18#define PLAT_NAME CONF_PLATFORM_STRING
19#elif defined(CONF_FAMILY_UNIX)
20#define PLAT_EXT ""
21#if defined(CONF_ARCH_IA32)
22#define PLAT_NAME CONF_PLATFORM_STRING "-x86"
23#elif defined(CONF_ARCH_AMD64)
24#define PLAT_NAME CONF_PLATFORM_STRING "-x86_64"
25#else
26#define PLAT_NAME CONF_PLATFORM_STRING "-unsupported"
27#endif
28#else
29#if defined(AUTOUPDATE)
30#error Compiling with autoupdater on an unsupported platform
31#endif
32#define PLAT_EXT ""
33#define PLAT_NAME "unsupported-unsupported"
34#endif
35
36#define PLAT_CLIENT_DOWN CLIENT_EXEC "-" PLAT_NAME PLAT_EXT
37#define PLAT_SERVER_DOWN SERVER_EXEC "-" PLAT_NAME PLAT_EXT
38
39#define PLAT_CLIENT_EXEC CLIENT_EXEC PLAT_EXT
40#define PLAT_SERVER_EXEC SERVER_EXEC PLAT_EXT
41
43
44class CUpdater : public IUpdater
45{
46 friend class CUpdaterFetchTask;
47
51 class CHttp *m_pHttp;
52
54
56 char m_aStatus[256] GUARDED_BY(m_Lock);
57 int m_Percent GUARDED_BY(m_Lock);
60
61 std::forward_list<std::pair<std::string, bool>> m_FileJobs;
62 std::shared_ptr<CUpdaterFetchTask> m_pCurrentTask;
63 decltype(m_FileJobs)::iterator m_CurrentJob;
64
67
70
71 void AddFileJob(const char *pFile, bool Job);
72 void FetchFile(const char *pFile, const char *pDestPath = nullptr) REQUIRES(!m_Lock);
73 bool MoveFile(const char *pFile);
74
79
80 bool ReplaceClient();
81 bool ReplaceServer();
82
84
85public:
86 CUpdater();
87
89 void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock);
90 int GetCurrentPercent() override REQUIRES(!m_Lock);
91
92 void InitiateUpdate() REQUIRES(!m_Lock) override;
93 void Init(CHttp *pHttp);
94 void Update() REQUIRES(!m_Lock) override;
95};
96
97#endif
Definition: http.h:266
std::atomic< EState > m_State
Definition: http.h:278
Definition: lock.h:88
Definition: updater.cpp:18
Definition: updater.h:45
void ParseUpdate() REQUIRES(!m_Lock)
Definition: updater.cpp:236
void InitiateUpdate() REQUIRES(!m_Lock) override
Definition: updater.cpp:277
void PerformUpdate() REQUIRES(!m_Lock)
Definition: updater.cpp:283
char m_aStatus[256] GUARDED_BY(m_Lock)
bool m_ClientFetched
Definition: updater.h:68
decltype(m_FileJobs) ::iterator m_CurrentJob
Definition: updater.h:63
void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock)
Definition: updater.cpp:113
class IClient * m_pClient
Definition: updater.h:48
void Init(CHttp *pHttp)
Definition: updater.cpp:93
void AddFileJob(const char *pFile, bool Job)
Definition: updater.cpp:183
bool MoveFile(const char *pFile)
Definition: updater.cpp:133
std::forward_list< std::pair< std::string, bool > > m_FileJobs
Definition: updater.h:61
int m_Percent GUARDED_BY(m_Lock)
bool ReplaceServer()
Definition: updater.cpp:212
bool ReplaceClient()
Definition: updater.cpp:188
EUpdaterState m_State GUARDED_BY(m_Lock)
std::shared_ptr< CUpdaterFetchTask > m_pCurrentTask
Definition: updater.h:62
EUpdaterState GetCurrentState() override REQUIRES(!m_Lock)
Definition: updater.cpp:107
bool m_ClientUpdate
Definition: updater.h:65
class IEngine * m_pEngine
Definition: updater.h:50
class CHttp * m_pHttp
Definition: updater.h:51
CLock m_Lock
Definition: updater.h:53
char m_aClientExecTmp[64]
Definition: updater.h:58
class IStorage * m_pStorage
Definition: updater.h:49
bool m_ServerFetched
Definition: updater.h:69
char m_aServerExecTmp[64]
Definition: updater.h:59
void SetCurrentState(EUpdaterState NewState) REQUIRES(!m_Lock)
Definition: updater.cpp:101
int GetCurrentPercent() override REQUIRES(!m_Lock)
Definition: updater.cpp:119
void CommitUpdate() REQUIRES(!m_Lock)
Definition: updater.cpp:367
void Update() REQUIRES(!m_Lock) override
Definition: updater.cpp:165
bool m_ServerUpdate
Definition: updater.h:66
void RunningUpdate() REQUIRES(!m_Lock)
Definition: updater.cpp:292
void FetchFile(const char *pFile, const char *pDestPath=nullptr) REQUIRES(!m_Lock)
Definition: updater.cpp:125
Definition: client.h:36
Definition: engine.h:15
Definition: storage.h:20
Definition: updater.h:7
EUpdaterState
Definition: updater.h:11
#define REQUIRES(...)
Definition: lock.h:32