From 1f34ed674026b63df2b37d5f968820b715b70835 Mon Sep 17 00:00:00 2001 From: Learath Lea Date: Fri, 13 Mar 2015 21:17:23 +0200 Subject: [PATCH 1/2] Call the completion callback even on a fail. --- src/engine/client/fetcher.cpp | 14 ++++++++------ src/engine/client/fetcher.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/engine/client/fetcher.cpp b/src/engine/client/fetcher.cpp index 89c7b31a1..81172ad84 100644 --- a/src/engine/client/fetcher.cpp +++ b/src/engine/client/fetcher.cpp @@ -91,7 +91,7 @@ void CFetcher::FetcherThread(void *pUser) } } -bool CFetcher::FetchFile(CFetchTask *pTask) +void CFetcher::FetchFile(CFetchTask *pTask) { for(int i = 0; pTask->m_pDest[i] != '\0'; i++) { @@ -126,18 +126,20 @@ bool CFetcher::FetchFile(CFetchTask *pTask) dbg_msg("fetcher", "Downloading %s", pTask->m_pDest); pTask->m_State = CFetchTask::STATE_RUNNING; int ret = curl_easy_perform(m_pHandle); + io_close(File); if(ret != CURLE_OK) { dbg_msg("fetcher", "Task failed. libcurl error: %s", aErr); pTask->m_State = (ret == CURLE_ABORTED_BY_CALLBACK) ? CFetchTask::STATE_ABORTED : CFetchTask::STATE_ERROR; - return false; } - io_close(File); - dbg_msg("fetcher", "Task done %s", pTask->m_pDest); - pTask->m_State = CFetchTask::STATE_DONE; + else + { + dbg_msg("fetcher", "Task done %s", pTask->m_pDest); + pTask->m_State = CFetchTask::STATE_DONE; + + } if(pTask->m_pfnCompCallback) pTask->m_pfnCompCallback(pTask, pTask->m_pUser); - return true; } void CFetcher::WriteToFile(char *pData, size_t size, size_t nmemb, void *pFile) diff --git a/src/engine/client/fetcher.h b/src/engine/client/fetcher.h index 7803f5ea5..9096e75e9 100644 --- a/src/engine/client/fetcher.h +++ b/src/engine/client/fetcher.h @@ -25,7 +25,7 @@ public: virtual void QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest, int StorageType = 2, void *pUser = 0, COMPFUNC pfnCompCb = 0, PROGFUNC pfnProgCb = 0); virtual void Escape(char *pBud, size_t size, const char *pStr); static void FetcherThread(void *pUser); - bool FetchFile(CFetchTask *pTask); + void FetchFile(CFetchTask *pTask); static void WriteToFile(char *pData, size_t size, size_t nmemb, void *pFile); static int ProgressCallback(void *pUser, double DlTotal, double DlCurr, double UlTotal, double UlCurr); }; From b75a7563676c4274528bd407122c885670b5d73e Mon Sep 17 00:00:00 2001 From: Learath Lea Date: Fri, 13 Mar 2015 21:18:00 +0200 Subject: [PATCH 2/2] Don't get stuck on a manifest fail. --- src/engine/autoupdate.h | 1 + src/engine/client/autoupdate.cpp | 5 ++++- src/game/client/components/menus_browser.cpp | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/engine/autoupdate.h b/src/engine/autoupdate.h index 89e78e1a1..2b2008d09 100644 --- a/src/engine/autoupdate.h +++ b/src/engine/autoupdate.h @@ -16,6 +16,7 @@ public: PARSING_UPDATE, DOWNLOADING, NEED_RESTART, + FAIL_MANIFEST, }; virtual void Update() = 0; diff --git a/src/engine/client/autoupdate.cpp b/src/engine/client/autoupdate.cpp index 2a3423b69..ddea091a6 100644 --- a/src/engine/client/autoupdate.cpp +++ b/src/engine/client/autoupdate.cpp @@ -39,7 +39,10 @@ void CAutoUpdate::CompletionCallback(CFetchTask *pTask, void *pUser) CAutoUpdate *pUpdate = (CAutoUpdate *)pUser; if(!str_comp(pTask->Dest(), "update.json")) { - pUpdate->m_State = GOT_MANIFEST; + if(pTask->State() == CFetchTask::STATE_DONE) + pUpdate->m_State = GOT_MANIFEST; + else if(pTask->State() == CFetchTask::STATE_ERROR) + pUpdate->m_State = FAIL_MANIFEST; } else if(!str_comp(pTask->Dest(), pUpdate->m_aLastFile)) { diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 879bd837d..628bc4606 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1292,6 +1292,11 @@ void CMenus::RenderServerbrowser(CUIRect MainView) str_format(aBuf, sizeof(aBuf), Localize("Current version: %s"), GAME_VERSION); else if(State >= IAutoUpdate::GETTING_MANIFEST && State < IAutoUpdate::NEED_RESTART) str_format(aBuf, sizeof(aBuf), "Downloading %s:", AutoUpdate()->GetCurrentFile()); + else if(State == IAutoUpdate::FAIL_MANIFEST) + { + str_format(aBuf, sizeof(aBuf), "Failed to download manifest!"); + TextRender()->TextColor(1.0f, 0.4f, 0.4f, 1.0f); + } else if(State == IAutoUpdate::NEED_RESTART) { str_format(aBuf, sizeof(aBuf), "DDNet Client updated!");