Merge pull request #8514 from Robyt3/Updater-Cleanup

Minor cleanup of updater and HTTP client
This commit is contained in:
archimede67 2024-06-23 18:18:54 +00:00 committed by GitHub
commit 62c3c4274d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 12 additions and 13 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
};

View file

@ -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];

View file

@ -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)
{