From 7b9b7af4d67440fe2c95b7ce121e989c4263f3ea Mon Sep 17 00:00:00 2001 From: Barinade Date: Wed, 23 Sep 2020 15:26:26 -0500 Subject: [PATCH] DLMAN: queued pack getter, remove from queue, consistency fix, bool fix to support some stuff down the line --- src/Etterna/Singletons/DownloadManager.cpp | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Etterna/Singletons/DownloadManager.cpp b/src/Etterna/Singletons/DownloadManager.cpp index 5b04d10152..b9fdd6ba7b 100644 --- a/src/Etterna/Singletons/DownloadManager.cpp +++ b/src/Etterna/Singletons/DownloadManager.cpp @@ -599,7 +599,9 @@ DownloadManager::UpdatePacks(float fDeltaSeconds) auto it = DownloadQueue.begin(); DownloadQueue.pop_front(); auto pack = *it; - auto dl = DLMAN->DownloadAndInstallPack(pack.first, pack.second); + auto* dl = DLMAN->DownloadAndInstallPack(pack.first, pack.second); + if (dl) + dl->p_Pack->downloading = true; } if (!downloadingPacks) return; @@ -2381,6 +2383,15 @@ class LunaDownloadManager : public Luna } return 1; } + static int GetQueuedPacks(T* p, lua_State* L) + { + lua_createtable(L, p->DownloadQueue.size(), 0); + for (unsigned i = 0; i < p->DownloadQueue.size(); i++) { + p->DownloadQueue[i].first->PushSelf(L); + lua_rawseti(L, -2, i + 1); + } + return 1; + } static int GetUsername(T* p, lua_State* L) { lua_pushstring(L, DLMAN->sessionUser.c_str()); @@ -2775,6 +2786,7 @@ class LunaDownloadManager : public Luna ADD_METHOD(GetCoreBundle); ADD_METHOD(GetAllPacks); ADD_METHOD(GetDownloadingPacks); + ADD_METHOD(GetQueuedPacks); ADD_METHOD(GetDownloads); ADD_METHOD(GetToken); ADD_METHOD(IsLoggedIn); @@ -2818,8 +2830,10 @@ class LunaDownloadablePack : public Luna bool mirror = false; if (lua_gettop(L) > 0) mirror = BArg(1); - if (p->downloading) + if (p->downloading) { + p->PushSelf(L); return 1; + } Download* dl = DLMAN->DownloadAndInstallPack(p, mirror); if (dl) { dl->PushSelf(L); @@ -2853,6 +2867,22 @@ class LunaDownloadablePack : public Luna lua_pushboolean(L, it != DLMAN->DownloadQueue.end()); return 1; } + static int RemoveFromQueue(T* p, lua_State* L) + { + auto it = std::find_if( + DLMAN->DownloadQueue.begin(), + DLMAN->DownloadQueue.end(), + [p](pair pair) { return pair.first == p; }); + if (it == DLMAN->DownloadQueue.end()) + // does not exist + lua_pushboolean(L, false); + else { + DLMAN->DownloadQueue.erase(it); + // success? + lua_pushboolean(L, true); + } + return 1; + } static int IsDownloading(T* p, lua_State* L) { lua_pushboolean(L, p->downloading == 0); @@ -2881,6 +2911,7 @@ class LunaDownloadablePack : public Luna ADD_METHOD(DownloadAndInstall); ADD_METHOD(IsDownloading); ADD_METHOD(IsQueued); + ADD_METHOD(RemoveFromQueue); ADD_METHOD(GetAvgDifficulty); ADD_METHOD(GetName); ADD_METHOD(GetSize);