From 1204ea247e52b2ae030d6adf67f41f030560b310 Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Sat, 25 Oct 2014 17:57:04 +0200 Subject: [PATCH] Preparation work on priority mode: config file parsing, documentation. --- include/config.h | 5 +++ main.cpp | 46 +++++++++++++++++++++++++++ man/lgogdownloader.supplemental.groff | 11 +++++++ 3 files changed, 62 insertions(+) diff --git a/include/config.h b/include/config.h index 3fc9a48..01d2939 100644 --- a/include/config.h +++ b/include/config.h @@ -63,6 +63,11 @@ class Config std::string sLanguagePackSubdir; std::string sDLCSubdir; std::string sGameSubdir; + std::string sLanguagePriority; + std::string sPlatformPriority; + std::vector vLanguagePriority; + std::vector vPlatformPriority; + unsigned int iInstallerType; unsigned int iInstallerLanguage; int iRetries; diff --git a/main.cpp b/main.cpp index 4019688..c752031 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,40 @@ template void set_vm_value(std::map &priority, unsigned int &type) +{ + size_t idx = 0, found; + + while ((found = priority_string.find(',', idx)) != std::string::npos) + { + priority.push_back(std::stoi(priority_string.substr(idx, found - idx))); + idx = found + 1; + } + priority.push_back(std::stoi(priority_string.substr(idx))); + + 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; + } +} + int main(int argc, char *argv[]) { Config config; @@ -68,6 +102,8 @@ 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 unrecognized_options_cfg; bpo::variables_map vm; @@ -148,6 +184,9 @@ 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\" 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\" for Linux first, then Windows if no Linux version").c_str()) + ; // Options read from config file options_cfg_only.add_options() @@ -300,6 +339,13 @@ int main(int argc, char *argv[]) // Override cover option if (bNoCover) config.bCover = false; + + // Handle priority business + if (!config.sLanguagePriority.empty()) + handle_priority("languages", config.sLanguagePriority, config.vLanguagePriority, config.iInstallerLanguage); + if (!config.sPlatformPriority.empty()) + handle_priority("platforms", config.sPlatformPriority, config.vPlatformPriority, config.iInstallerType); + } catch (std::exception& e) { diff --git a/man/lgogdownloader.supplemental.groff b/man/lgogdownloader.supplemental.groff index bf719eb..5f5ad1d 100644 --- a/man/lgogdownloader.supplemental.groff +++ b/man/lgogdownloader.supplemental.groff @@ -83,5 +83,16 @@ Must be in the following format: .br } +[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. +.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. +.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. + [availability] The latest version of this distribution is available from \fIhttps://github.com/Sude-/lgogdownloader\fP +