use std::optional to fix soundness hole

This commit is contained in:
Abhi Agarwal 2024-04-01 20:52:18 -04:00
parent a314f2d635
commit 9319075245
No known key found for this signature in database
GPG Key ID: 98BCB70B1890F9CE
8 changed files with 112 additions and 137 deletions

View File

@ -149,11 +149,7 @@ if(USE_QT_GUI)
) )
endif(USE_QT_GUI) endif(USE_QT_GUI)
if(Qt6_FOUND)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
endif(Qt6_FOUND)
if(MSVC) if(MSVC)
# Force to always compile with W4 # Force to always compile with W4

View File

@ -12,6 +12,7 @@
#include <json/json.h> #include <json/json.h>
#include <mutex> #include <mutex>
#include <ctime> #include <ctime>
#include <optional>
#include "filelist.h" #include "filelist.h"
@ -305,10 +306,10 @@ class Config
std::string sPassword; std::string sPassword;
// Lists // Lists
Filelist blacklist; std::optional<Filelist> blacklist;
Filelist ignorelist; std::optional<Filelist> ignorelist;
Filelist gamehasdlc; std::optional<Filelist> gamehasdlc;
Filelist whitelist; std::optional<Filelist> whitelist;
// Cloud save options // Cloud save options
std::vector<std::string> cloudWhiteList; std::vector<std::string> cloudWhiteList;

View File

