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
42class CUpdaterFetchTask;
43
44class CUpdater : public IUpdater
45{
46 friend class CUpdaterFetchTask;
47
48 class IClient *m_pClient;
49 class IStorage *m_pStorage;
50 class IEngine *m_pEngine;
51 class CHttp *m_pHttp;
52
53 CLock m_Lock;
54
55 EUpdaterState m_State GUARDED_BY(m_Lock);
56 char m_aStatus[256] GUARDED_BY(m_Lock);
57 int m_Percent GUARDED_BY(m_Lock);
58 char m_aClientExecTmp[64];
59 char m_aServerExecTmp[64];
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
65 bool m_ClientUpdate;
66 bool m_ServerUpdate;
67
68 bool m_ClientFetched;
69 bool m_ServerFetched;
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
75 void ParseUpdate() REQUIRES(!m_Lock);
76 void PerformUpdate() REQUIRES(!m_Lock);
77 void RunningUpdate() REQUIRES(!m_Lock);
78 void CommitUpdate() REQUIRES(!m_Lock);
79
80 bool ReplaceClient();
81 bool ReplaceServer();
82
83 void SetCurrentState(EUpdaterState NewState) REQUIRES(!m_Lock);
84
85public:
86 CUpdater();
87
88 EUpdaterState GetCurrentState() override REQUIRES(!m_Lock);
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
98