-
Notifications
You must be signed in to change notification settings - Fork 250
/
utils.h
191 lines (159 loc) · 6.75 KB
/
utils.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
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright (c) 2019-2024 hors<[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#ifndef UTILS_H
#define UTILS_H
#include <QDir>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QSettings>
#include "global.h"
#include "xzip.h"
class Utils : public QObject {
Q_OBJECT
public:
enum ACTION {
ACTION_UNKNOWN = 0,
ACTION_COPYFILE,
ACTION_REMOVEFILE,
ACTION_REMOVEDIRECTORYIFEMPTY,
ACTION_MAKEDIRECTORY,
ACTION_UNPACKDIRECTORY,
ACTION_UNPACKFILE
};
struct WEB_RECORD {
QString sName;
QString sFileName;
QString sLink;
};
struct STATUS {
bool bInstall;
bool bUpdate;
bool bRemove;
QString sServerListVersion;
QString sServerListDate;
QString sInstalledVersion;
QString sInstalledDate;
WEB_RECORD webRecord;
};
struct STATS {
QString sModule;
qint64 nTotalModule;
qint64 nCurrentModule;
QString sFile;
qint64 nTotalFile;
qint64 nCurrentFile;
qint64 nTotalBytes;
qint64 nCurrentBytes;
};
struct RECORD {
QString sFullPath;
QString sPath;
bool bIsFile;
};
struct HANDLE_RECORD {
QString sSrc;
QString sPath;
QString sSHA1;
QString sPattern;
ACTION action;
};
struct MDATA {
QString sName;
QString sVersion;
bool bIs32;
bool bIs64;
QString sDate;
QString sAuthor;
QString sBugreport;
QString sInfo;
QString sRoot;
QString sBundleFileName;
QList<Utils::HANDLE_RECORD> listInstallRecords;
QList<Utils::HANDLE_RECORD> listRemoveRecords;
QList<Utils::HANDLE_RECORD> listConvertRecords;
qint64 nSize;
qint64 nCompressedSize;
QString sSrc;
QString sSHA1;
QString sGithub;
QList<QString> listDownloads;
QString sUpdated;
};
struct FILE_RECORD {
QString sFullPath;
QString sPath;
QString sSHA1;
// qint64 nSize;
// qint64 nCompressedSize;
};
struct DIRECTORY_RECORD {
QString sFullPath;
QString sPath;
};
struct MODULES_DATA {
QList<Utils::MDATA> listServerList;
QList<Utils::MDATA> listInstalled;
QMap<QString, STATUS> mapStatus;
QList<WEB_RECORD> listUpdates;
};
explicit Utils(QObject *pParent = nullptr);
static QList<RECORD> getRecords(QString sRootPath);
static bool checkMData(MDATA *pMData, QString *psErrorString);
static QString createBundleName(MDATA *pMData);
static bool isPluginValid(QString sFileName, XBinary::PDSTRUCT *pPdStruct);
static bool isPluginValid(QIODevice *pDevice, XBinary::PDSTRUCT *pPdStruct);
static QByteArray createPluginInfo(Utils::MDATA *pMData, QList<Utils::FILE_RECORD> *pListFileRecords, QList<Utils::DIRECTORY_RECORD> *pListDirectoryRecords);
static MDATA getMDataFromZip(QString sFileName, QString sRootPath, XBinary::PDSTRUCT *pPdStruct);
static MDATA getMDataFromZip(QIODevice *pDevice, QString sRootPath, XBinary::PDSTRUCT *pPdStruct);
static MDATA getMDataFromData(QByteArray baData);
static MDATA getMDataFromJSONFile(QString sFileName);
static QList<MDATA> getInstalledModules(QString sDataPath, QString sRootPath);
static QList<MDATA> getModulesFromJSONFile(QString sFileName);
static QDate getDateFromJSONFile(QString sFileName);
static bool createServerList(QString sListFileName, QList<QString> *pList, QString sWebPrefix, QString sDate);
static void mDataToObject(Utils::MDATA *pMData, QJsonObject *pObject);
static void objectToMData(QJsonObject *pObject, Utils::MDATA *pMData);
static void handleRecordToObject(Utils::HANDLE_RECORD *pHandleRecord, QJsonObject *pObject);
static void objectToHandleRecord(QJsonObject *pObject, Utils::HANDLE_RECORD *pHandleRecord);
static QMap<QString, STATUS> getModulesStatusMap(QString sDataPath, QList<MDATA> *pServerList, QList<MDATA> *pInstalled);
static MODULES_DATA getModulesData(QString sDataPath);
static QList<Utils::WEB_RECORD> getUpdates(QMap<QString, STATUS> *pMapStatus);
static QString getInstalledJsonFileName(QString sDataPath, QString sName);
static QString getServerListFileName(QString sDataPath);
static QString getServerLastestListFileName(QString sDataPath);
static QString getModuleFileName(QString sDataPath, QString sName);
static QString getConvertPath(QString sDataPath, QString sName);
static QString getConvertDownloadFileName(QString sDataPath, QString sName, QString sPattern);
static QString getConvertModulePath(QString sDataPath, QString sName);
static Utils::MDATA getMDataByName(QList<MDATA> *pServerList, QString sName);
static QList<QString> getNamesFromWebRecords(QList<WEB_RECORD> *pListWebRecords);
static Utils::WEB_RECORD getWebRecordByName(QList<WEB_RECORD> *pListWebRecords, QString sName);
static bool isGithubPresent(QString sServerListFileName);
static bool updateJsonFile(QString sFileName, QList<MDATA> listMData);
static bool updateServerList(QString sOldFileName, QString sNewFileName);
static QString actionIdToString(ACTION action);
static ACTION stringToActionId(QString sAction);
static bool checkPattern(QString sString, Utils::MDATA *pMData);
private:
static void _getRecords(QString sRootPath, QString sCurrentPath, QList<RECORD> *pListRecords);
};
#endif // UTILS_H