From 211aa3a3e628760a23b30cec18f2c17bd75834a1 Mon Sep 17 00:00:00 2001 From: Sude Date: Sat, 3 Oct 2015 19:09:50 +0300 Subject: [PATCH] Combine priority handling with --platform and --language options Use "+" as separator to combine values and "," to set priority --- main.cpp | 75 ++++++++------------------- man/lgogdownloader.supplemental.groff | 9 ++-- 2 files changed, 26 insertions(+), 58 deletions(-) diff --git a/main.cpp b/main.cpp index ba4b8c5..06d4aff 100644 --- a/main.cpp +++ b/main.cpp @@ -26,46 +26,22 @@ template void set_vm_value(std::map &priority, unsigned int &type, const std::vector& options) +// Parse the options string +void parseOptionString(const std::string &option_string, std::vector &priority, unsigned int &type, const std::vector& options) { - std::vector tokens = Util::tokenize(priority_string, ","); - for (std::vector::iterator it = tokens.begin(); it != tokens.end(); it++) + 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++) { - priority.push_back(Util::getOptionValue(*it, options)); + 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; } - - unsigned int wanted = 0; - #ifdef DEBUG - std::cerr << "DEBUG INFO (handle_priority): for " << what << " found "; - #endif - for (std::vector::iterator it = priority.begin(); it != priority.end(); it++) - { - wanted |= *it; - #ifdef DEBUG - std::cerr << *it << " "; - #endif - } - #ifdef DEBUG - std::cerr << std::endl; - #endif - - if (wanted != type) - { - type = wanted; - std::cout << "Warning: for " << what << " the priority string doesn't match the enabled installers, forcing enabled installers to " << type << std::endl; - } -} - -unsigned int parseOptionString(const std::string &option_string, const std::vector& options) -{ - unsigned int value = 0; - std::vector tokens = Util::tokenize(option_string, ","); - for (std::vector::iterator it = tokens.begin(); it != tokens.end(); it++) - { - value |= Util::getOptionValue(*it, options); - } - return value; } int main(int argc, char *argv[]) @@ -82,6 +58,7 @@ int main(int argc, char *argv[]) config.sConfigFilePath = config.sConfigDirectory + "/config.cfg"; config.sBlacklistFilePath = config.sConfigDirectory + "/blacklist.txt"; + std::string priority_help_text = "Set priority by separating values with \",\"\nCombine values by separating with \"+\""; // Create help text for --platform option std::string platform_text = "Select which installers are downloaded\n"; unsigned int platform_all = Util::getOptionValue("all", GlobalConstants::PLATFORMS); @@ -90,6 +67,8 @@ int main(int argc, char *argv[]) platform_text += GlobalConstants::PLATFORMS[i].str + " = " + GlobalConstants::PLATFORMS[i].regexp + "|" + std::to_string(GlobalConstants::PLATFORMS[i].id) + "\n"; } platform_text += "All = all|" + std::to_string(platform_all); + platform_text += "\n\n" + priority_help_text; + platform_text += "\nExample: Linux if available otherwise Windows and Mac: l,w+m"; // Create help text for --language option std::string language_text = "Select which language installers are downloaded\n"; @@ -99,7 +78,9 @@ int main(int argc, char *argv[]) language_text += GlobalConstants::LANGUAGES[i].str + " = " + GlobalConstants::LANGUAGES[i].regexp + "|" + std::to_string(GlobalConstants::LANGUAGES[i].id) + "\n"; } language_text += "Add the values to download multiple languages\nAll = all|" + std::to_string(language_all) + "\n" - + "French + Polish = \"fr,pl\"|" + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL) + " (" + std::to_string(GlobalConstants::LANGUAGE_FR) + "+" + std::to_string(GlobalConstants::LANGUAGE_PL) + "=" + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL) + ")"; + + "French + Polish = \"fr+pl\"|" + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL) + " (" + std::to_string(GlobalConstants::LANGUAGE_FR) + "+" + std::to_string(GlobalConstants::LANGUAGE_PL) + "=" + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL) + ")"; + language_text += "\n\n" + priority_help_text; + language_text += "\nExample: German if available otherwise English and French: de,en+fr"; // Create help text for --check-orphans std::string orphans_regex_default = ".*\\.(zip|exe|bin|dmg|old|deb|tar\\.gz|pkg|sh)$"; // Limit to files with these extensions (".old" is for renamed older version files) @@ -107,8 +88,6 @@ int main(int argc, char *argv[]) // Help text for subdir options std::string subdir_help_text = "\nTemplates:\n- %platform%\n- %gamename%\n- %dlcname%"; - // Help text for priority options - std::string priority_help_text = "\nIf set, only the first matching one will be downloaded. If unset, all matching combinations will be downloaded.\nSyntax: use a string separated by \",\""; std::vector vFileIdStrings; std::vector unrecognized_options_cfg; @@ -170,8 +149,8 @@ int main(int argc, char *argv[]) ("limit-rate", bpo::value(&config.iDownloadRate)->default_value(0), "Limit download rate to value in kB\n0 = unlimited") ("xml-directory", bpo::value(&config.sXMLDirectory), "Set directory for GOG XML files") ("chunk-size", bpo::value(&config.iChunkSize)->default_value(10), "Chunk size (in MB) when creating XML") - ("platform", bpo::value(&sInstallerPlatform)->default_value(std::to_string(GlobalConstants::PLATFORM_WINDOWS|GlobalConstants::PLATFORM_LINUX)), platform_text.c_str()) - ("language", bpo::value(&sInstallerLanguage)->default_value(std::to_string(GlobalConstants::LANGUAGE_EN)), language_text.c_str()) + ("platform", bpo::value(&sInstallerPlatform)->default_value("w+l"), platform_text.c_str()) + ("language", bpo::value(&sInstallerLanguage)->default_value("en"), language_text.c_str()) ("no-installers", bpo::value(&bNoInstallers)->zero_tokens()->default_value(false), "Don't download/list/repair installers") ("no-extras", bpo::value(&bNoExtras)->zero_tokens()->default_value(false), "Don't download/list/repair extras") ("no-patches", bpo::value(&bNoPatches)->zero_tokens()->default_value(false), "Don't download/list/repair patches") @@ -197,8 +176,6 @@ int main(int argc, char *argv[]) ("subdir-game", bpo::value(&config.sGameSubdir)->default_value("%gamename%"), ("Set subdirectory for game" + subdir_help_text).c_str()) ("use-cache", bpo::value(&config.bUseCache)->zero_tokens()->default_value(false), ("Use game details cache")) ("cache-valid", bpo::value(&config.iCacheValid)->default_value(2880), ("Set how long cached game details are valid (in minutes)\nDefault: 2880 minutes (48 hours)")) - ("language-priority", bpo::value(&config.sLanguagePriority)->default_value(""), ("Set priority of systems" + priority_help_text + ", like \"4,1\" or \"fr,en\" for French first, then English if no French version").c_str()) - ("platform-priority", bpo::value(&config.sPlatformPriority)->default_value(""), ("Set priority of platforms" + priority_help_text + ", like \"4,1\" or \"linux,windows\" for Linux first, then Windows if no Linux version").c_str()) ("save-serials", bpo::value(&config.bSaveSerials)->zero_tokens()->default_value(false), "Save serial numbers when downloading") ("ignore-dlc-count", bpo::value(&config.sIgnoreDLCCountRegex)->implicit_value(".*"), "Set regular expression filter for games to ignore DLC count information\nIgnoring DLC count information helps in situations where the account page doesn't provide accurate information about DLCs") ; @@ -326,8 +303,6 @@ int main(int argc, char *argv[]) config.bRemoteXML = !bNoRemoteXML; config.bSubDirectories = !bNoSubDirectories; config.bPlatformDetection = !bNoPlatformDetection; - config.iInstallerLanguage = parseOptionString(sInstallerLanguage, GlobalConstants::LANGUAGES); - config.iInstallerPlatform = parseOptionString(sInstallerPlatform, GlobalConstants::PLATFORMS); for (auto i = unrecognized_options_cli.begin(); i != unrecognized_options_cli.end(); ++i) if (i->compare(0, GlobalConstants::PROTOCOL_PREFIX.length(), GlobalConstants::PROTOCOL_PREFIX) == 0) @@ -358,12 +333,8 @@ int main(int argc, char *argv[]) config.bLoginHTTP = true; } - // Handle priority business - if (!config.sLanguagePriority.empty()) - handle_priority("languages", config.sLanguagePriority, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES); - if (!config.sPlatformPriority.empty()) - handle_priority("platforms", config.sPlatformPriority, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS); - + parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES); + parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS); } catch (std::exception& e) { diff --git a/man/lgogdownloader.supplemental.groff b/man/lgogdownloader.supplemental.groff index 52e1735..22423a0 100644 --- a/man/lgogdownloader.supplemental.groff +++ b/man/lgogdownloader.supplemental.groff @@ -85,14 +85,11 @@ Must be in the following format: } [priorities] -For both languages and platforms, the default behavior is to download all enabled ones. -The \fBlanguage-priority\fB and \fBplatform-priority\fB switches enable a priority-based mode: only the first matching one will be downloaded. +Separating values with "," when using \fBlanguage\fP and \fBplatform\fP switches enables a priority-based mode: only the first matching one will be downloaded. .PP -For example, setting \fBlanguage\fB to 5 means both French and English will be downloaded (if available) for all games. Setting \fBlanguage-priority\fB to 4,1 means that the French version (and only that one) will be downloaded if available, and if not, the English version will be downloaded. +For example, setting \fBlanguage\fP to \fBfr+en\fP means both French and English will be downloaded (if available) for all games. Setting \fBlanguage\fP to \fBfr,en\fP means that the French version (and only that one) will be downloaded if available, and if not, the English version will be downloaded. .PP -You're allowed to "stack" codes in the priority string if needed. If you set \fBlanguage-priority\fB 132,1 it means it'll download both Spanish (128) and French (4) versions if they are available, and the English (1) one only if none of French and Spanish are available. -.PP -Ideally the \fBlanguage\fB and \fBplatform\fB settings should match the sum of all enabled codes in the "priority" versions. If they don't, they'll be overrided with a warning. +You're allowed to "stack" codes in the priority string if needed. If you set \fBlanguage\fP to \fBes+fr,en\fP it means it'll download both Spanish (es) and French (fr) versions if they are available, and the English (en) one only if none of French and Spanish are available. [availability] The latest version of this distribution is available from \fIhttps://github.com/Sude-/lgogdownloader\fP