-
Notifications
You must be signed in to change notification settings - Fork 1
/
engineupdater.h
178 lines (164 loc) · 6.38 KB
/
engineupdater.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
RPG Paper Maker Copyright (C) 2017 Marie Laporte
This file is part of RPG Paper Maker.
RPG Paper Maker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RPG Paper Maker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ENGINEUPDATER_H
#define ENGINEUPDATER_H
#include <QCoreApplication>
#include <QJsonObject>
#include <QJsonArray>
#include <QNetworkReply>
#include <QComboBox>
#include <QMutex>
#include <QFile>
#include "engineupdatefilekind.h"
// -------------------------------------------------------
//
// CLASS EngineUpdater
//
// Module used for detecting if the engine needs to be updated
//
// -------------------------------------------------------
class EngineUpdater : public QObject
{
Q_OBJECT
public:
EngineUpdater();
virtual ~EngineUpdater();
QString messageError() const;
bool hasUpdaterExpired() const;
QString lastVersion() const;
static const QString VERSION;
static const QString ELECTRON_VERSION;
static const QString LARGE_FILES_UPDATE_VERSION;
static const QString jsonFiles;
static const QString jsonSource;
static const QString jsonTarget;
static const QString jsonRepo;
static const QString jsonOS;
static const QString jsonWindows;
static const QString jsonLinux;
static const QString jsonMac;
static const QString jsonOnlyFiles;
static const QString jsonSymLink;
static const QString jsonExe;
static const QString jsonLarge;
static const QString jsonAdd;
static const QString jsonReplace;
static const QString jsonRemove;
static const QString jsonTree;
static const QString jsonScripts;
static const QString jsonGames;
static const QString jsonEngineWin;
static const QString jsonEngineLinux;
static const QString jsonEngineMac;
static const QString jsonContent;
static const QString jsonBR;
static const QString jsonEngineExe;
static const QString jsonGameExe;
static const QString jsonTranslations;
static const QString jsonExample;
static const QString gitRepoEngine;
static QString gitRepoGame;
static QString gitRepoGameBuild;
static const QString gitRepoDependencies;
static const QString gitRepoBR;
static const QString pathGitHub;
static void startEngineProcess();
static bool isNeedUpdate();
static void writeTrees();
static void writeTree(QString path, QString gitRepo, QString targetPath,
QJsonObject &objTree);
static void getTree(QJsonObject& objTree, QString localUrl, QString path,
QString targetUrl, QString repo);
static void getJSONFile(QJsonObject &obj, QString source, QString target,
QString repo, bool link, bool isDir);
static void getJSONDir(QJsonObject &obj, QJsonArray& files, QString target);
static void getJSONExeEngine(QJsonObject &obj, QString os);
static void getJSONExeGame(QJsonObject &obj, QString os);
static int countObjJson(QJsonObject& obj);
static int countArrayJson(QJsonArray& files);
static int countObjUpdate(QJsonObject& obj);
bool hasVersion() const;
QString getVersionJson() const;
void changeNeedUpdate(bool checked);
void start();
void updateVersion(QString &version);
bool download(EngineUpdateFileKind action, QJsonObject& obj,
QString& version);
bool downloadFile(EngineUpdateFileKind action, QJsonObject& obj,
QString &version);
bool addFile(QString source, QString target, QString repo,
QString version, bool exe, bool link);
bool addFileURL(QUrl &url, QString source, QString target, bool exe, bool link, QString path);
void removeFile(QString& target);
bool replaceFile(QString source, QString target, QString repo,
QString version, bool exe, bool link);
bool downloadFolder(EngineUpdateFileKind action, QJsonObject& obj,
QString &version, bool onlyFiles = false);
bool addFolder(QString& target, QJsonArray& files, QString &version,
bool onlyFiles = false);
void removeFolder(QString& target, bool onlyFiles = false);
bool replaceFolder(QString& target, QJsonArray& files, QString& version,
bool onlyFiles = false);
void downloadExecutables();
bool downloadScripts(QString version);
void getVersions(QJsonArray& versions);
bool check();
bool readDocumentVersion();
bool readTrees(QString& version);
void writeVersion(QString& version);
void setCurrentCount(int c);
void fillVersionsComboBox(QComboBox *comboBox);
void downloadTranslations(QString version);
void downloadLargeFiles(QString version);
void downloadLargeFile(QString version, QString filename, QString target);
void updateUpdater();
void downloadExampleProject();
void removeFilesLeftTarget(QString target);
void downloadCompleted();
void removeOldExe();
protected:
QNetworkAccessManager *m_manager;
QJsonObject m_document;
QJsonArray m_versions;
int m_index;
QString m_currentVersion;
QString m_lastVersion;
QString m_updaterVersion;
QString m_largeVersion;
QString m_messageError;
QString m_focusProgress;
int m_countFiles;
int m_totalFiles;
QVector<QPair<QString, QString>> m_links;
QJsonArray m_versionsContent;
QMutex m_mutex;
QList<QJsonObject> m_filesLeft;
QTimer *m_timer;
public slots:
void downloadEngine(bool isLastVersion, QString oldVersion);
void update();
void handleReading(QNetworkReply *reply, QFile *file);
void handleFinished(QNetworkReply *reply, QFile *file);
void onDownloadProgress(QString source, qint64 a, qint64 b);
void progressTimer();
signals:
void progress(int, QString);
void progressDescription(QString);
void setCount(int);
void addOne();
void finishedCheck(bool);
void needUpdate();
};
#endif // ENGINEUPDATER_H