From f9981c1be027e07549e4925056abd22cecfa12bd Mon Sep 17 00:00:00 2001 From: Sude Date: Sun, 5 Mar 2017 22:47:44 +0200 Subject: [PATCH] Galaxy: Add option to select platform --- include/config.h | 1 + main.cpp | 11 +++++++++++ src/downloader.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index a31573f..f3b2ded 100644 --- a/include/config.h +++ b/include/config.h @@ -34,6 +34,7 @@ struct DownloadConfig std::vector vPlatformPriority; std::vector vLanguagePriority; unsigned int iInclude; + unsigned int iGalaxyPlatform; bool bRemoteXML; bool bCover; diff --git a/main.cpp b/main.cpp index 2c1b6cc..3d8720f 100644 --- a/main.cpp +++ b/main.cpp @@ -74,6 +74,13 @@ int main(int argc, char *argv[]) platform_text += "\n\n" + priority_help_text; platform_text += "\nExample: Linux if available otherwise Windows and Mac: l,w+m"; + // Create help text for --galaxy-platform option + std::string galaxy_platform_text = "Select platform\n"; + for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i) + { + galaxy_platform_text += GlobalConstants::PLATFORMS[i].str + " = " + GlobalConstants::PLATFORMS[i].regexp + "|" + std::to_string(GlobalConstants::PLATFORMS[i].id) + "\n"; + } + // Create help text for --language option std::string language_text = "Select which language installers are downloaded\n"; unsigned int language_all = Util::getOptionValue("all", GlobalConstants::LANGUAGES); @@ -129,6 +136,7 @@ int main(int argc, char *argv[]) std::string sInstallerLanguage; std::string sIncludeOptions; std::string sExcludeOptions; + std::string sGalaxyPlatform; Globals::globalConfig.bReport = false; // Commandline options (no config file) options_cli_no_cfg.add_options() @@ -202,6 +210,7 @@ int main(int argc, char *argv[]) options_cli_no_cfg_hidden.add_options() ("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()) ; options_cli_all.add(options_cli_no_cfg).add(options_cli_cfg); @@ -402,6 +411,8 @@ int main(int argc, char *argv[]) Util::parseOptionString(sInstallerLanguage, Globals::globalConfig.dlConf.vLanguagePriority, Globals::globalConfig.dlConf.iInstallerLanguage, GlobalConstants::LANGUAGES); Util::parseOptionString(sInstallerPlatform, Globals::globalConfig.dlConf.vPlatformPriority, Globals::globalConfig.dlConf.iInstallerPlatform, GlobalConstants::PLATFORMS); + Globals::globalConfig.dlConf.iGalaxyPlatform = Util::getOptionValue(sGalaxyPlatform, GlobalConstants::PLATFORMS); + unsigned int include_value = 0; unsigned int exclude_value = 0; std::vector vInclude = Util::tokenize(sIncludeOptions, ","); diff --git a/src/downloader.cpp b/src/downloader.cpp index e624c89..e477a9b 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -3498,7 +3498,24 @@ void Downloader::galaxyInstallGame(const std::string& product_id, int build_inde if (build_index < 0) build_index = 0; - Json::Value json = gogGalaxy->getProductBuilds(product_id); + std::string sPlatform; + unsigned int iPlatform = Globals::globalConfig.dlConf.iGalaxyPlatform; + if (iPlatform == GlobalConstants::PLATFORM_LINUX) + sPlatform = "linux"; + else if (iPlatform == GlobalConstants::PLATFORM_MAC) + sPlatform = "osx"; + else + sPlatform = "windows"; + + 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 + if (json.empty() && iPlatform == GlobalConstants::PLATFORM_LINUX) + { + std::cout << "Galaxy API doesn't have Linux support" << std::endl; + return; + } + if (json["items"][build_index]["generation"].asInt() != 2) { std::cout << "Only generation 2 builds are supported currently" << std::endl; @@ -3775,7 +3792,24 @@ void Downloader::galaxyInstallGame(const std::string& product_id, int build_inde void Downloader::galaxyShowBuilds(const std::string& product_id, int build_index) { - Json::Value json = gogGalaxy->getProductBuilds(product_id); + std::string sPlatform; + unsigned int iPlatform = Globals::globalConfig.dlConf.iGalaxyPlatform; + if (iPlatform == GlobalConstants::PLATFORM_LINUX) + sPlatform = "linux"; + else if (iPlatform == GlobalConstants::PLATFORM_MAC) + sPlatform = "osx"; + else + sPlatform = "windows"; + + 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 + if (json.empty() && iPlatform == GlobalConstants::PLATFORM_LINUX) + { + std::cout << "Galaxy API doesn't have Linux support" << std::endl; + return; + } + if (build_index < 0) { for (unsigned int i = 0; i < json["items"].size(); ++i)