-
Notifications
You must be signed in to change notification settings - Fork 14
/
googleapkdownloadtask.h
79 lines (58 loc) · 2.42 KB
/
googleapkdownloadtask.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
74
75
76
77
78
79
#ifndef GOOGLEAPKDOWNLOADTASK_H
#define GOOGLEAPKDOWNLOADTASK_H
#include <QObject>
#include <QTemporaryFile>
#include <QMutex>
#include <zlib.h>
#include <playapi/api.h>
#include <utility>
#include "googleplayapi.h"
struct DownloadProgress {
std::mutex mtx;
size_t downloadsize;
size_t downloads;
std::vector<size_t> progress;
};
class GoogleApkDownloadTask : public QObject {
Q_OBJECT
Q_PROPERTY(GooglePlayApi* playApi WRITE setPlayApi)
Q_PROPERTY(QString packageName WRITE setPackageName READ packageName)
Q_PROPERTY(qint32 versionCode WRITE setVersionCode READ versionCode)
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
Q_PROPERTY(QStringList filePaths READ filePaths)
Q_PROPERTY(bool keepApks READ keepApks WRITE setKeepApks)
Q_PROPERTY(bool dryrun MEMBER m_dryrun)
private:
GooglePlayApi* m_playApi = nullptr;
QString m_packageName;
qint32 m_versionCode;
QMutex fileMutex;
std::vector<std::shared_ptr<QTemporaryFile>> files;
std::atomic_bool m_active;
bool m_keepApks = false;
bool m_dryrun = false;
void startDownload(playapi::proto::finsky::download::AndroidAppDeliveryData const &dd, bool skipMainApk = false);
static bool curlDoZlibInflate(z_stream& zs, int file, char* data, size_t len, int flags);
template<class T, class U> void downloadFile(T const&dd, U cookie, std::function<void()> success, std::function<void()> error, std::shared_ptr<DownloadProgress> progress, std::string componentName, size_t id);
public:
explicit GoogleApkDownloadTask(QObject *parent = nullptr);
void setPlayApi(GooglePlayApi* value);
bool active() const { return m_active; }
bool keepApks() const { return m_keepApks; }
void setKeepApks(bool keepApks) { m_keepApks = keepApks; }
QString packageName() const { return m_packageName; }
void setPackageName(QString packageName) { m_packageName = packageName; }
qint32 versionCode() const { return m_versionCode; }
void setVersionCode(qint32 versionCode) { m_versionCode = versionCode; }
QStringList filePaths();
signals:
void progress(qreal progress);
void finished();
void error(QString const& err);
void activeChanged();
void queueDownload(playapi::proto::finsky::download::AndroidAppDeliveryData dd, bool skipMainApk);
void downloadInfo(QString const& url);
public slots:
void start(bool skipMainApk = false);
};
#endif // GOOGLEAPKDOWNLOADTASK_H