@ -155,9 +155,9 @@ class Downloader
static std::string getChangelogFromJSON(const Json::Value& json); static std::string getChangelogFromJSON(const Json::Value& json);
void saveJsonFile(const std::string& json, const std::string& filepath); void saveJsonFile(const std::string& json, const std::string& filepath);
void saveChangelog(const std::string& changelog, const std::string& filepath); void saveChangelog(const std::string& changelog, const std::string& filepath);
static void processDownloadQueue(Config conf, const unsigned int& tid); static void processDownloadQueue(const Config& conf, const unsigned int& tid);
static void processCloudSaveDownloadQueue(Config conf, const unsigned int& tid); static void processCloudSaveDownloadQueue(const Config& conf, const unsigned int& tid);
static void processCloudSaveUploadQueue(Config conf, const unsigned int& tid); static void processCloudSaveUploadQueue(const Config& conf, const unsigned int& tid);
static int progressCallbackForThread(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); static int progressCallbackForThread(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
template <typename T> void printProgress(const ThreadSafeQueue<T>& download_queue); template <typename T> void printProgress(const ThreadSafeQueue<T>& download_queue);
static void getGameDetailsThread(Config config, const unsigned int& tid); static void getGameDetailsThread(Config config, const unsigned int& tid);
@ -169,10 +169,10 @@ class Downloader
static size_t readData(void *ptr, size_t size, size_t nmemb, FILE *stream); static size_t readData(void *ptr, size_t size, size_t nmemb, FILE *stream);
std::vector<std::string> galaxyGetOrphanedFiles(const std::vector<galaxyDepotItem>& items, const std::string& install_path); std::vector<std::string> galaxyGetOrphanedFiles(const std::vector<galaxyDepotItem>& items, const std::string& install_path);
static void processGalaxyDownloadQueue(const std::string& install_path, Config conf, const unsigned int& tid); static void processGalaxyDownloadQueue(const std::string& install_path, const Config& conf, const unsigned int& tid);
void galaxyInstallGame_MojoSetupHack(const std::string& product_id); void galaxyInstallGame_MojoSetupHack(const std::string& product_id);
void galaxyInstallGame_MojoSetupHack_CombineSplitFiles(const splitFilesMap& mSplitFiles, const bool& bAppendtoFirst = false); void galaxyInstallGame_MojoSetupHack_CombineSplitFiles(const splitFilesMap& mSplitFiles, const bool& bAppendtoFirst = false);
static void processGalaxyDownloadQueue_MojoSetupHack(Config conf, const unsigned int& tid); static void processGalaxyDownloadQueue_MojoSetupHack(const Config& conf, const unsigned int& tid);
int mojoSetupGetFileVector(const gameFile& gf, std::vector<zipFileEntry>& vFiles); int mojoSetupGetFileVector(const gameFile& gf, std::vector<zipFileEntry>& vFiles);
std::string getGalaxyInstallDirectory(galaxyAPI *galaxyHandle, const Json::Value& manifest); std::string getGalaxyInstallDirectory(galaxyAPI *galaxyHandle, const Json::Value& manifest);
bool galaxySelectProductIdHelper(const std::string& product_id, std::string& selected_product); bool galaxySelectProductIdHelper(const std::string& product_id, std::string& selected_product);

View File

@ -25,14 +25,13 @@ class FilelistItem {
class Filelist class Filelist
{ {
public: public:
Filelist(){}; Filelist(const std::vector<std::string>& lines);
void initialize(const std::vector<std::string>& lines); bool Matches(const std::string& path) const;
bool Matches(const std::string& path); bool Matches(const std::string& path, const std::string& gamename, std::string subdirectory = "") const;
bool Matches(const std::string& path, const std::string& gamename, std::string subdirectory = "");
std::vector<FilelistItem>::size_type size() const { return files.size(); } std::vector<FilelistItem>::size_type size() const { return files.size(); }
bool empty() { return files.empty(); } bool empty() const { return files.empty(); }
private: private:
std::vector<FilelistItem> files; std::vector<FilelistItem> files;
}; };

View File

@ -11,6 +11,7 @@
#include "galaxyapi.h" #include "galaxyapi.h"
#include "globals.h" #include "globals.h"
#include <optional>
#include <fstream> #include <fstream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
@ -72,9 +73,9 @@ int main(int argc, char *argv[])
std::string priority_help_text = "Set priority by separating values with \",\"\nCombine values by separating with \"+\""; std::string priority_help_text = "Set priority by separating values with \",\"\nCombine values by separating with \"+\"";
// Create help text for --platform option // Create help text for --platform option
std::string platform_text = "Select which installers are downloaded\n"; std::string platform_text = "Select which installers are downloaded\n";
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i) for (const auto& platform : GlobalConstants::PLATFORMS)
{ {
platform_text += GlobalConstants::PLATFORMS[i].str + " = " + GlobalConstants::PLATFORMS[i].regexp + "\n"; platform_text += platform.str + " = " + platform.regexp + "\n";
} }
platform_text += "All = all"; platform_text += "All = all";
platform_text += "\n\n" + priority_help_text; platform_text += "\n\n" + priority_help_text;
@ -82,16 +83,16 @@ int main(int argc, char *argv[])
// Create help text for --galaxy-platform option // Create help text for --galaxy-platform option
std::string galaxy_platform_text = "Select platform\n"; std::string galaxy_platform_text = "Select platform\n";
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i) for (const auto& platform : GlobalConstants::PLATFORMS)
{ {
galaxy_platform_text += GlobalConstants::PLATFORMS[i].str + " = " + GlobalConstants::PLATFORMS[i].regexp + "\n"; galaxy_platform_text += platform.str + " = " + platform.regexp + "\n";
} }
// Create help text for --language option // Create help text for --language option
std::string language_text = "Select which language installers are downloaded\n"; std::string language_text = "Select which language installers are downloaded\n";
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i) for (const auto& language : GlobalConstants::LANGUAGES)
{ {
language_text += GlobalConstants::LANGUAGES[i].str + " = " + GlobalConstants::LANGUAGES[i].regexp + "\n"; language_text += language.str + " = " + language.regexp + "\n";
} }
language_text += "All = all"; language_text += "All = all";
language_text += "\n\n" + priority_help_text; language_text += "\n\n" + priority_help_text;
@ -99,16 +100,16 @@ int main(int argc, char *argv[])
// Create help text for --galaxy-language option // Create help text for --galaxy-language option
std::string galaxy_language_text = "Select language\n"; std::string galaxy_language_text = "Select language\n";
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i) for (const auto& language : GlobalConstants::LANGUAGES)
{ {
galaxy_language_text += GlobalConstants::LANGUAGES[i].str + " = " + GlobalConstants::LANGUAGES[i].regexp + "\n"; galaxy_language_text += language.str + " = " + language.regexp + "\n";
} }
// Create help text for --galaxy-arch option // Create help text for --galaxy-arch option
std::string galaxy_arch_text = "Select architecture\n"; std::string galaxy_arch_text = "Select architecture\n";
for (unsigned int i = 0; i < GlobalConstants::GALAXY_ARCHS.size(); ++i) for (const auto& arch : GlobalConstants::GALAXY_ARCHS)
{ {
galaxy_arch_text += GlobalConstants::GALAXY_ARCHS[i].str + " = " + GlobalConstants::GALAXY_ARCHS[i].regexp + "\n"; galaxy_arch_text += arch.str + " = " + arch.regexp + "\n";
} }
// Create help text for --subdir-galaxy-install option // Create help text for --subdir-galaxy-install option
@ -127,9 +128,9 @@ int main(int argc, char *argv[])
// Create help text for --galaxy-cdn-priority option // Create help text for --galaxy-cdn-priority option
std::string galaxy_cdn_priority_text = "Set priority for used CDNs\n"; std::string galaxy_cdn_priority_text = "Set priority for used CDNs\n";
for (unsigned int i = 0; i < GlobalConstants::GALAXY_CDNS.size(); ++i) for (const auto& cdn : GlobalConstants::GALAXY_CDNS)
{ {
galaxy_cdn_priority_text += GlobalConstants::GALAXY_CDNS[i].str + " = " + GlobalConstants::GALAXY_CDNS[i].regexp + "\n"; galaxy_cdn_priority_text += cdn.str + " = " + cdn.regexp + "\n";
} }
galaxy_cdn_priority_text += "\n" + priority_help_text; galaxy_cdn_priority_text += "\n" + priority_help_text;
@ -142,18 +143,18 @@ int main(int argc, char *argv[])
// Help text for include and exclude options // Help text for include and exclude options
std::string include_options_text; std::string include_options_text;
for (unsigned int i = 0; i < GlobalConstants::INCLUDE_OPTIONS.size(); ++i) for (const auto& include_option : GlobalConstants::INCLUDE_OPTIONS)
{ {
include_options_text += GlobalConstants::INCLUDE_OPTIONS[i].str + " = " + GlobalConstants::INCLUDE_OPTIONS[i].regexp + "\n"; include_options_text += include_option.str + " = " + include_option.regexp + "\n";
} }
include_options_text += "All = all\n"; include_options_text += "All = all\n";
include_options_text += "Separate with \",\" to use multiple values"; include_options_text += "Separate with \",\" to use multiple values";
// Create help text for --list-format option // Create help text for --list-format option
std::string list_format_text = "List games/tags\n"; std::string list_format_text = "List games/tags\n";
for (unsigned int i = 0; i < GlobalConstants::LIST_FORMAT.size(); ++i) for (const auto& list_format: GlobalConstants::LIST_FORMAT)
{ {
list_format_text += GlobalConstants::LIST_FORMAT[i].str + " = " + GlobalConstants::LIST_FORMAT[i].regexp + "\n"; list_format_text += list_format.str + " = " + list_format.regexp + "\n";
} }
std::string galaxy_product_id_install; std::string galaxy_product_id_install;
@ -413,7 +414,7 @@ int main(int argc, char *argv[])
std::getline(ifs, line); std::getline(ifs, line);
lines.push_back(std::move(line)); lines.push_back(std::move(line));
} }
Globals::globalConfig.blacklist.initialize(lines); Globals::globalConfig.blacklist = Filelist(lines);
} }
} }
@ -429,7 +430,7 @@ int main(int argc, char *argv[])
std::getline(ifs, line); std::getline(ifs, line);
lines.push_back(std::move(line)); lines.push_back(std::move(line));
} }
Globals::globalConfig.whitelist.initialize(lines); Globals::globalConfig.whitelist = Filelist(lines);
} }
} }
@ -450,7 +451,7 @@ int main(int argc, char *argv[])
std::getline(ifs, line); std::getline(ifs, line);
lines.push_back(std::move(line)); lines.push_back(std::move(line));
} }
Globals::globalConfig.ignorelist.initialize(lines); Globals::globalConfig.ignorelist = Filelist(lines);
} }
} }
@ -481,7 +482,7 @@ int main(int argc, char *argv[])
std::getline(ifs, line); std::getline(ifs, line);
lines.push_back(std::move(line)); lines.push_back(std::move(line));
} }
Globals::globalConfig.gamehasdlc.initialize(lines); Globals::globalConfig.gamehasdlc = Filelist(lines);
} }
} }
} }

