This commit is contained in:
parent
63acb4374d
commit
6f89e0f052
@ -19,6 +19,7 @@ namespace Components
|
|||||||
|
|
||||||
Download::CLDownload.Running = true;
|
Download::CLDownload.Running = true;
|
||||||
Download::CLDownload.Mod = mod;
|
Download::CLDownload.Mod = mod;
|
||||||
|
Download::CLDownload.TerminateThread = false;
|
||||||
Download::CLDownload.Target = Party::Target();
|
Download::CLDownload.Target = Party::Target();
|
||||||
Download::CLDownload.Thread = std::thread(Download::ModDownloader, &Download::CLDownload);
|
Download::CLDownload.Thread = std::thread(Download::ModDownloader, &Download::CLDownload);
|
||||||
}
|
}
|
||||||
@ -125,7 +126,7 @@ namespace Components
|
|||||||
mg_mgr_init(&download->Mgr, &fDownload);
|
mg_mgr_init(&download->Mgr, &fDownload);
|
||||||
mg_connect_http(&download->Mgr, Download::DownloadHandler, url.data(), NULL, NULL);
|
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);
|
mg_mgr_poll(&download->Mgr, 0);
|
||||||
}
|
}
|
||||||
@ -164,6 +165,8 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (download->TerminateThread) return;
|
||||||
|
|
||||||
if (!Download::ParseModList(download, list))
|
if (!Download::ParseModList(download, list))
|
||||||
{
|
{
|
||||||
download->Thread.detach();
|
download->Thread.detach();
|
||||||
@ -177,8 +180,12 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (download->TerminateThread) return;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < download->Files.size(); ++i)
|
for (unsigned int i = 0; i < download->Files.size(); ++i)
|
||||||
{
|
{
|
||||||
|
if (download->TerminateThread) return;
|
||||||
|
|
||||||
if (!Download::DownloadFile(download, i))
|
if (!Download::DownloadFile(download, i))
|
||||||
{
|
{
|
||||||
Dvar::Var("partyend_reason").Set(fmt::sprintf("Failed to download file: %s!", download->Files[i].Name.data()));
|
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;
|
static std::string mod = download->Mod;
|
||||||
|
|
||||||
download->Thread.detach();
|
download->Thread.detach();
|
||||||
|
@ -16,11 +16,12 @@ namespace Components
|
|||||||
class ClientDownload
|
class ClientDownload
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientDownload() : Valid(false), Running(false) {}
|
ClientDownload() : Valid(false), Running(false), TerminateThread(false) {}
|
||||||
~ClientDownload() { this->Clear(); }
|
~ClientDownload() { this->Clear(); }
|
||||||
|
|
||||||
bool Running;
|
bool Running;
|
||||||
bool Valid;
|
bool Valid;
|
||||||
|
bool TerminateThread;
|
||||||
mg_mgr Mgr;
|
mg_mgr Mgr;
|
||||||
Network::Address Target;
|
Network::Address Target;
|
||||||
std::string Mod;
|
std::string Mod;
|
||||||
@ -28,6 +29,7 @@ namespace Components
|
|||||||
std::thread Thread;
|
std::thread Thread;
|
||||||
std::string Progress;
|
std::string Progress;
|
||||||
|
|
||||||
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -40,6 +42,13 @@ namespace Components
|
|||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
|
this->TerminateThread = true;
|
||||||
|
|
||||||
|
if (this->Thread.joinable())
|
||||||
|
{
|
||||||
|
this->Thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
this->Running = false;
|
this->Running = false;
|
||||||
this->Mod.clear();
|
this->Mod.clear();
|
||||||
this->Files.clear();
|
this->Files.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user