mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52: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 blacklist;
|
||||||
Blacklist ignorelist;
|
Blacklist ignorelist;
|
||||||
Blacklist gamehasdlc;
|
Blacklist gamehasdlc;
|
||||||
|
|
||||||
|
std::vector<std::string> cloudWhiteList;
|
||||||
|
std::vector<std::string> cloudBlackList;
|
||||||
|
|
||||||
std::string sGameHasDLCList;
|
std::string sGameHasDLCList;
|
||||||
|
|
||||||
// Integers
|
// Integers
|
||||||
|
@ -101,10 +101,12 @@ class Downloader
|
|||||||
void clearUpdateNotifications();
|
void clearUpdateNotifications();
|
||||||
void repair();
|
void repair();
|
||||||
void download();
|
void download();
|
||||||
|
|
||||||
void downloadCloudSaves(const std::string& product_id, int build_index = -1);
|
void downloadCloudSaves(const std::string& product_id, int build_index = -1);
|
||||||
void downloadCloudSavesById(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 uploadCloudSaves(const std::string& product_id, int build_index = -1);
|
||||||
void uploadCloudSavesById(const std::string& product_id, int build_index = -1);
|
void uploadCloudSavesById(const std::string& product_id, int build_index = -1);
|
||||||
|
|
||||||
void checkOrphans();
|
void checkOrphans();
|
||||||
void checkStatus();
|
void checkStatus();
|
||||||
void updateCache();
|
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")
|
("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")
|
("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")
|
("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
|
#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")
|
("enable-login-gui", bpo::value<bool>(&Globals::globalConfig.bEnableLoginGUI)->zero_tokens()->default_value(false), "Enable login GUI when encountering reCAPTCHA on login form")
|
||||||
#endif
|
#endif
|
||||||
@ -238,7 +242,6 @@ int main(int argc, char *argv[])
|
|||||||
// Commandline options (config file)
|
// Commandline options (config file)
|
||||||
options_cli_cfg.add_options()
|
options_cli_cfg.add_options()
|
||||||
("directory", bpo::value<std::string>(&Globals::globalConfig.dirConf.sDirectory)->default_value("."), "Set download directory")
|
("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")
|
("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")
|
("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")
|
("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);
|
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()
|
Downloader::Downloader()
|
||||||
{
|
{
|
||||||
if (Globals::globalConfig.bLogin)
|
if (Globals::globalConfig.bLogin)
|
||||||
@ -4684,6 +4709,11 @@ int Downloader::cloudSaveListByIdForEach(const std::string& product_id, int buil
|
|||||||
|
|
||||||
for(auto &fileJson : fileList) {
|
for(auto &fileJson : fileList) {
|
||||||
auto path = fileJson["name"].asString();
|
auto path = fileJson["name"].asString();
|
||||||
|
|
||||||
|
if(!whitelisted(path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto pos = path.find_first_of('/');
|
auto pos = path.find_first_of('/');
|
||||||
|
|
||||||
auto location = name_to_location[path.substr(0, pos)] + path.substr(pos);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto remote_path = (name / boost::filesystem::relative(*file, location)).string();
|
||||||
|
if(!whitelisted(remote_path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cloudSaveFile csf {
|
cloudSaveFile csf {
|
||||||
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
||||||
boost::filesystem::file_size(*file),
|
boost::filesystem::file_size(*file),
|
||||||
(name / boost::filesystem::relative(*file, location)).string(),
|
std::move(remote_path),
|
||||||
file->path().string()
|
file->path().string()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -4904,10 +4939,16 @@ void Downloader::galaxyShowLocalCloudSavesById(const std::string& product_id, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirForEach(location, [&](boost::filesystem::directory_iterator file) {
|
dirForEach(location, [&](boost::filesystem::directory_iterator file) {
|
||||||
|
auto path = (name / boost::filesystem::relative(*file, location)).string();
|
||||||
|
|
||||||
|
if(!whitelisted(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cloudSaveFile csf {
|
cloudSaveFile csf {
|
||||||
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
boost::posix_time::from_time_t(boost::filesystem::last_write_time(*file) - 1),
|
||||||
boost::filesystem::file_size(*file),
|
boost::filesystem::file_size(*file),
|
||||||
(name / boost::filesystem::relative(*file, location)).string(),
|
std::move(path),
|
||||||
file->path().string()
|
file->path().string()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user