-
Notifications
You must be signed in to change notification settings - Fork 126
/
autoupdater.h
117 lines (86 loc) · 2.47 KB
/
autoupdater.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef AUTOUPDATER_H
#define AUTOUPDATER_H
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QDir>
#include <QFile>
#include <QThread>
#include <QUrl>
#include <QUrlQuery>
#include <QProcessEnvironment>
#include <QQueue>
#include <QVector>
#include <QProcess>
#include <QNetworkConfigurationManager>
// Mixing C and C++ :(
extern "C" {
#include <verifysig.h>
}
#define FILE_READ_CHUNK 8192
// TODO Move to somewhere? Document that we can override?
#define SERVER_FNAME "server.js"
#define ASAR_FNAME "stremio.asar"
#define PARTIAL_UPDATE_FILES { SERVER_FNAME, ASAR_FNAME }
#if defined(Q_OS_WIN)
#define FULL_UPDATE_FILES { "windows" }
#elif defined(Q_OS_MACOS)
#define FULL_UPDATE_FILES { "mac" }
#elif defined(Q_OS_LINUX)
#define FULL_UPDATE_FILES { "linux" }
#else
#define FULL_UPDATE_FILES { }
#endif
typedef QPair<QUrl, QByteArray> fDownload;
class AutoUpdater : public QObject
{
Q_OBJECT
public:
AutoUpdater();
public slots:
bool isInstalled();
void checkForUpdates(QString, QString);
void updateFromVersionDesc(QUrl, QByteArray);
void abort();
void setForceFullUpdate(bool);
bool moveFileToAppDir(QString);
int executeCmd(QString, QStringList, bool);
signals:
void performPing();
void networkStatus(bool);
void error(QString, QVariant);
void checkFinished(QVariant);
void prepared(QVariantList, QVariant);
private slots:
void abortPerform();
void checkForUpdatesPerform(QString, QString);
void checkForUpdatesFinished();
void updateFromVersionDescPerform(QUrl, QByteArray);
void updateFromVersionDescFinished();
void prepareUpdate(QJsonDocument);
void downloadFinished();
void downloadReadyRead();
void emitFatalError(QString, QVariant);
private:
void enqueueDownload(QUrl, QByteArray);
void startNextDownload();
QByteArray getFileChecksum(QString);
QNetworkAccessManager* manager = NULL;
// State; must be reset on abort
QJsonDocument currentVersionDesc;
QNetworkReply* currentCheck = NULL;
QNetworkReply* currentDownload = NULL;
QFile output;
// Download queue, prepared files
QQueue<fDownload> downloadQueue;
QVariantList preparedFiles;
// options
bool forceFullUpdate = false;
// progress tracking
bool inProgress = false;
};
#endif // AUTOUPDATER_H