Skip to content

Commit

Permalink
Fix pack bundle dls (Hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jul 18, 2018
1 parent 08b65b3 commit 6c5cb16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
41 changes: 15 additions & 26 deletions src/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ inline CURL* initCURLHandle() {
struct curl_slist *list = NULL;
list = curl_slist_append(list, ("Authorization: Bearer " + DLMAN->authToken).c_str());
curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, list);
curl_easy_setopt(curlHandle, CURLOPT_TIMEOUT, 60);//Seconds
curl_easy_setopt(curlHandle, CURLOPT_TIMEOUT, 120);//Seconds
return curlHandle;
}
inline bool addFileToForm(curl_httppost *&form, curl_httppost *&lastPtr, string field, string fileName, string filePath, RString &contents)
Expand Down Expand Up @@ -366,6 +366,10 @@ Download* DownloadManager::DownloadAndInstallPack(DownloadablePack* pack)
return nullptr;
}
}
if (downloadingPacks >= maxPacksToDownloadAtOnce) {
DLMAN->DownloadQueue.emplace_back(pack);
return nullptr;
}
Download* dl = DownloadAndInstallPack(pack->url);
dl->p_Pack = pack;
return dl;
Expand Down Expand Up @@ -453,6 +457,7 @@ void DownloadManager::UpdateHTTP(float fDeltaSeconds)
}
void DownloadManager::UpdatePacks(float fDeltaSeconds)
{
timeSinceLastDownload += fDeltaSeconds;
if (pendingInstallDownloads.size() > 0 && !gameplay) {
//Install all pending packs
for (auto i = pendingInstallDownloads.begin(); i != pendingInstallDownloads.end(); i++) {
Expand All @@ -470,6 +475,12 @@ void DownloadManager::UpdatePacks(float fDeltaSeconds)
else
SONGMAN->DifferentialReload();
}
if (downloadingPacks < maxPacksToDownloadAtOnce && !DownloadQueue.empty() && timeSinceLastDownload > DownloadCooldownTime) {
auto it = DownloadQueue.begin();
DownloadQueue.pop_front();
auto pack = *it;
auto dl = DLMAN->DownloadAndInstallPack(pack);
}
if (!downloadingPacks)
return;
timeval timeout;
Expand Down Expand Up @@ -521,6 +532,7 @@ void DownloadManager::UpdatePacks(float fDeltaSeconds)
if (i->second->p_RFWrapper.file.IsOpen())
i->second->p_RFWrapper.file.Close();
if (msg->msg == CURLMSG_DONE) {
timeSinceLastDownload = 0;
i->second->Done(i->second);
if (!gameplay) {
installedPacks = true;
Expand Down Expand Up @@ -1034,31 +1046,8 @@ vector<DownloadablePack*> DownloadManager::GetCoreBundle(string whichoneyo) {
void DownloadManager::DownloadCoreBundle(string whichoneyo) {
auto bundle = GetCoreBundle(whichoneyo);
sort(bundle.begin(), bundle.end(), [](DownloadablePack* x1, DownloadablePack* x2) {return x1->size < x2->size; });
std::deque<DownloadablePack*>* list = new std::deque<DownloadablePack*>();
std::move(
begin(bundle),
end(bundle),
back_inserter(*list)
);
auto it = list->begin();
if (it == list->end())
return;
auto pack = *it;
list->pop_front();
function<void(Download*)> down = [list](Download* dl) {
auto it = list->begin();
if (it != list->end()) {
auto pack = *it;
list->pop_front();
auto newDl = DLMAN->DownloadAndInstallPack(pack->url);
newDl->Done = dl->Done;
}
else {
delete list;
}
};
auto dl = DLMAN->DownloadAndInstallPack(pack->url);
dl->Done = down;
for (auto pack : bundle)
DLMAN->DownloadQueue.emplace_back(pack);
}

void DownloadManager::RefreshLastVersion()
Expand Down
5 changes: 5 additions & 0 deletions src/DownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "RageFileManager.h"
#include "curl/curl.h"
#include "Difficulty.h"
#include <deque>

class DownloadablePack;

Expand Down Expand Up @@ -199,6 +200,10 @@ class DownloadManager

// most recent single score upload result -mina
RString mostrecentresult = "";
std::deque<DownloadablePack*> DownloadQueue;
const int maxPacksToDownloadAtOnce = 1;
const long DownloadCooldownTime = 5;
long timeSinceLastDownload = 0;
void DownloadCoreBundle(string whichoneyo);
vector<DownloadablePack*> GetCoreBundle(string whichoneyo);

Expand Down

0 comments on commit 6c5cb16

Please sign in to comment.