forked from KLN90B/KLN90B-GPS-for-FSX-P3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTTPDownloader.h
73 lines (57 loc) · 1.45 KB
/
HTTPDownloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
This file is part of swan2 project.
Copyright (C) 2013 by Nick Sharmanzhinov
except134@gmail.com
*/
#pragma once
namespace swan2
{
namespace lib
{
namespace core
{
#define HTTP_BUFFER_SIZE (16384)
enum
{
HTTP_STATE_WORKING = 0,
HTTP_STATE_COMPLETE,
HTTP_STATE_CANCELED,
HTTP_STATE_ERROR,
HTTP_STATE_NONE,
};
class DownloadManager;
class HTTPDownloader
{
public:
HTTPDownloader();
virtual ~HTTPDownloader();
int Create(DownloadManager* pParent);
int Download(const char* szURL,const char* szDestination);
void Cancel();
int GetState() { return curState; };
int GetFileSize() const { return fileSize; };
const std::string& GetURL() const { return urlPath; };
const std::string& GetDstFileName() const { return dstFile; };
void Release();
void OnError();
void OnComplete();
void OnCancel();
private:
static DWORD DownloadProc(HTTPDownloader* _this);
void CreateThread();
DWORD DoDownload();
void PrepareBuffer();
std::string urlPath;
std::string dstFile;
HANDLE dlThread;
HINTERNET inetHandle;
HINTERNET urlHandle;
unsigned char* dlBuffer;
int fileSize;
volatile int curState;
volatile bool isContinue;
DownloadManager* parentManager;
};
}
}
}