2013-03-15 21:46:16 +01:00
|
|
|
/* 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
|
2013-03-24 22:56:57 +01:00
|
|
|
* http://www.wtfpl.net/ for more details. */
|
2013-03-15 21:46:16 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_H__
|
|
|
|
#define CONFIG_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <curl/curl.h>
|
2017-02-17 10:14:28 +01:00
|
|
|
#include <json/json.h>
|
|
|
|
#include <mutex>
|
|
|
|
#include <ctime>
|
2013-03-15 21:46:16 +01:00
|
|
|
|
2014-06-20 17:30:40 +02:00
|
|
|
#include "blacklist.h"
|
|
|
|
|
2017-02-17 10:14:28 +01:00
|
|
|
struct DirectoryConfig
|
|
|
|
{
|
|
|
|
bool bSubDirectories;
|
|
|
|
std::string sDirectory;
|
2022-07-31 14:11:32 +02:00
|
|
|
std::string sWinePrefix;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::string sGameSubdir;
|
|
|
|
std::string sInstallersSubdir;
|
|
|
|
std::string sExtrasSubdir;
|
|
|
|
std::string sPatchesSubdir;
|
|
|
|
std::string sLanguagePackSubdir;
|
|
|
|
std::string sDLCSubdir;
|
2018-09-12 14:18:54 +02:00
|
|
|
std::string sGalaxyInstallSubdir;
|
2017-02-17 10:14:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DownloadConfig
|
|
|
|
{
|
|
|
|
unsigned int iInstallerPlatform;
|
|
|
|
unsigned int iInstallerLanguage;
|
2018-09-12 19:07:59 +02:00
|
|
|
unsigned int iGalaxyCDN;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::vector<unsigned int> vPlatformPriority;
|
|
|
|
std::vector<unsigned int> vLanguagePriority;
|
2018-09-12 19:07:59 +02:00
|
|
|
std::vector<unsigned int> vGalaxyCDNPriority;
|
2021-11-09 13:59:42 +01:00
|
|
|
std::vector<std::string> vTags;
|
2017-02-17 10:14:28 +01:00
|
|
|
unsigned int iInclude;
|
2017-03-05 21:47:44 +01:00
|
|
|
unsigned int iGalaxyPlatform;
|
2017-03-06 06:22:34 +01:00
|
|
|
unsigned int iGalaxyLanguage;
|
2017-05-23 15:44:27 +02:00
|
|
|
unsigned int iGalaxyArch;
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
bool bRemoteXML;
|
|
|
|
bool bSaveChangelogs;
|
|
|
|
bool bSaveSerials;
|
|
|
|
bool bAutomaticXMLCreation;
|
|
|
|
|
|
|
|
bool bInstallers;
|
|
|
|
bool bExtras;
|
|
|
|
bool bPatches;
|
|
|
|
bool bLanguagePacks;
|
|
|
|
bool bDLC;
|
|
|
|
|
|
|
|
bool bIgnoreDLCCount;
|
|
|
|
bool bDuplicateHandler;
|
2018-09-05 16:41:43 +02:00
|
|
|
bool bGalaxyDependencies;
|
2019-06-06 19:00:38 +02:00
|
|
|
bool bGalaxyDeleteOrphans;
|
2017-02-17 10:14:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gameSpecificConfig
|
|
|
|
{
|
|
|
|
DownloadConfig dlConf;
|
|
|
|
DirectoryConfig dirConf;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GalaxyConfig
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool isExpired()
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(m);
|
2017-09-20 05:59:43 +02:00
|
|
|
bool bExpired = true; // assume that token is expired
|
2017-02-27 21:24:56 +01:00
|
|
|
intmax_t time_now = time(NULL);
|
2017-02-17 10:14:28 +01:00
|
|
|
if (this->token_json.isMember("expires_at"))
|
2017-02-27 21:24:56 +01:00
|
|
|
bExpired = (time_now > this->token_json["expires_at"].asLargestInt());
|
2017-02-17 10:14:28 +01:00
|
|
|
return bExpired;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getAccessToken()
|
|
|
|
{
|
2017-09-15 01:17:44 +02:00
|
|
|
std:: string access_token;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m);
|
2017-09-15 01:17:44 +02:00
|
|
|
if (this->token_json.isMember("access_token"))
|
|
|
|
access_token = this->token_json["access_token"].asString();
|
|
|
|
return access_token;
|
2017-02-17 10:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getRefreshToken()
|
|
|
|
{
|
2017-09-15 01:17:44 +02:00
|
|
|
std::string refresh_token;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m);
|
2017-09-15 01:17:44 +02:00
|
|
|
if (this->token_json.isMember("refresh_token"))
|
|
|
|
refresh_token = this->token_json["refresh_token"].asString();
|
|
|
|
return refresh_token;
|
2017-02-17 10:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value getJSON()
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(m);
|
|
|
|
return this->token_json;
|
|
|
|
}
|
|
|
|
|
2022-08-02 18:36:31 +02:00
|
|
|
std::string getUserId() {
|
|
|
|
std::unique_lock<std::mutex> lock(m);
|
|
|
|
|
|
|
|
if(this->token_json.isMember("user_id")) {
|
|
|
|
return this->token_json["user_id"].asString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:14:28 +01:00
|
|
|
void setJSON(Json::Value json)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(m);
|
|
|
|
if (!json.isMember("expires_at"))
|
2017-02-27 21:24:56 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2017-02-17 10:14:28 +01:00
|
|
|
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);
|
2022-08-02 18:36:31 +02:00
|
|
|
if(token_json.isMember("client_id")) {
|
|
|
|
return token_json["client_id"].asString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return default_client_id;
|
2017-02-17 10:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getClientSecret()
|
|
|
|
{
|
2022-08-02 18:36:31 +02:00
|
|
|
if(token_json.isMember("client_secret")) {
|
|
|
|
return token_json["client_secret"].asString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return default_client_secret;
|
2017-02-17 10:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
redirect_uri = other.redirect_uri;
|
|
|
|
filepath = other.filepath;
|
|
|
|
token_json = other.token_json;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
private:
|
2022-08-02 18:36:31 +02:00
|
|
|
const std::string default_client_id = "46899977096215655";
|
|
|
|
const std::string default_client_secret = "9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9";
|
|
|
|
|
2017-02-17 10:14:28 +01:00
|
|
|
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;
|
2017-08-01 22:59:11 +02:00
|
|
|
std::string sUserAgent;
|
2017-02-17 10:14:28 +01:00
|
|
|
long int iTimeout;
|
|
|
|
curl_off_t iDownloadRate;
|
2017-11-08 14:20:03 +01:00
|
|
|
long int iLowSpeedTimeout;
|
|
|
|
long int iLowSpeedTimeoutRate;
|
2017-02-17 10:14:28 +01:00
|
|
|
};
|
|
|
|
|
2013-03-15 21:46:16 +01:00
|
|
|
class Config
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Config() {};
|
|
|
|
virtual ~Config() {};
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
// Booleans
|
2019-11-14 17:25:12 +01:00
|
|
|
bool bLogin;
|
2017-02-17 10:14:28 +01:00
|
|
|
bool bSaveConfig;
|
|
|
|
bool bResetConfig;
|
|
|
|
|
|
|
|
bool bDownload;
|
2013-03-15 21:46:16 +01:00
|
|
|
bool bRepair;
|
2018-07-21 22:59:08 +02:00
|
|
|
bool bUpdated;
|
2017-02-17 10:14:28 +01:00
|
|
|
bool bList;
|
|
|
|
bool bListDetails;
|
|
|
|
bool bCheckStatus;
|
|
|
|
bool bShowWishlist;
|
2018-07-21 22:59:08 +02:00
|
|
|
bool bNotifications;
|
2018-12-20 12:10:27 +01:00
|
|
|
bool bIncludeHiddenProducts;
|
2021-09-12 09:25:37 +02:00
|
|
|
bool bSizeOnly;
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
bool bVerbose;
|
2013-11-14 14:40:59 +01:00
|
|
|
bool bUnicode; // use Unicode in console output
|
|
|
|
bool bColor; // use colors
|
2014-02-13 09:05:16 +01:00
|
|
|
bool bReport;
|
2017-02-17 10:14:28 +01:00
|
|
|
bool bRespectUmask;
|
|
|
|
bool bPlatformDetection;
|
2019-03-01 22:12:04 +01:00
|
|
|
#ifdef USE_QT_GUI_LOGIN
|
2019-04-22 17:01:19 +02:00
|
|
|
bool bEnableLoginGUI;
|
2019-03-01 22:12:04 +01:00
|
|
|
#endif
|
2021-11-09 13:59:42 +01:00
|
|
|
bool bListTags;
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
// Cache
|
2014-10-16 10:05:57 +02:00
|
|
|
bool bUseCache;
|
|
|
|
bool bUpdateCache;
|
2017-02-17 10:14:28 +01:00
|
|
|
int iCacheValid;
|
|
|
|
|
|
|
|
// Download with file id options
|
|
|
|
std::string sFileIdString;
|
|
|
|
std::string sOutputFilename;
|
|
|
|
|
|
|
|
// Curl
|
|
|
|
CurlConfig curlConf;
|
|
|
|
|
|
|
|
// Download
|
|
|
|
DownloadConfig dlConf;
|
|
|
|
|
|
|
|
// Directories
|
|
|
|
DirectoryConfig dirConf;
|
2014-10-16 10:05:57 +02:00
|
|
|
std::string sCacheDirectory;
|
2013-03-15 21:46:16 +01:00
|
|
|
std::string sXMLDirectory;
|
2013-12-11 10:27:53 +01:00
|
|
|
std::string sConfigDirectory;
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
// File paths
|
2013-03-15 21:46:16 +01:00
|
|
|
std::string sConfigFilePath;
|
2014-06-20 17:30:40 +02:00
|
|
|
std::string sBlacklistFilePath;
|
2016-02-20 21:59:52 +01:00
|
|
|
std::string sIgnorelistFilePath;
|
2016-11-05 13:51:52 +01:00
|
|
|
std::string sGameHasDLCListFilePath;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::string sReportFilePath;
|
|
|
|
|
|
|
|
std::string sXMLFile;
|
|
|
|
|
|
|
|
// Regex
|
|
|
|
std::string sGameRegex;
|
2013-12-22 12:02:48 +01:00
|
|
|
std::string sOrphanRegex;
|
2017-02-17 10:14:28 +01:00
|
|
|
std::string sIgnoreDLCCountRegex;
|
|
|
|
|
|
|
|
// Priorities
|
|
|
|
std::string sPlatformPriority;
|
|
|
|
std::string sLanguagePriority;
|
|
|
|
|
|
|
|
// General strings
|
|
|
|
std::string sVersionString;
|
|
|
|
std::string sVersionNumber;
|
2017-03-06 04:46:48 +01:00
|
|
|
std::string sEmail;
|
|
|
|
std::string sPassword;
|
2017-02-17 10:14:28 +01:00
|
|
|
|
|
|
|
// Lists
|
|
|
|
Blacklist blacklist;
|
|
|
|
Blacklist ignorelist;
|
|
|
|
Blacklist gamehasdlc;
|
2016-11-05 13:51:52 +01:00
|
|
|
std::string sGameHasDLCList;
|
2014-10-25 17:57:04 +02:00
|
|
|
|
2017-02-17 10:14:28 +01:00
|
|
|
// Integers
|
2014-02-26 13:59:23 +01:00
|
|
|
int iRetries;
|
2017-02-17 10:14:28 +01:00
|
|
|
unsigned int iThreads;
|
2020-02-17 18:33:15 +01:00
|
|
|
unsigned int iInfoThreads;
|
2014-06-10 11:16:49 +02:00
|
|
|
int iWait;
|
2013-03-15 21:46:16 +01:00
|
|
|
size_t iChunkSize;
|
2017-08-18 08:33:10 +02:00
|
|
|
int iProgressInterval;
|
2013-03-15 21:46:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONFIG_H__
|