Use named enum EUpdaterState instead of int

This commit is contained in:
Robert Müller 2024-06-23 13:46:22 +02:00
parent 80ff5157d0
commit c4b9924b28
5 changed files with 11 additions and 12 deletions

View file

@ -98,13 +98,13 @@ void CUpdater::Init(CHttp *pHttp)
m_pHttp = pHttp; m_pHttp = pHttp;
} }
void CUpdater::SetCurrentState(int NewState) void CUpdater::SetCurrentState(EUpdaterState NewState)
{ {
CLockScope ls(m_Lock); CLockScope ls(m_Lock);
m_State = NewState; m_State = NewState;
} }
int CUpdater::GetCurrentState() IUpdater::EUpdaterState CUpdater::GetCurrentState()
{ {
CLockScope ls(m_Lock); CLockScope ls(m_Lock);
return m_State; return m_State;
@ -164,8 +164,7 @@ bool CUpdater::MoveFile(const char *pFile)
void CUpdater::Update() void CUpdater::Update()
{ {
auto State = GetCurrentState(); switch(GetCurrentState())
switch(State)
{ {
case IUpdater::GOT_MANIFEST: case IUpdater::GOT_MANIFEST:
PerformUpdate(); PerformUpdate();

View file

@ -52,7 +52,7 @@ class CUpdater : public IUpdater
CLock m_Lock; CLock m_Lock;
int m_State GUARDED_BY(m_Lock); EUpdaterState m_State GUARDED_BY(m_Lock);
char m_aStatus[256] GUARDED_BY(m_Lock); char m_aStatus[256] GUARDED_BY(m_Lock);
int m_Percent GUARDED_BY(m_Lock); int m_Percent GUARDED_BY(m_Lock);
char m_aClientExecTmp[64]; char m_aClientExecTmp[64];
@ -80,12 +80,12 @@ class CUpdater : public IUpdater
bool ReplaceClient(); bool ReplaceClient();
bool ReplaceServer(); bool ReplaceServer();
void SetCurrentState(int NewState) REQUIRES(!m_Lock); void SetCurrentState(EUpdaterState NewState) REQUIRES(!m_Lock);
public: public:
CUpdater(); CUpdater();
int GetCurrentState() override REQUIRES(!m_Lock); EUpdaterState GetCurrentState() override REQUIRES(!m_Lock);
void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock); void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock);
int GetCurrentPercent() override REQUIRES(!m_Lock); int GetCurrentPercent() override REQUIRES(!m_Lock);

View file

@ -7,9 +7,9 @@ class IUpdater : public IInterface
{ {
MACRO_INTERFACE("updater") MACRO_INTERFACE("updater")
public: public:
enum enum EUpdaterState
{ {
CLEAN = 0, CLEAN,
GETTING_MANIFEST, GETTING_MANIFEST,
GOT_MANIFEST, GOT_MANIFEST,
PARSING_UPDATE, PARSING_UPDATE,
@ -22,7 +22,7 @@ public:
virtual void Update() = 0; virtual void Update() = 0;
virtual void InitiateUpdate() = 0; virtual void InitiateUpdate() = 0;
virtual int GetCurrentState() = 0; virtual EUpdaterState GetCurrentState() = 0;
virtual void GetCurrentFile(char *pBuf, int BufSize) = 0; virtual void GetCurrentFile(char *pBuf, int BufSize) = 0;
virtual int GetCurrentPercent() = 0; virtual int GetCurrentPercent() = 0;
}; };

View file

@ -3402,7 +3402,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView)
#if defined(CONF_AUTOUPDATE) #if defined(CONF_AUTOUPDATE)
{ {
bool NeedUpdate = str_comp(Client()->LatestVersion(), "0"); bool NeedUpdate = str_comp(Client()->LatestVersion(), "0");
int State = Updater()->GetCurrentState(); IUpdater::EUpdaterState State = Updater()->GetCurrentState();
// Update Button // Update Button
char aBuf[256]; char aBuf[256];

View file

@ -206,7 +206,7 @@ void CMenus::RenderStartMenu(CUIRect MainView)
#if defined(CONF_AUTOUPDATE) #if defined(CONF_AUTOUPDATE)
char aBuf[64]; char aBuf[64];
CUIRect Part; CUIRect Part;
int State = Updater()->GetCurrentState(); IUpdater::EUpdaterState State = Updater()->GetCurrentState();
bool NeedUpdate = str_comp(Client()->LatestVersion(), "0"); bool NeedUpdate = str_comp(Client()->LatestVersion(), "0");
if(State == IUpdater::CLEAN && NeedUpdate) if(State == IUpdater::CLEAN && NeedUpdate)
{ {