2014-10-29 12:37:38 +00:00
|
|
|
#ifndef ENGINE_CLIENT_FETCHER_H
|
|
|
|
#define ENGINE_CLIENT_FETCHER_H
|
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
#include <engine/shared/jobs.h>
|
|
|
|
#include <engine/storage.h>
|
|
|
|
#include <engine/kernel.h>
|
2014-10-29 12:37:38 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
class CFetchTask : public IJob
|
2014-10-29 12:37:38 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-11-23 14:47:38 +00:00
|
|
|
IStorage *m_pStorage;
|
2017-09-23 21:11:12 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
char m_aUrl[256];
|
|
|
|
char m_aDest[128];
|
|
|
|
int m_StorageType;
|
|
|
|
bool m_UseDDNetCA;
|
|
|
|
bool m_CanTimeout;
|
|
|
|
|
|
|
|
double m_Size;
|
|
|
|
double m_Current;
|
|
|
|
int m_Progress;
|
|
|
|
int m_State;
|
2014-10-29 12:37:38 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
std::atomic<bool> m_Abort;
|
|
|
|
|
|
|
|
virtual void OnProgress() { }
|
|
|
|
virtual void OnCompletion() { }
|
2017-09-23 21:11:12 +00:00
|
|
|
|
2014-10-29 12:37:38 +00:00
|
|
|
static int ProgressCallback(void *pUser, double DlTotal, double DlCurr, double UlTotal, double UlCurr);
|
2017-11-23 14:47:38 +00:00
|
|
|
static size_t WriteCallback(char *pData, size_t Size, size_t Number, void *pFile);
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STATE_ERROR = -1,
|
|
|
|
STATE_QUEUED,
|
|
|
|
STATE_RUNNING,
|
|
|
|
STATE_DONE,
|
|
|
|
STATE_ABORTED,
|
|
|
|
};
|
|
|
|
|
|
|
|
CFetchTask(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, bool UseDDNetCA = false, bool CanTimeout = true);
|
|
|
|
|
|
|
|
double Current() const;
|
|
|
|
double Size() const;
|
|
|
|
int Progress() const;
|
|
|
|
int State() const;
|
|
|
|
const char *Dest() const;
|
|
|
|
void Abort();
|
2014-10-29 12:37:38 +00:00
|
|
|
};
|
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
bool FetcherInit();
|
|
|
|
void EscapeUrl(char *pBud, int Size, const char *pStr);
|
2014-10-29 12:37:38 +00:00
|
|
|
#endif
|