mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-01 21:42:31 +01:00
Add a whitelist and blacklist for cloud saves
This commit is contained in:
parent
5db36f6b7f
commit
4ff846e5cd
@ -296,6 +296,10 @@ class Config
|
||||
Blacklist blacklist;
|
||||
Blacklist ignorelist;
|
||||
Blacklist gamehasdlc;
|
||||
|
||||
std::vector<std::string> cloudWhiteList;
|
||||
std::vector<std::string> cloudBlackList;
|
||||
|
||||
std::string sGameHasDLCList;
|
||||
|
||||
// Integers
|
||||
|
@ -101,10 +101,12 @@ class Downloader
|
||||
void clearUpdateNotifications();
|
||||
void repair();
|
||||
void download();
|
||||
|
||||
void downloadCloudSaves(const std::string& product_id, int build_index = -1);
|
||||
void downloadCloudSavesById(const std::string& product_id, int build_index = -1);
|
||||
void uploadCloudSaves(const std::string& product_id, int build_index = -1);
|
||||
void uploadCloudSavesById(const std::string& product_id, int build_index = -1);
|
||||
|
||||
void checkOrphans();
|
||||
void checkStatus();
|
||||
void updateCache();
|
||||
|
5
main.cpp
5
main.cpp
@ -229,6 +229,10 @@ int main(int argc, char *argv[])
|
||||
("cacert", bpo::value<std::string>(&Globals::globalConfig.curlConf.sCACertPath)->default_value(""), "Path to CA certificate bundle in PEM format")
|
||||
("respect-umask", bpo::value<bool>(&Globals::globalConfig.bRespectUmask)->zero_tokens()->default_value(false), "Do not adjust permissions of sensitive files")
|
||||
("user-agent", bpo::value<std::string>(&Globals::globalConfig.curlConf.sUserAgent)->default_value(DEFAULT_USER_AGENT), "Set user agent")
|
||||
|
||||
("wine-prefix", bpo::value<std::string>(&Globals::globalConfig.dirConf.sWinePrefix)->default_value("."), "Set wineprefix directory")
|
||||
("cloud-whitelist", bpo::value<std::vector<std::string>>(&Globals::globalConfig.cloudWhiteList)->multitoken(), "Include this list of cloud saves, by default all cloud saves are included\n Example: --cloud-whitelist saves/AutoSave-0 saves/AutoSave-1/screenshot.png")
|
||||
("cloud-blacklist", bpo::value<std::vector<std::string>>(&Globals::globalConfig.cloudBlackList)->multitoken(), "Exclude this list of cloud saves\n Example: --cloud-blacklist saves/AutoSave-0 saves/AutoSave-1/screenshot.png")
|
||||
#ifdef USE_QT_GUI_LOGIN
|
||||
("enable-login-gui", bpo::value<bool>(&Globals::globalConfig.bEnableLoginGUI)->zero_tokens()->default_value(false), "Enable login GUI when encountering reCAPTCHA on login form")
|
||||
#endif
|
||||
@ -238,7 +242,6 @@ int main(int argc, char *argv[])
|
||||
// Commandline options (config file)
|
||||
options_cli_cfg.add_options()
|
||||
("directory", bpo::value<std::string>(&Globals::globalConfig.dirConf.sDirectory)->default_value("."), "Set download directory")
|
||||
("wine-prefix", bpo::value<std::string>(&Globals::globalConfig.dirConf.sWinePrefix)->default_value("."), "Set wineprefix directory")
|
||||
("limit-rate", bpo::value<curl_off_t>(&Globals::globalConfig.curlConf.iDownloadRate)->default_value(0), "Limit download rate to value in kB\n0 = unlimited")
|
||||
("xml-directory", bpo::value<std::string>(&Globals::globalConfig.sXMLDirectory), "Set directory for GOG XML files")
|
||||
("chunk-size", bpo::value<size_t>(&Globals::globalConfig.iChunkSize)->default_value(10), "Chunk size (in MB) when creating XML")
|
||||
|
@ -83,6 +83,31 @@ void dirForEach(const std::string &location, std::function<void(boost::filesyste
|
||||
dirForEachHelper(location, f);
|
||||
}
|
||||
|
||||
bool whitelisted(const std::string &path) {
|
||||
auto &whitelist = Globals::globalConfig.cloudWhiteList;
|
||||
auto &blacklist = Globals::globalConfig.cloudBlackList;
|
||||
|
||||
// Check if path is whitelisted
|
||||
if(!whitelist.empty()) {
|
||||
return std::any_of(std::begin(whitelist), std::end(whitelist), [&path](const std::string &whitelisted) {
|
||||
return
|
||||
path.rfind(whitelisted, 0) == 0 &&
|
||||
(path.size() == whitelisted.size() || path[whitelisted.size()] == '/');
|
||||
});
|
||||
}
|
||||
|
||||
// Check if blacklisted
|
||||
if(!blacklist.empty()) {
|
||||
return !std::any_of(std::begin(blacklist), std::end(blacklist), [&path](const std::string &blacklisted) {
|
||||
return
|
||||
path.rfind(blacklisted, 0) == 0 &&
|
||||
(path.size() == blacklisted.size() || path[blacklisted.size()] == '/');
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Downloader::Downloader()
|
||||
{
|
||||
if (Globals::globalConfig.bLogin)
|
||||
@ -4684,6 +4709,11 @@ int Downloader::cloudSaveListByIdForEach(const std::string& product_id, int buil
|
||||
|
||||
for(auto &fileJson : fileList) {
|
||||
auto path = fileJson["name"].asString();
|
||||
|
||||
if(!whitelisted(path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto pos = path.find_first_of('/');
|
||||
|
||||
auto location = name_to_location[path.substr(0, pos)] + path.substr(pos);
|
||||
@ -4734,11 +4764,16 @@ void Downloader::uploadCloudSavesById(const std::string& product_id, int build_i
|
||||
return;
|
||||
}
|
||||
|
||||
auto remote_path = (name / boost::filesystem::relative(*file, location)).string();
|
||||
if(!whitelisted(remote_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cloudSaveFile csf {
|
||||
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
||||
boost::filesystem::file_size(*file),
|
||||
(name / boost::filesystem::relative(*file, location)).string(),
|
||||
std::move(remote_path),
|
||||
file->path().string()
|
||||
};
|
||||
|
||||
@ -4904,10 +4939,16 @@ void Downloader::galaxyShowLocalCloudSavesById(const std::string& product_id, in
|
||||
}
|
||||
|
||||
dirForEach(location, [&](boost::filesystem::directory_iterator file) {
|
||||
auto path = (name / boost::filesystem::relative(*file, location)).string();
|
||||
|
||||
if(!whitelisted(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cloudSaveFile csf {
|
||||
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
||||
boost::filesystem::file_size(*file),
|
||||
(name / boost::filesystem::relative(*file, location)).string(),
|
||||
std::move(path),
|
||||
file->path().string()
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user