diff --git a/include/gamedetails.h b/include/gamedetails.h index f0af033..4ccc601 100644 --- a/include/gamedetails.h +++ b/include/gamedetails.h @@ -23,13 +23,13 @@ class gameDetails std::string title; std::string icon; std::string serials; - void filterWithPriorities(const Config& config); + void filterWithPriorities(const gameSpecificConfig& config); void makeFilepaths(const gameSpecificDirectoryConfig& config); std::string getSerialsFilepath(); Json::Value getDetailsAsJson(); virtual ~gameDetails(); protected: - void filterListWithPriorities(std::vector& list, const Config& config); + void filterListWithPriorities(std::vector& list, const gameSpecificConfig& config); private: std::string serialsFilepath; }; diff --git a/include/util.h b/include/util.h index c289288..8f77162 100644 --- a/include/util.h +++ b/include/util.h @@ -39,6 +39,8 @@ struct gameSpecificConfig bool bDLC; bool bIgnoreDLCCount; gameSpecificDirectoryConfig dirConf; + std::vector vLanguagePriority; + std::vector vPlatformPriority; }; namespace Util @@ -61,6 +63,7 @@ namespace Util std::vector tokenize(const std::string& str, const std::string& separator = ","); unsigned int getOptionValue(const std::string& str, const std::vector& options); std::string getOptionNameString(const unsigned int& value, const std::vector& options); + void parseOptionString(const std::string &option_string, std::vector &priority, unsigned int &type, const std::vector& options); } #endif // UTIL_H diff --git a/main.cpp b/main.cpp index b521f67..27ec91e 100644 --- a/main.cpp +++ b/main.cpp @@ -20,24 +20,6 @@ template void set_vm_value(std::map &priority, unsigned int &type, const std::vector& options) -{ - type = 0; - std::vector tokens_priority = Util::tokenize(option_string, ","); - for (std::vector::iterator it_priority = tokens_priority.begin(); it_priority != tokens_priority.end(); it_priority++) - { - unsigned int value = 0; - std::vector tokens_value = Util::tokenize(*it_priority, "+"); - for (std::vector::iterator it_value = tokens_value.begin(); it_value != tokens_value.end(); it_value++) - { - value |= Util::getOptionValue(*it_value, options); - } - priority.push_back(value); - type |= value; - } -} - int main(int argc, char *argv[]) { // Constants for option selection with include/exclude @@ -342,8 +324,8 @@ int main(int argc, char *argv[]) if (config.sXMLFile == "automatic") config.bAutomaticXMLCreation = true; - parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES); - parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS); + Util::parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES); + Util::parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS); unsigned int include_value = 0; unsigned int exclude_value = 0; diff --git a/src/downloader.cpp b/src/downloader.cpp index 319bde1..35162c3 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -270,17 +270,48 @@ int Downloader::getGameDetails() conf.iInstallerLanguage = config.iInstallerLanguage; conf.iInstallerPlatform = config.iInstallerPlatform; conf.dirConf = dirConfDefault; + conf.vLanguagePriority = config.vLanguagePriority; + conf.vPlatformPriority = config.vPlatformPriority; if (!config.bUpdateCache) // Disable game specific config files for cache update { int iOptionsOverridden = Util::getGameSpecificConfig(gameItems[i].name, &conf); if (iOptionsOverridden > 0) + { std::cout << std::endl << gameItems[i].name << " - " << iOptionsOverridden << " options overridden with game specific options" << std::endl; + if (config.bVerbose) + { + if (conf.bIgnoreDLCCount) + std::cout << "\tIgnore DLC count" << std::endl; + if (conf.bDLC != config.bDLC) + std::cout << "\tDLC: " << (conf.bDLC ? "true" : "false") << std::endl; + if (conf.iInstallerLanguage != config.iInstallerLanguage) + std::cout << "\tLanguage: " << Util::getOptionNameString(conf.iInstallerLanguage, GlobalConstants::LANGUAGES) << std::endl; + if (conf.vLanguagePriority != config.vLanguagePriority) + { + std::cout << "\tLanguage priority:" << std::endl; + for (unsigned int j = 0; j < conf.vLanguagePriority.size(); ++j) + { + std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vLanguagePriority[j], GlobalConstants::LANGUAGES) << std::endl; + } + } + if (conf.iInstallerPlatform != config.iInstallerPlatform) + std::cout << "\tPlatform: " << Util::getOptionNameString(conf.iInstallerPlatform, GlobalConstants::PLATFORMS) << std::endl; + if (conf.vPlatformPriority != config.vPlatformPriority) + { + std::cout << "\tPlatform priority:" << std::endl; + for (unsigned int j = 0; j < conf.vPlatformPriority.size(); ++j) + { + std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vPlatformPriority[j], GlobalConstants::PLATFORMS) << std::endl; + } + } + } + } } game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler); if (!gogAPI->getError()) { - game.filterWithPriorities(config); + game.filterWithPriorities(conf); Json::Value gameDetailsJSON; if (game.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras @@ -311,7 +342,7 @@ int Downloader::getGameDetails() { gameDetails dlc; dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler); - dlc.filterWithPriorities(config); + dlc.filterWithPriorities(conf); if (dlc.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras { if (gameDetailsJSON.empty()) @@ -3058,6 +3089,8 @@ std::vector Downloader::getGameDetailsFromJsonNode(Json::Value root conf.bDLC = config.bDLC; conf.iInstallerLanguage = config.iInstallerLanguage; conf.iInstallerPlatform = config.iInstallerPlatform; + conf.vLanguagePriority = config.vLanguagePriority; + conf.vPlatformPriority = config.vPlatformPriority; if (Util::getGameSpecificConfig(game.gamename, &conf) > 0) std::cout << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl; @@ -3107,7 +3140,7 @@ std::vector Downloader::getGameDetailsFromJsonNode(Json::Value root } if (!game.extras.empty() || !game.installers.empty() || !game.patches.empty() || !game.languagepacks.empty() || !game.dlcs.empty()) { - game.filterWithPriorities(config); + game.filterWithPriorities(conf); details.push_back(game); } } diff --git a/src/gamedetails.cpp b/src/gamedetails.cpp index 0224910..71bb347 100644 --- a/src/gamedetails.cpp +++ b/src/gamedetails.cpp @@ -10,7 +10,7 @@ gameDetails::~gameDetails() //dtor } -void gameDetails::filterWithPriorities(const Config& config) +void gameDetails::filterWithPriorities(const gameSpecificConfig& config) { if (config.vPlatformPriority.empty() && config.vLanguagePriority.empty()) return; @@ -20,7 +20,7 @@ void gameDetails::filterWithPriorities(const Config& config) filterListWithPriorities(languagepacks, config); } -void gameDetails::filterListWithPriorities(std::vector& list, const Config& config) +void gameDetails::filterListWithPriorities(std::vector& list, const gameSpecificConfig& config) { /* Compute the score of each item - we use a scoring mechanism and we keep all ties diff --git a/src/util.cpp b/src/util.cpp index c82f1a7..5433650 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -240,36 +240,22 @@ int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, { if (root.isMember("language")) { - unsigned int language = 0; if (root["language"].isInt()) - language = root["language"].asUInt(); + conf->iInstallerLanguage = root["language"].asUInt(); else { - std::vector tokens = Util::tokenize(root["language"].asString(), "+"); - for (std::vector::iterator it = tokens.begin(); it != tokens.end(); it++) - { - language |= Util::getOptionValue(*it, GlobalConstants::LANGUAGES); - } + Util::parseOptionString(root["language"].asString(), conf->vLanguagePriority, conf->iInstallerLanguage, GlobalConstants::LANGUAGES); } - - conf->iInstallerLanguage = language; res++; } if (root.isMember("platform")) { - unsigned int platform = 0; if (root["platform"].isInt()) - platform = root["platform"].asUInt(); + conf->iInstallerPlatform = root["platform"].asUInt(); else { - std::vector tokens = Util::tokenize(root["platform"].asString(), "+"); - for (std::vector::iterator it = tokens.begin(); it != tokens.end(); it++) - { - platform |= Util::getOptionValue(*it, GlobalConstants::PLATFORMS); - } + Util::parseOptionString(root["platform"].asString(), conf->vPlatformPriority, conf->iInstallerPlatform, GlobalConstants::PLATFORMS); } - - conf->iInstallerPlatform = platform; res++; } if (root.isMember("dlc")) @@ -535,3 +521,22 @@ std::string Util::getOptionNameString(const unsigned int& value, const std::vect } return str; } + +// Parse the options string +void Util::parseOptionString(const std::string &option_string, std::vector &priority, unsigned int &type, const std::vector& options) +{ + type = 0; + priority.clear(); + std::vector tokens_priority = Util::tokenize(option_string, ","); + for (std::vector::iterator it_priority = tokens_priority.begin(); it_priority != tokens_priority.end(); it_priority++) + { + unsigned int value = 0; + std::vector tokens_value = Util::tokenize(*it_priority, "+"); + for (std::vector::iterator it_value = tokens_value.begin(); it_value != tokens_value.end(); it_value++) + { + value |= Util::getOptionValue(*it_value, options); + } + priority.push_back(value); + type |= value; + } +}