Skip to content

Commit

Permalink
Delete everything in Cache/Downloads (temp files) on destruction and
Browse files Browse the repository at this point in the history
construction of DLMAN
  • Loading branch information
nico-abram committed Dec 17, 2017
1 parent 0c58a6a commit 826363d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static Preference<RString> packListURL("packListURL", "https://etternaonline.com
static Preference<RString> serverURL("UploadServerURL", "https://etternaonline.com/api");
static Preference<unsigned int> 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)
{
Expand Down Expand Up @@ -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<RString> 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.
{
Expand All @@ -245,6 +256,7 @@ DownloadManager::DownloadManager() {

DownloadManager::~DownloadManager()
{
EmptyTempDLFileDir();
if (mHandle != nullptr)
curl_multi_cleanup(mHandle);
mHandle = nullptr;
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit 826363d

Please sign in to comment.