Skip to content

Commit

Permalink
Dont download packs already loaded and fix a crash for null download (#…
Browse files Browse the repository at this point in the history
…104)

calls from lua
  • Loading branch information
nico-abram authored and MinaciousGrace committed Nov 16, 2017
1 parent b73d93b commit 5d1f844
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/DownloadManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#pragma once

#include "global.h"
#if !defined(WITHOUT_NETWORKING)
#include "RageFileManager.h"
#include "ScreenManager.h"
#include "Preference.h"
Expand All @@ -15,6 +18,7 @@
#include "curl/curl.h"
#include "JsonUtil.h"
#include "Foreach.h"
#include "Song.h"

shared_ptr<DownloadManager> DLMAN = nullptr;

Expand Down Expand Up @@ -103,7 +107,6 @@ void DownloadManager::InstallSmzip(const string &sZipFile)
}


#if !defined(WITHOUT_NETWORKING)

int progressfunc(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
Expand Down Expand Up @@ -212,6 +215,15 @@ void Download::Update(float fDeltaSeconds)
}
Download* DownloadManager::DownloadAndInstallPack(DownloadablePack* pack)
{
auto songs = SONGMAN->GetAllSongs();
vector<RString> packs;
SONGMAN->GetSongGroupNames(packs);
for (auto packName : packs) {
if (packName == pack->name) {
SCREENMAN->SystemMessage("Already have pack " + packName + ", not downloading");
return nullptr;
}
}
Download* dl = DownloadAndInstallPack(pack->url);
dl->p_Pack = pack;
return dl;
Expand Down Expand Up @@ -298,7 +310,9 @@ bool DownloadManager::UpdateAndIsFinished(float fDeltaSeconds)
if (i->second->handle != nullptr)
curl_easy_cleanup(i->second->handle);
i->second->handle = nullptr;
delete i->second;
if (i->second->p_Pack != nullptr)
i->second->p_Pack->downloading = false;
finishedDownloads[i->second->m_Url] = i->second;
downloads.erase(i);
break;
}
Expand Down Expand Up @@ -588,7 +602,11 @@ class LunaDownloadablePack : public Luna<DownloadablePack>
if (p->downloading)
return 1;
p->downloading = true;
DLMAN->DownloadAndInstallPack(p)->PushSelf(L);
Download * dl = DLMAN->DownloadAndInstallPack(p);
if (dl)
dl->PushSelf(L);
else
lua_pushnil(L);
return 1;
}
static int GetName(T* p, lua_State* L)
Expand Down Expand Up @@ -661,7 +679,7 @@ class LunaDownload : public Luna<Download>

LUA_REGISTER_CLASS(Download)

#endif



#endif
3 changes: 2 additions & 1 deletion src/DownloadManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#pragma once
#ifndef SM_DOWNMANAGER

#define SM_DOWNMANAGER
Expand Down Expand Up @@ -81,6 +81,7 @@ class DownloadManager
DownloadManager();
~DownloadManager();
map<string, Download*> downloads;
map<string, Download*> finishedDownloads;
CURLM* mHandle{nullptr};
CURLMcode ret;
int running{0};
Expand Down

0 comments on commit 5d1f844

Please sign in to comment.