From 826363dfa3749f363785a8470705845e013c2509 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 17 Dec 2017 02:27:12 -0300 Subject: [PATCH] Delete everything in Cache/Downloads (temp files) on destruction and construction of DLMAN --- src/DownloadManager.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index cf632fa5a1..06d5ee1ec2 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -35,6 +35,7 @@ static Preference packListURL("packListURL", "https://etternaonline.com static Preference serverURL("UploadServerURL", "https://etternaonline.com/api"); static Preference automaticSync("automaticScoreSync", 1); static const string TEMP_ZIP_MOUNT_POINT = "/@temp-zip/"; +static const string DL_DIR = SpecialFiles::CACHE_DIR + "Downloads/"; size_t write_memory_buffer(void *contents, size_t size, size_t nmemb, void *userp) { @@ -230,7 +231,17 @@ inline void SetCURLFormPostField(CURL* curlHandle, curl_httppost *&form, curl_ht { CURLFormPostField(curlHandle, form, lastPtr, field.c_str(), to_string(value).c_str()); } +inline void EmptyTempDLFileDir() +{ + vector files; + FILEMAN->GetDirListing(DL_DIR + "*", files, false, true); + for (auto& file : files) { + if (FILEMAN->IsAFile(file)) + FILEMAN->Remove(file); + } +} DownloadManager::DownloadManager() { + EmptyTempDLFileDir(); curl_global_init(CURL_GLOBAL_ALL); // Register with Lua. { @@ -245,6 +256,7 @@ DownloadManager::DownloadManager() { DownloadManager::~DownloadManager() { + EmptyTempDLFileDir(); if (mHandle != nullptr) curl_multi_cleanup(mHandle); mHandle = nullptr; @@ -428,7 +440,7 @@ bool DownloadManager::UpdateAndIsFinished(float fDeltaSeconds) string Download::MakeTempFileName(string s) { - return SpecialFiles::CACHE_DIR + "Downloads/" + Basename(s); + return DL_DIR + Basename(s); } bool DownloadManager::LoggedIn() {