View File

@ -109,6 +109,28 @@ bool whitelisted(const std::string &path) {
return true; return true;
} }
// checks if a given path matches either the whitelist or the blacklist.
bool shouldSkipFile(const std::string &path) {
const auto &whitelist = Globals::globalConfig.whitelist;
const auto &blacklist = Globals::globalConfig.blacklist;
if(whitelist.has_value()) {
if (!whitelist->Matches(path)) {
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "skipped non-whitelisted file: " << path << std::endl;
return true;
}
}
else if (blacklist.has_value()) {
if (blacklist->Matches(path)) {
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "skipped blacklisted file: " << path << std::endl;
return true;
}
}
return false;
}
Downloader::Downloader() Downloader::Downloader()
{ {
if (Globals::globalConfig.bLogin) if (Globals::globalConfig.bLogin)
@ -204,11 +226,11 @@ int Downloader::init()
{ {
if (!Globals::globalConfig.sGameHasDLCList.empty()) if (!Globals::globalConfig.sGameHasDLCList.empty())
{ {
if (Globals::globalConfig.gamehasdlc.empty()) if (Globals::globalConfig.gamehasdlc.has_value() && Globals::globalConfig.gamehasdlc->empty())
{ {
std::string game_has_dlc_list = this->getResponse(Globals::globalConfig.sGameHasDLCList); std::string game_has_dlc_list = this->getResponse(Globals::globalConfig.sGameHasDLCList);
if (!game_has_dlc_list.empty()) if (!game_has_dlc_list.empty())
Globals::globalConfig.gamehasdlc.initialize(Util::tokenize(game_has_dlc_list, "\n")); Globals::globalConfig.gamehasdlc = Filelist(Util::tokenize(game_has_dlc_list, "\n"));
} }
} }
@ -631,17 +653,8 @@ void Downloader::repair()
continue; continue;
std::string filepath = vGameFiles[i].getFilepath(); std::string filepath = vGameFiles[i].getFilepath();
if (Globals::globalConfig.whitelist.Matches(filepath)) if (shouldSkipFile(filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "including whitelisted file " << filepath << std::endl;
}
else if (Globals::globalConfig.blacklist.Matches(filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
}
// Refresh Galaxy login if token is expired // Refresh Galaxy login if token is expired
if (gogGalaxy->isTokenExpired()) if (gogGalaxy->isTokenExpired())
@ -1687,9 +1700,9 @@ std::string Downloader::getChangelogFromJSON(const Json::Value& json)
} }
// Linear search. Good thing computers are fast and lists are small. // Linear search. Good thing computers are fast and lists are small.
static int isPresent(const std::vector<gameFile>& list, const boost::filesystem::path& path, Filelist& blacklist) static int isPresent(std::vector<gameFile>& list, const boost::filesystem::path& path, std::optional<Filelist>& blacklist)
{ {
if(blacklist.Matches(path.native())) { if(blacklist.has_value() && blacklist->Matches(path.native())) {
return false; return false;
} }
for (unsigned int k = 0; k < list.size(); ++k) for (unsigned int k = 0; k < list.size(); ++k)
@ -1771,7 +1784,7 @@ void Downloader::checkOrphans()
if (boost::filesystem::is_regular_file(dir_iter->status())) if (boost::filesystem::is_regular_file(dir_iter->status()))
{ {
std::string filepath = dir_iter->path().string(); std::string filepath = dir_iter->path().string();
if (config.ignorelist.Matches(filepath.substr(pathlen))) { if (config.ignorelist.has_value() && config.ignorelist->Matches(filepath.substr(pathlen))) {
if (config.iMsgLevel >= MSGLEVEL_VERBOSE) if (config.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "skipped ignorelisted file " << filepath << std::endl; std::cerr << "skipped ignorelisted file " << filepath << std::endl;
} else { } else {
@ -1867,13 +1880,8 @@ void Downloader::checkStatus()
continue; continue;
const boost::filesystem::path filepath = gamefile.getFilepath(); const boost::filesystem::path filepath = gamefile.getFilepath();
if (Globals::globalConfig.whitelist.Matches(filepath.native())) { if (shouldSkipFile(filepath.native()))
// no-op
}
else if (Globals::globalConfig.blacklist.Matches(filepath.native())) {
continue; continue;
}
std::string filePathString = filepath.filename().string(); std::string filePathString = filepath.filename().string();
std::string gamename = gamefile.gamename; std::string gamename = gamefile.gamename;
@ -2559,7 +2567,7 @@ void Downloader::showWishlist()
return; return;
} }
void Downloader::processCloudSaveUploadQueue(Config conf, const unsigned int& tid) { void Downloader::processCloudSaveUploadQueue(const Config& conf, const unsigned int& tid) {
std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]"; std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]";
std::unique_ptr<galaxyAPI> galaxy { new galaxyAPI(Globals::globalConfig.curlConf) }; std::unique_ptr<galaxyAPI> galaxy { new galaxyAPI(Globals::globalConfig.curlConf) };
@ -2704,7 +2712,7 @@ void Downloader::processCloudSaveUploadQueue(Config conf, const unsigned int& ti
msgQueue.push(Message("Finished all tasks", MSGTYPE_INFO, msg_prefix, MSGLEVEL_DEFAULT)); msgQueue.push(Message("Finished all tasks", MSGTYPE_INFO, msg_prefix, MSGLEVEL_DEFAULT));
} }
void Downloader::processCloudSaveDownloadQueue(Config conf, const unsigned int& tid) { void Downloader::processCloudSaveDownloadQueue(const Config& conf, const unsigned int& tid) {
std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]"; std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]";
std::unique_ptr<galaxyAPI> galaxy { new galaxyAPI(Globals::globalConfig.curlConf) }; std::unique_ptr<galaxyAPI> galaxy { new galaxyAPI(Globals::globalConfig.curlConf) };
@ -2938,7 +2946,7 @@ void Downloader::processCloudSaveDownloadQueue(Config conf, const unsigned int&
msgQueue.push(Message("Finished all tasks", MSGTYPE_INFO, msg_prefix, MSGLEVEL_DEFAULT)); msgQueue.push(Message("Finished all tasks", MSGTYPE_INFO, msg_prefix, MSGLEVEL_DEFAULT));
} }
void Downloader::processDownloadQueue(Config conf, const unsigned int& tid) void Downloader::processDownloadQueue(const Config& conf, const unsigned int& tid)
{ {
std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]"; std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]";
@ -3000,12 +3008,17 @@ void Downloader::processDownloadQueue(Config conf, const unsigned int& tid)
filepath = boost::filesystem::absolute(filepath, boost::filesystem::current_path()); filepath = boost::filesystem::absolute(filepath, boost::filesystem::current_path());
boost::filesystem::path directory = filepath.parent_path(); boost::filesystem::path directory = filepath.parent_path();
if (conf.whitelist.Matches(filepath.string())) if (conf.whitelist.has_value())
{ {
if (conf.whitelist->Matches(filepath.string())) {
msgQueue.push(Message("Whitelisted file: " + filepath.string(), MSGTYPE_INFO, msg_prefix, MSGLEVEL_VERBOSE)); msgQueue.push(Message("Whitelisted file: " + filepath.string(), MSGTYPE_INFO, msg_prefix, MSGLEVEL_VERBOSE));
} else {
continue;
} }
else if (conf.blacklist.Matches(filepath.string())) }
else if (conf.blacklist.has_value())
{ {
if (conf.blacklist->Matches(filepath.string()))
msgQueue.push(Message("Blacklisted file: " + filepath.string(), MSGTYPE_INFO, msg_prefix, MSGLEVEL_VERBOSE)); msgQueue.push(Message("Blacklisted file: " + filepath.string(), MSGTYPE_INFO, msg_prefix, MSGLEVEL_VERBOSE));
continue; continue;
} }
@ -4000,22 +4013,11 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
for (auto it = items.begin(); it != items.end();) for (auto it = items.begin(); it != items.end();)
{ {
std::string item_install_path = install_path + "/" + it->path; std::string item_install_path = install_path + "/" + it->path;
if (Globals::globalConfig.whitelist.Matches(item_install_path)) if (shouldSkipFile(item_install_path)) {
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE) {
std::cout << "Including whitelisted file: " << item_install_path << std::endl;
}
}
else if (Globals::globalConfig.blacklist.Matches(item_install_path))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE) {
std::cout << "Skipping blacklisted file: " << item_install_path << std::endl;
}
it = items.erase(it); it = items.erase(it);
continue; } else {
it++;
} }
++it;
} }
// Check for differences between previously installed build and new build // Check for differences between previously installed build and new build
@ -4058,10 +4060,10 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
std::vector<std::string> deleted_filepaths; std::vector<std::string> deleted_filepaths;
if (!items_old.empty()) if (!items_old.empty())
{ {
for (auto old_item: items_old) for (const auto& old_item: items_old)
{ {
bool isDeleted = true; bool isDeleted = true;
for (auto item: items) for (const auto& item: items)
{ {
if (old_item.path == item.path) if (old_item.path == item.path)
{ {
@ -4077,7 +4079,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
// Delete old files // Delete old files
if (!deleted_filepaths.empty()) if (!deleted_filepaths.empty())
{ {
for (auto path : deleted_filepaths) for (const auto& path : deleted_filepaths)
{ {
std::string filepath = install_path + "/" + path; std::string filepath = install_path + "/" + path;
std::cout << "Deleting " << filepath << std::endl; std::cout << "Deleting " << filepath << std::endl;
@ -4166,7 +4168,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
} }
} }
void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Config conf, const unsigned int& tid) void Downloader::processGalaxyDownloadQueue(const std::string& install_path, const Config& conf, const unsigned int& tid)
{ {
std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]"; std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]";
@ -4714,8 +4716,12 @@ void Downloader::galaxyShowBuildFilesById(const std::string& product_id, int bui
json_items[i]["size"] = static_cast<unsigned int>(items[i].totalSizeUncompressed); json_items[i]["size"] = static_cast<unsigned int>(items[i].totalSizeUncompressed);
json_items[i]["md5"] = items[i].md5; json_items[i]["md5"] = items[i].md5;
json_items[i]["isDependency"] = items[i].isDependency; json_items[i]["isDependency"] = items[i].isDependency;
json_items[i]["whitelisted"] = Globals::globalConfig.whitelist.Matches(items[i].path); if (Globals::globalConfig.whitelist.has_value()) {
json_items[i]["blacklisted"] = Globals::globalConfig.blacklist.Matches(items[i].path); json_items[i]["whitelisted"] = Globals::globalConfig.whitelist->Matches(items[i].path);
}
if (Globals::globalConfig.blacklist.has_value()) {
json_items[i]["blacklisted"] = Globals::globalConfig.blacklist->Matches(items[i].path);
}
} }
Json::StyledStreamWriter().write(std::cout, json_items); Json::StyledStreamWriter().write(std::cout, json_items);
@ -4744,6 +4750,7 @@ std::string parseLocationHelper(const std::string &location, const std::map<std:
return parsedLocation; return parsedLocation;
} }
std::string parseLocation(const std::string &location, const std::map<std::string, std::string> &var) { std::string parseLocation(const std::string &location, const std::map<std::string, std::string> &var) {
auto parsedLocation = parseLocationHelper(location, var); auto parsedLocation = parseLocationHelper(location, var);
Util::replaceAllString(parsedLocation, "\\", "/"); Util::replaceAllString(parsedLocation, "\\", "/");
@ -5274,7 +5281,7 @@ std::vector<std::string> Downloader::galaxyGetOrphanedFiles(const std::vector<ga
if (boost::filesystem::is_regular_file(dir_iter->status())) if (boost::filesystem::is_regular_file(dir_iter->status()))
{ {
std::string filepath = dir_iter->path().string(); std::string filepath = dir_iter->path().string();
if (Globals::globalConfig.ignorelist.Matches(filepath.substr(pathlen))) if (Globals::globalConfig.ignorelist.has_value() && Globals::globalConfig.ignorelist->Matches(filepath.substr(pathlen)))
{ {
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE) if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "skipped ignorelisted file " << filepath << std::endl; std::cerr << "skipped ignorelisted file " << filepath << std::endl;
@ -5526,42 +5533,22 @@ void Downloader::galaxyInstallGame_MojoSetupHack(const std::string& product_id)
// Add files to download queue // Add files to download queue
uintmax_t totalSize = 0; uintmax_t totalSize = 0;
for (std::uintmax_t i = 0; i < vZipFiles.size(); ++i) for (const auto& zipfile : vZipFiles)
{ {
if (Globals::globalConfig.whitelist.Matches(vZipFiles[i].filepath)) if (shouldSkipFile(zipfile.filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "Including whitelisted file: " << vZipFiles[i].filepath << std::endl;
}
else if (Globals::globalConfig.blacklist.Matches(vZipFiles[i].filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "Skipping blacklisted file: " << vZipFiles[i].filepath << std::endl;
continue; continue;
} dlQueueGalaxy_MojoSetupHack.push(zipfile);
dlQueueGalaxy_MojoSetupHack.push(vZipFiles[i]); iTotalRemainingBytes.fetch_add(zipfile.comp_size);
iTotalRemainingBytes.fetch_add(vZipFiles[i].comp_size); totalSize += zipfile.uncomp_size;
totalSize += vZipFiles[i].uncomp_size;
} }
// Add symlinks to download queue // Add symlinks to download queue
for (std::uintmax_t i = 0; i < vZipFilesSymlink.size(); ++i) for (const auto& symlink_zipfile : vZipFilesSymlink) {
{ if (shouldSkipFile(symlink_zipfile.filepath))
if (Globals::globalConfig.whitelist.Matches(vZipFiles[i].filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "Including whitelisted file: " << vZipFiles[i].filepath << std::endl;
}
else if (Globals::globalConfig.blacklist.Matches(vZipFilesSymlink[i].filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cout << "Skipping blacklisted file: " << vZipFilesSymlink[i].filepath << std::endl;
continue; continue;
} dlQueueGalaxy_MojoSetupHack.push(symlink_zipfile);
dlQueueGalaxy_MojoSetupHack.push(vZipFilesSymlink[i]); iTotalRemainingBytes.fetch_add(symlink_zipfile.comp_size);
iTotalRemainingBytes.fetch_add(vZipFilesSymlink[i].comp_size); totalSize += symlink_zipfile.uncomp_size;
totalSize += vZipFilesSymlink[i].uncomp_size;
} }
std::cout << game.title << std::endl; std::cout << game.title << std::endl;
@ -5756,7 +5743,7 @@ void Downloader::galaxyInstallGame_MojoSetupHack_CombineSplitFiles(const splitFi
return; return;
} }
void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const unsigned int& tid) void Downloader::processGalaxyDownloadQueue_MojoSetupHack(const Config& conf, const unsigned int& tid)
{ {
std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]"; std::string msg_prefix = "[Thread #" + std::to_string(tid) + "]";
@ -6580,18 +6567,9 @@ void Downloader::printGameDetailsAsText(gameDetails& game)
void Downloader::printGameFileDetailsAsText(gameFile& gf) void Downloader::printGameFileDetailsAsText(gameFile& gf)
{ {
std::string filepath = gf.getFilepath(); const std::string filepath = gf.getFilepath();
if (Globals::globalConfig.whitelist.Matches(filepath)) if(shouldSkipFile(filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "included whitelisted file " << filepath << std::endl;
}
else if (Globals::globalConfig.blacklist.Matches(filepath))
{
if (Globals::globalConfig.iMsgLevel >= MSGLEVEL_VERBOSE)
std::cerr << "skipped blacklisted file " << filepath << std::endl;
return; return;
}
std::cout << "\tid: " << gf.id << std::endl std::cout << "\tid: " << gf.id << std::endl
<< "\tname: " << gf.name << std::endl << "\tname: " << gf.name << std::endl

View File

@ -16,7 +16,7 @@ enum {
BLFLAG_PERL = 1 << 1 BLFLAG_PERL = 1 << 1
}; };
void Filelist::initialize(const std::vector<std::string>& lines) { Filelist::Filelist(const std::vector<std::string>& lines) {
int linenr = 1; int linenr = 1;
for (auto it = lines.begin(); it != lines.end(); ++it, ++linenr) { for (auto it = lines.begin(); it != lines.end(); ++it, ++linenr) {
FilelistItem item; FilelistItem item;
@ -57,12 +57,13 @@ void Filelist::initialize(const std::vector<std::string>& lines) {
item.regex.assign(item.source, rx_flags); item.regex.assign(item.source, rx_flags);
files.push_back(std::move(item)); files.push_back(std::move(item));
} else { } else {
std::cout << "unknown expression type in blacklist line " << linenr << std::endl; std::cerr << "unknown expression type in filelist line " << linenr << std::endl;
} }
} }
} }
bool Filelist::Matches(const std::string& path) { bool Filelist::Matches(const std::string& path) const
{
for (const auto& item : files) { for (const auto& item : files) {
if (item.flags & BLFLAG_RX && boost::regex_search(path, item.regex)) if (item.flags & BLFLAG_RX && boost::regex_search(path, item.regex))
return true; return true;
@ -70,7 +71,7 @@ bool Filelist::Matches(const std::string& path) {
return false; return false;
} }
bool Filelist::Matches(const std::string& path, const std::string& gamename, std::string subdirectory) bool Filelist::Matches(const std::string& path, const std::string& gamename, std::string subdirectory) const
{ {
const std::string filepath = Util::makeRelativeFilepath(path, gamename, subdirectory); const std::string filepath = Util::makeRelativeFilepath(path, gamename, subdirectory);
return Matches(filepath); return Matches(filepath);

View File

@ -209,9 +209,8 @@ std::vector<gameItem> Website::getGames()
} }
} }
if (!bDownloadDLCInfo && !Globals::globalConfig.gamehasdlc.empty()) if (!bDownloadDLCInfo && !Globals::globalConfig.gamehasdlc.has_value() && !Globals::globalConfig.gamehasdlc->empty()) {
{ if (Globals::globalConfig.gamehasdlc->Matches(game.name))
if (Globals::globalConfig.gamehasdlc.Matches(game.name))
bDownloadDLCInfo = true; bDownloadDLCInfo = true;
} }