iw4x-client/src/Components/Modules/Download.hpp

94 lines
1.9 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
2017-01-19 16:23:59 -05:00
namespace Components
{
class Download : public Component
{
public:
Download();
~Download();
void preDestroy() override;
2018-12-17 08:29:18 -05:00
static void InitiateClientDownload(const std::string& mod, bool needPassword, bool map = false);
static void InitiateMapDownload(const std::string& map, bool needPassword);
2017-01-19 16:23:59 -05:00
private:
class ClientDownload
{
public:
2017-04-06 16:22:47 -04:00
ClientDownload(bool _isMap = false) : running(false), valid(false), terminateThread(false), isMap(_isMap), totalBytes(0), downBytes(0), lastTimeStamp(0), timeStampBytes(0) {}
2017-01-19 16:23:59 -05:00
~ClientDownload() { this->clear(); }
bool running;
bool valid;
bool terminateThread;
2017-04-06 16:22:47 -04:00
bool isMap;
bool isPrivate;
2017-01-19 16:23:59 -05:00
Network::Address target;
std::string hashedPassword;
2017-01-19 16:23:59 -05:00
std::string mod;
std::thread thread;
2022-10-28 06:52:34 -04:00
std::size_t totalBytes;
std::size_t downBytes;
2017-01-19 16:23:59 -05:00
int lastTimeStamp;
2022-10-28 06:52:34 -04:00
std::size_t timeStampBytes;
2017-01-19 16:23:59 -05:00
class File
{
public:
std::string name;
std::string hash;
2022-10-28 06:52:34 -04:00
std::size_t size;
2017-01-19 16:23:59 -05:00
};
std::vector<File> files;
void clear()
{
this->terminateThread = true;
if (this->thread.joinable())
{
this->thread.join();
}
this->running = false;
this->mod.clear();
this->files.clear();
if (this->valid)
{
this->valid = false;
}
}
};
class FileDownload
{
public:
ClientDownload* download;
ClientDownload::File file;
int timestamp;
bool downloading;
unsigned int index;
std::string buffer;
2022-10-28 06:52:34 -04:00
std::size_t receivedBytes;
2017-01-19 16:23:59 -05:00
};
static ClientDownload CLDownload;
2017-05-25 14:18:20 -04:00
static std::thread ServerThread;
static bool Terminate;
2022-06-28 03:26:43 -04:00
static bool ServerRunning;
2017-01-19 16:23:59 -05:00
2022-10-28 06:52:34 -04:00
static void DownloadProgress(FileDownload* fDownload, std::size_t bytes);
2017-01-19 16:23:59 -05:00
static void ModDownloader(ClientDownload* download);
2018-12-17 08:29:18 -05:00
static bool ParseModList(ClientDownload* download, const std::string& list);
2017-01-19 16:23:59 -05:00
static bool DownloadFile(ClientDownload* download, unsigned int index);
};
}