Skip to content

Commit

Permalink
Make a bundle in c++ use pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jul 18, 2018
1 parent 683313b commit 7f8ccd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,8 @@ void DownloadManager::RequestChartLeaderBoard(string chartkey)
SendRequest("/charts/"+chartkey+"/leaderboards", vector<pair<string, string>>(), done, true);
}

vector<DownloadablePack> DownloadManager::GetCoreBundle(string whichoneyo) {
vector<DownloadablePack> bundle;
vector<DownloadablePack*> DownloadManager::GetCoreBundle(string whichoneyo) {
vector<DownloadablePack*> bundle;
auto done = [this, &bundle](HTTPRequest& req, CURLMsg *) {
try {
json j= json::parse(req.result);
Expand All @@ -990,7 +990,7 @@ vector<DownloadablePack> DownloadManager::GetCoreBundle(string whichoneyo) {
auto dlPack = find_if(dlPacks.begin(), dlPacks.end(),
[&name](DownloadablePack x) { return x.name == name; });
if(dlPack != dlPacks.end())
bundle.emplace_back(*dlPack);
bundle.emplace_back(dlPack);
}
}
catch (exception e) { }
Expand All @@ -1001,8 +1001,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>();
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),
Expand All @@ -1018,14 +1018,14 @@ void DownloadManager::DownloadCoreBundle(string whichoneyo) {
if (it != list->end()) {
auto pack = *it;
list->pop_front();
auto newDl = DLMAN->DownloadAndInstallPack(pack.url);
auto newDl = DLMAN->DownloadAndInstallPack(pack->url);
newDl->Done = dl->Done;
}
else {
delete list;
}
};
auto dl = DLMAN->DownloadAndInstallPack(pack.url);
auto dl = DLMAN->DownloadAndInstallPack(pack->url);
dl->Done = down;
}

Expand Down Expand Up @@ -1589,7 +1589,7 @@ class LunaDownloadManager : public Luna<DownloadManager>
auto bundle = DLMAN->GetCoreBundle(SArg(1));
lua_createtable(L, bundle.size(), 0);
for (int i = 0; i < bundle.size(); ++i) {
bundle[i].PushSelf(L);
bundle[i]->PushSelf(L);
lua_rawseti(L, -2, i + 1);
}
return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/DownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class DownloadManager
// most recent single score upload result -mina
RString mostrecentresult = "";
void DownloadCoreBundle(string whichoneyo);
vector<DownloadablePack> GetCoreBundle(string whichoneyo);
vector<DownloadablePack*> GetCoreBundle(string whichoneyo);

// Lua
void PushSelf(lua_State *L);
Expand Down

0 comments on commit 7f8ccd9

Please sign in to comment.