This commit is contained in:
momo5502 2016-08-31 18:12:31 +02:00
parent 63acb4374d
commit 6f89e0f052
2 changed files with 20 additions and 2 deletions

View File

@ -19,6 +19,7 @@ namespace Components
Download::CLDownload.Running = true;
Download::CLDownload.Mod = mod;
Download::CLDownload.TerminateThread = false;
Download::CLDownload.Target = Party::Target();
Download::CLDownload.Thread = std::thread(Download::ModDownloader, &Download::CLDownload);
}
@ -125,7 +126,7 @@ namespace Components
mg_mgr_init(&download->Mgr, &fDownload);
mg_connect_http(&download->Mgr, Download::DownloadHandler, url.data(), NULL, NULL);
while (fDownload.downloading)
while (fDownload.downloading && !fDownload.download->TerminateThread)
{
mg_mgr_poll(&download->Mgr, 0);
}
@ -164,6 +165,8 @@ namespace Components
return;
}
if (download->TerminateThread) return;
if (!Download::ParseModList(download, list))
{
download->Thread.detach();
@ -177,8 +180,12 @@ namespace Components
return;
}
if (download->TerminateThread) return;
for (unsigned int i = 0; i < download->Files.size(); ++i)
{
if (download->TerminateThread) return;
if (!Download::DownloadFile(download, i))
{
Dvar::Var("partyend_reason").Set(fmt::sprintf("Failed to download file: %s!", download->Files[i].Name.data()));
@ -197,6 +204,8 @@ namespace Components
}
}
if (download->TerminateThread) return;
static std::string mod = download->Mod;
download->Thread.detach();

View File

@ -16,11 +16,12 @@ namespace Components
class ClientDownload
{
public:
ClientDownload() : Valid(false), Running(false) {}
ClientDownload() : Valid(false), Running(false), TerminateThread(false) {}
~ClientDownload() { this->Clear(); }
bool Running;
bool Valid;
bool TerminateThread;
mg_mgr Mgr;
Network::Address Target;
std::string Mod;
@ -28,6 +29,7 @@ namespace Components
std::thread Thread;
std::string Progress;
class File
{
public:
@ -40,6 +42,13 @@ namespace Components
void Clear()
{
this->TerminateThread = true;
if (this->Thread.joinable())
{
this->Thread.join();
}
this->Running = false;
this->Mod.clear();
this->Files.clear();