From d4a6791e65d1d01727eaa4d641b5e694d7a8add9 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 6 Mar 2017 07:22:34 +0200 Subject: [PATCH] Galaxy: Add option to select language --- include/config.h | 1 + main.cpp | 10 ++++++++++ src/downloader.cpp | 19 +++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/config.h b/include/config.h index 38213a2..5f00b5b 100644 --- a/include/config.h +++ b/include/config.h @@ -35,6 +35,7 @@ struct DownloadConfig std::vector vLanguagePriority; unsigned int iInclude; unsigned int iGalaxyPlatform; + unsigned int iGalaxyLanguage; bool bRemoteXML; bool bCover; diff --git a/main.cpp b/main.cpp index 2e14e06..3298781 100644 --- a/main.cpp +++ b/main.cpp @@ -93,6 +93,13 @@ int main(int argc, char *argv[]) language_text += "\n\n" + priority_help_text; language_text += "\nExample: German if available otherwise English and French: de,en+fr"; + // Create help text for --galaxy-language option + std::string galaxy_language_text = "Select language\n"; + for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i) + { + galaxy_language_text += GlobalConstants::LANGUAGES[i].str + " = " + GlobalConstants::LANGUAGES[i].regexp + "|" + std::to_string(GlobalConstants::LANGUAGES[i].id) + "\n"; + } + // 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) std::string check_orphans_text = "Check for orphaned files (files found on local filesystem that are not found on GOG servers). Sets regular expression filter (Perl syntax) for files to check. If no argument is given then the regex defaults to '" + orphans_regex_default + "'"; @@ -137,6 +144,7 @@ int main(int argc, char *argv[]) std::string sIncludeOptions; std::string sExcludeOptions; std::string sGalaxyPlatform; + std::string sGalaxyLanguage; Globals::globalConfig.bReport = false; // Commandline options (no config file) options_cli_no_cfg.add_options() @@ -211,6 +219,7 @@ int main(int argc, char *argv[]) ("galaxy-install", bpo::value(&galaxy_product_id_install)->default_value(""), "Install game using product id") ("galaxy-show-builds", bpo::value(&galaxy_product_id_show_builds)->default_value(""), "Show game builds using product id") ("galaxy-platform", bpo::value(&sGalaxyPlatform)->default_value("w"), galaxy_platform_text.c_str()) + ("galaxy-language", bpo::value(&sGalaxyLanguage)->default_value("en"), galaxy_language_text.c_str()) ("login-email", bpo::value(&Globals::globalConfig.sEmail)->default_value(""), "login email") ("login-password", bpo::value(&Globals::globalConfig.sPassword)->default_value(""), "login password") ; @@ -440,6 +449,7 @@ int main(int argc, char *argv[]) Util::parseOptionString(sInstallerPlatform, Globals::globalConfig.dlConf.vPlatformPriority, Globals::globalConfig.dlConf.iInstallerPlatform, GlobalConstants::PLATFORMS); Globals::globalConfig.dlConf.iGalaxyPlatform = Util::getOptionValue(sGalaxyPlatform, GlobalConstants::PLATFORMS); + Globals::globalConfig.dlConf.iGalaxyLanguage = Util::getOptionValue(sGalaxyLanguage, GlobalConstants::LANGUAGES); unsigned int include_value = 0; unsigned int exclude_value = 0; diff --git a/src/downloader.cpp b/src/downloader.cpp index eaf6583..66fc36e 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -3516,6 +3516,17 @@ void Downloader::galaxyInstallGame(const std::string& product_id, int build_inde else sPlatform = "windows"; + std::string sLanguage = "en"; + unsigned int iLanguage = Globals::globalConfig.dlConf.iGalaxyLanguage; + for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i) + { + if (GlobalConstants::LANGUAGES[i].id == iLanguage) + { + sLanguage = GlobalConstants::LANGUAGES[i].code; + break; + } + } + Json::Value json = gogGalaxy->getProductBuilds(product_id, sPlatform); // JSON is empty and platform is Linux. Most likely cause is that Galaxy API doesn't have Linux support @@ -3544,15 +3555,15 @@ void Downloader::galaxyInstallGame(const std::string& product_id, int build_inde std::vector items; for (unsigned int i = 0; i < json["depots"].size(); ++i) { - bool bSupportedLanguage = false; + bool bSelectedLanguage = false; for (unsigned int j = 0; j < json["depots"][i]["languages"].size(); ++j) { std::string language = json["depots"][i]["languages"][j].asString(); - if (language == "*" || language == "en") - bSupportedLanguage = true; + if (language == "*" || language == sLanguage) + bSelectedLanguage = true; } - if (!bSupportedLanguage) + if (!bSelectedLanguage) continue; std::string depotHash = json["depots"][i]["manifest"].asString();