diff --git a/include/config.h b/include/config.h index 9c678ec..ea6fe6c 100644 --- a/include/config.h +++ b/include/config.h @@ -78,6 +78,7 @@ class Config unsigned int iInstallerPlatform; unsigned int iInstallerLanguage; + unsigned int iInclude; int iRetries; int iWait; int iCacheValid; diff --git a/main.cpp b/main.cpp index 06d4aff..0a19e91 100644 --- a/main.cpp +++ b/main.cpp @@ -46,6 +46,27 @@ void parseOptionString(const std::string &option_string, std::vector INCLUDE_OPTIONS = + { + { OPTION_INSTALLERS, "i", "Installers", "i|installers" }, + { OPTION_EXTRAS, "e", "Extras", "e|extras" }, + { OPTION_PATCHES, "p", "Patches", "p|patches" }, + { OPTION_LANGPACKS, "l", "Language packs", "l|languagepacks|langpacks" }, + { OPTION_COVERS, "c", "Covers", "c|cover|covers" }, + { OPTION_DLCS, "d", "DLCs", "d|dlc|dlcs" } + }; + Config config; config.sVersionString = VERSION_STRING; config.sVersionNumber = VERSION_NUMBER; @@ -89,6 +110,14 @@ 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 include and exclude options + std::string include_options_text; + for (unsigned int i = 0; i < INCLUDE_OPTIONS.size(); ++i) + { + include_options_text += INCLUDE_OPTIONS[i].str + " = " + INCLUDE_OPTIONS[i].regexp + "|" + std::to_string(INCLUDE_OPTIONS[i].id) + "\n"; + } + include_options_text += "Separate with \",\" to use multiple values"; + std::vector vFileIdStrings; std::vector unrecognized_options_cfg; std::vector unrecognized_options_cli; @@ -104,18 +133,14 @@ int main(int argc, char *argv[]) bool bNoColor = false; bool bNoUnicode = false; bool bNoDuplicateHandler = false; - bool bNoInstallers = false; - bool bNoExtras = false; - bool bNoPatches = false; - bool bNoLanguagePacks = false; - bool bNoDLC = false; bool bNoRemoteXML = false; bool bNoSubDirectories = false; - bool bNoCover = false; bool bNoPlatformDetection = false; bool bLogin = false; std::string sInstallerPlatform; std::string sInstallerLanguage; + std::string sIncludeOptions; + std::string sExcludeOptions; config.bReport = false; // Commandline options (no config file) options_cli_no_cfg.add_options() @@ -134,7 +159,6 @@ int main(int argc, char *argv[]) ("save-config", bpo::value(&config.bSaveConfig)->zero_tokens()->default_value(false), "Create config file with current settings") ("reset-config", bpo::value(&config.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default") ("report", bpo::value(&config.sReportFilePath)->implicit_value("lgogdownloader-report.log"), "Save report of downloaded/repaired files to specified file\nDefault filename: lgogdownloader-report.log") - ("no-cover", bpo::value(&bNoCover)->zero_tokens()->default_value(false), "Don't download cover images. Overrides --cover option.\nUseful for making exceptions when \"cover\" is set to true in config file.") ("update-cache", bpo::value(&config.bUpdateCache)->zero_tokens()->default_value(false), "Update game details cache") ("no-platform-detection", bpo::value(&bNoPlatformDetection)->zero_tokens()->default_value(false), "Don't try to detect supported platforms from game shelf.\nSkips the initial fast platform detection and detects the supported platforms from game details which is slower but more accurate.\nUseful in case platform identifier is missing for some games in the game shelf.\nUsing --platform with --list doesn't work with this option.") ("download-file", bpo::value(&config.sFileIdString)->default_value(""), "Download files using fileid\n\nFormat:\n\"gamename/fileid\"\nor: \"gogdownloader://gamename/fileid\"\n\nMultiple files:\n\"gamename1/fileid1,gamename2/fileid2\"\nor: \"gogdownloader://gamename1/fileid1,gamename2/fileid2\"\n\nThis option ignores all subdir options. The files are downloaded to directory specified with --directory option.") @@ -151,12 +175,6 @@ int main(int argc, char *argv[]) ("chunk-size", bpo::value(&config.iChunkSize)->default_value(10), "Chunk size (in MB) when creating XML") ("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") - ("no-language-packs", bpo::value(&bNoLanguagePacks)->zero_tokens()->default_value(false), "Don't download/list/repair language packs") - ("no-dlc", bpo::value(&bNoDLC)->zero_tokens()->default_value(false), "Don't download/list/repair DLCs") - ("cover", bpo::value(&config.bCover)->zero_tokens()->default_value(false), "Download cover images") ("no-remote-xml", bpo::value(&bNoRemoteXML)->zero_tokens()->default_value(false), "Don't use remote XML for repair") ("no-unicode", bpo::value(&bNoUnicode)->zero_tokens()->default_value(false), "Don't use Unicode in the progress bar") ("no-color", bpo::value(&bNoColor)->zero_tokens()->default_value(false), "Don't use coloring in the progress bar") @@ -178,6 +196,8 @@ int main(int argc, char *argv[]) ("cache-valid", bpo::value(&config.iCacheValid)->default_value(2880), ("Set how long cached game details are valid (in minutes)\nDefault: 2880 minutes (48 hours)")) ("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") + ("include", bpo::value(&sIncludeOptions)->default_value("all"), ("Select what to download/list/repair\n" + include_options_text).c_str()) + ("exclude", bpo::value(&sExcludeOptions)->default_value("covers"), ("Select what not to download/list/repair\n" + include_options_text).c_str()) ; // Options read from config file options_cfg_only.add_options() @@ -295,11 +315,6 @@ int main(int argc, char *argv[]) config.bColor = !bNoColor; config.bUnicode = !bNoUnicode; config.bDuplicateHandler = !bNoDuplicateHandler; - config.bInstallers = !bNoInstallers; - config.bExtras = !bNoExtras; - config.bPatches = !bNoPatches; - config.bLanguagePacks = !bNoLanguagePacks; - config.bDLC = !bNoDLC; config.bRemoteXML = !bNoRemoteXML; config.bSubDirectories = !bNoSubDirectories; config.bPlatformDetection = !bNoPlatformDetection; @@ -323,10 +338,6 @@ int main(int argc, char *argv[]) return 1; } - // Override cover option - if (bNoCover) - config.bCover = false; - if (bLogin) { config.bLoginAPI = true; @@ -335,6 +346,29 @@ int main(int argc, char *argv[]) parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES); parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS); + + unsigned int include_value = 0; + unsigned int exclude_value = 0; + std::vector vInclude = Util::tokenize(sIncludeOptions, ","); + std::vector vExclude = Util::tokenize(sExcludeOptions, ","); + for (std::vector::iterator it = vInclude.begin(); it != vInclude.end(); it++) + { + include_value |= Util::getOptionValue(*it, INCLUDE_OPTIONS); + } + for (std::vector::iterator it = vExclude.begin(); it != vExclude.end(); it++) + { + exclude_value |= Util::getOptionValue(*it, INCLUDE_OPTIONS); + } + config.iInclude = include_value & ~exclude_value; + + // Assign values + // TODO: Use config.iInclude in Downloader class directly and get rid of this value assignment + config.bCover = (config.iInclude & OPTION_COVERS); + config.bInstallers = (config.iInclude & OPTION_INSTALLERS); + config.bExtras = (config.iInclude & OPTION_EXTRAS); + config.bPatches = (config.iInclude & OPTION_PATCHES); + config.bLanguagePacks = (config.iInclude & OPTION_LANGPACKS); + config.bDLC = (config.iInclude & OPTION_DLCS); } catch (std::exception& e) {