forked from blastrock/pkgj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgi_downloader.hpp
68 lines (54 loc) · 1.36 KB
/
pkgi_downloader.hpp
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
#pragma once
#include <atomic>
#include <deque>
#include <mutex>
#include <optional>
#include <vector>
#include "pkgi_thread.hpp"
enum Type
{
Game,
Update,
Dlc,
PsxGame,
PspGame,
};
struct DownloadItem
{
Type type;
std::string name;
std::string content;
std::string url;
std::vector<uint8_t> rif;
std::vector<uint8_t> digest;
bool save_as_iso;
};
std::string type_to_string(Type type);
class Downloader
{
public:
Downloader(const Downloader&) = delete;
Downloader(Downloader&&) = delete;
Downloader& operator=(const Downloader&) = delete;
Downloader& operator=(Downloader&&) = delete;
Downloader();
~Downloader();
void add(const DownloadItem& d);
void remove_from_queue(const std::string& contentid);
bool is_in_queue(const std::string& titleid);
std::optional<DownloadItem> get_current_download();
float get_current_download_progress();
std::function<void(const std::string& content)> refresh;
std::function<void(const std::string& error)> error;
private:
using ScopeLock = std::lock_guard<Mutex>;
Cond _cond;
std::deque<DownloadItem> _queue;
DownloadItem _current_download;
bool _cancel_current = false;
std::atomic<float> _progress = 0.0f;
Thread _thread;
bool _dying = false;
void run();
void do_download(const DownloadItem& item);
};