diff --git a/src/engine/client/updater.cpp b/src/engine/client/updater.cpp index a5a0af2ef..782956785 100644 --- a/src/engine/client/updater.cpp +++ b/src/engine/client/updater.cpp @@ -98,13 +98,13 @@ void CUpdater::Init(CHttp *pHttp) m_pHttp = pHttp; } -void CUpdater::SetCurrentState(int NewState) +void CUpdater::SetCurrentState(EUpdaterState NewState) { CLockScope ls(m_Lock); m_State = NewState; } -int CUpdater::GetCurrentState() +IUpdater::EUpdaterState CUpdater::GetCurrentState() { CLockScope ls(m_Lock); return m_State; @@ -164,8 +164,7 @@ bool CUpdater::MoveFile(const char *pFile) void CUpdater::Update() { - auto State = GetCurrentState(); - switch(State) + switch(GetCurrentState()) { case IUpdater::GOT_MANIFEST: PerformUpdate(); diff --git a/src/engine/client/updater.h b/src/engine/client/updater.h index 746c81b02..4127ca5e3 100644 --- a/src/engine/client/updater.h +++ b/src/engine/client/updater.h @@ -52,7 +52,7 @@ class CUpdater : public IUpdater 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); int m_Percent GUARDED_BY(m_Lock); char m_aClientExecTmp[64]; @@ -80,12 +80,12 @@ class CUpdater : public IUpdater bool ReplaceClient(); bool ReplaceServer(); - void SetCurrentState(int NewState) REQUIRES(!m_Lock); + void SetCurrentState(EUpdaterState NewState) REQUIRES(!m_Lock); public: CUpdater(); - int GetCurrentState() override REQUIRES(!m_Lock); + EUpdaterState GetCurrentState() override REQUIRES(!m_Lock); void GetCurrentFile(char *pBuf, int BufSize) override REQUIRES(!m_Lock); int GetCurrentPercent() override REQUIRES(!m_Lock); diff --git a/src/engine/shared/http.cpp b/src/engine/shared/http.cpp index 6b72e980d..c69da07dc 100644 --- a/src/engine/shared/http.cpp +++ b/src/engine/shared/http.cpp @@ -308,7 +308,7 @@ int CHttpRequest::ProgressCallback(void *pUser, double DlTotal, double DlCurr, d CHttpRequest *pTask = (CHttpRequest *)pUser; pTask->m_Current.store(DlCurr, std::memory_order_relaxed); pTask->m_Size.store(DlTotal, std::memory_order_relaxed); - pTask->m_Progress.store((100 * DlCurr) / (DlTotal ? DlTotal : 1), std::memory_order_relaxed); + pTask->m_Progress.store(DlTotal == 0.0 ? 0 : (100 * DlCurr) / DlTotal, std::memory_order_relaxed); pTask->OnProgress(); return pTask->m_Abort ? -1 : 0; } diff --git a/src/engine/updater.h b/src/engine/updater.h index 8a3be8651..3de864091 100644 --- a/src/engine/updater.h +++ b/src/engine/updater.h @@ -7,9 +7,9 @@ class IUpdater : public IInterface { MACRO_INTERFACE("updater") public: - enum + enum EUpdaterState { - CLEAN = 0, + CLEAN, GETTING_MANIFEST, GOT_MANIFEST, PARSING_UPDATE, @@ -22,7 +22,7 @@ public: virtual void Update() = 0; virtual void InitiateUpdate() = 0; - virtual int GetCurrentState() = 0; + virtual EUpdaterState GetCurrentState() = 0; virtual void GetCurrentFile(char *pBuf, int BufSize) = 0; virtual int GetCurrentPercent() = 0; }; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index a14191a47..00be5dd49 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -3402,7 +3402,7 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView) #if defined(CONF_AUTOUPDATE) { bool NeedUpdate = str_comp(Client()->LatestVersion(), "0"); - int State = Updater()->GetCurrentState(); + IUpdater::EUpdaterState State = Updater()->GetCurrentState(); // Update Button char aBuf[256]; diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index 4b3421d1d..f32af9ff8 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -206,7 +206,7 @@ void CMenus::RenderStartMenu(CUIRect MainView) #if defined(CONF_AUTOUPDATE) char aBuf[64]; CUIRect Part; - int State = Updater()->GetCurrentState(); + IUpdater::EUpdaterState State = Updater()->GetCurrentState(); bool NeedUpdate = str_comp(Client()->LatestVersion(), "0"); if(State == IUpdater::CLEAN && NeedUpdate) {