/
config.h
292 lines (248 loc) · 7.54 KB
/
config.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
#ifndef CONFIG_H__
#define CONFIG_H__
#include <iostream>
#include <curl/curl.h>
#include <json/json.h>
#include <mutex>
#include <ctime>
#include "blacklist.h"
struct DirectoryConfig
{
bool bSubDirectories;
std::string sDirectory;
std::string sGameSubdir;
std::string sInstallersSubdir;
std::string sExtrasSubdir;
std::string sPatchesSubdir;
std::string sLanguagePackSubdir;
std::string sDLCSubdir;
};
struct DownloadConfig
{
unsigned int iInstallerPlatform;
unsigned int iInstallerLanguage;
std::vector<unsigned int> vPlatformPriority;
std::vector<unsigned int> vLanguagePriority;
unsigned int iInclude;
unsigned int iGalaxyPlatform;
unsigned int iGalaxyLanguage;
unsigned int iGalaxyArch;
bool bRemoteXML;
bool bSaveChangelogs;
bool bSaveSerials;
bool bAutomaticXMLCreation;
bool bInstallers;
bool bExtras;
bool bPatches;
bool bLanguagePacks;
bool bDLC;
bool bIgnoreDLCCount;
bool bDuplicateHandler;
bool bGalaxyDependencies;
};
struct gameSpecificConfig
{
DownloadConfig dlConf;
DirectoryConfig dirConf;
};
class GalaxyConfig
{
public:
bool isExpired()
{
std::unique_lock<std::mutex> lock(m);
bool bExpired = true; // assume that token is expired
intmax_t time_now = time(NULL);
if (this->token_json.isMember("expires_at"))
bExpired = (time_now > this->token_json["expires_at"].asLargestInt());
return bExpired;
}
std::string getAccessToken()
{
std:: string access_token;
std::unique_lock<std::mutex> lock(m);
if (this->token_json.isMember("access_token"))
access_token = this->token_json["access_token"].asString();
return access_token;
}
std::string getRefreshToken()
{
std::string refresh_token;
std::unique_lock<std::mutex> lock(m);
if (this->token_json.isMember("refresh_token"))
refresh_token = this->token_json["refresh_token"].asString();
return refresh_token;
}
Json::Value getJSON()
{
std::unique_lock<std::mutex> lock(m);
return this->token_json;
}
void setJSON(Json::Value json)
{
std::unique_lock<std::mutex> lock(m);
if (!json.isMember("expires_at"))
{
intmax_t time_now = time(NULL);
Json::Value::LargestInt expires_in = 3600;
if (json.isMember("expires_in"))
if (!json["expires_in"].isNull())
expires_in = json["expires_in"].asLargestInt();
Json::Value::LargestInt expires_at = time_now + expires_in;
json["expires_at"] = expires_at;
}
this->token_json = json;
}
void setFilepath(const std::string& path)
{
std::unique_lock<std::mutex> lock(m);
this->filepath = path;
}
std::string getFilepath()
{
std::unique_lock<std::mutex> lock(m);
return this->filepath;
}
std::string getClientId()
{
std::unique_lock<std::mutex> lock(m);
return this->client_id;
}
std::string getClientSecret()
{
std::unique_lock<std::mutex> lock(m);
return this->client_secret;
}
std::string getRedirectUri()
{
std::unique_lock<std::mutex> lock(m);
return this->redirect_uri;
}
GalaxyConfig() = default;
GalaxyConfig(const GalaxyConfig& other)
{
std::lock_guard<std::mutex> guard(other.m);
client_id = other.client_id;
client_secret = other.client_secret;
redirect_uri = other.redirect_uri;
filepath = other.filepath;
token_json = other.token_json;
}
GalaxyConfig& operator= (GalaxyConfig& other)
{
if(&other == this)
return *this;
std::unique_lock<std::mutex> lock1(m, std::defer_lock);
std::unique_lock<std::mutex> lock2(other.m, std::defer_lock);
std::lock(lock1, lock2);
client_id = other.client_id;
client_secret = other.client_secret;
redirect_uri = other.redirect_uri;
filepath = other.filepath;
token_json = other.token_json;
return *this;
}
protected:
private:
std::string client_id = "46899977096215655";
std::string client_secret = "9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9";
std::string redirect_uri = "https://embed.gog.com/on_login_success?origin=client";
std::string filepath;
Json::Value token_json;
mutable std::mutex m;
};
struct CurlConfig
{
bool bVerifyPeer;
bool bVerbose;
std::string sCACertPath;
std::string sCookiePath;
std::string sUserAgent;
long int iTimeout;
curl_off_t iDownloadRate;
long int iLowSpeedTimeout;
long int iLowSpeedTimeoutRate;
};
struct GogAPIConfig
{
std::string sToken;
std::string sSecret;
};
class Config
{
public:
Config() {};
virtual ~Config() {};
// Booleans
bool bLoginHTTP;
bool bLoginAPI;
bool bSaveConfig;
bool bResetConfig;
bool bDownload;
bool bRepair;
bool bUpdated;
bool bList;
bool bListDetails;
bool bCheckStatus;
bool bShowWishlist;
bool bNotifications;
bool bVerbose;
bool bUnicode; // use Unicode in console output
bool bColor; // use colors
bool bReport;
bool bRespectUmask;
bool bPlatformDetection;
// Cache
bool bUseCache;
bool bUpdateCache;
int iCacheValid;
// Download with file id options
std::string sFileIdString;
std::string sOutputFilename;
// Curl
CurlConfig curlConf;
// Download
DownloadConfig dlConf;
// Directories
DirectoryConfig dirConf;
std::string sCacheDirectory;
std::string sXMLDirectory;
std::string sConfigDirectory;
// File paths
std::string sConfigFilePath;
std::string sBlacklistFilePath;
std::string sIgnorelistFilePath;
std::string sGameHasDLCListFilePath;
std::string sReportFilePath;
std::string sXMLFile;
// Regex
std::string sGameRegex;
std::string sOrphanRegex;
std::string sIgnoreDLCCountRegex;
// Priorities
std::string sPlatformPriority;
std::string sLanguagePriority;
// General strings
std::string sVersionString;
std::string sVersionNumber;
std::string sEmail;
std::string sPassword;
GogAPIConfig apiConf;
// Lists
Blacklist blacklist;
Blacklist ignorelist;
Blacklist gamehasdlc;
std::string sGameHasDLCList;
// Integers
int iRetries;
unsigned int iThreads;
int iWait;
size_t iChunkSize;
int iProgressInterval;
};
#endif // CONFIG_H__