mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Use regular expressions for getting language and platform option values
Selecting languages with --language and --language-priority - Whatever code GOG happens to use in their API (mostly ISO 639-1) - ISO 639-1 - ISO 639-2/T - ISO 639-2/B - English name Selecting platforms with --platform and --platform-priority - Windows: "w, win, windows" - Linux: "l, lin, linux" - Mac: "m, mac, osx"
This commit is contained in:
parent
2206e988a6
commit
b4fd9fcf5c
@ -12,7 +12,7 @@
|
||||
|
||||
namespace GlobalConstants
|
||||
{
|
||||
struct optionsStruct {const unsigned int id; const std::string code; const std::string str;};
|
||||
struct optionsStruct {const unsigned int id; const std::string code; const std::string str; const std::string regexp;};
|
||||
const std::string PROTOCOL_PREFIX = "gogdownloader://";
|
||||
|
||||
// Language constants
|
||||
@ -39,26 +39,26 @@ namespace GlobalConstants
|
||||
|
||||
const std::vector<optionsStruct> LANGUAGES =
|
||||
{
|
||||
{ LANGUAGE_EN, "en", "English" },
|
||||
{ LANGUAGE_DE, "de", "German" },
|
||||
{ LANGUAGE_FR, "fr", "French" },
|
||||
{ LANGUAGE_PL, "pl", "Polish" },
|
||||
{ LANGUAGE_RU, "ru", "Russian" },
|
||||
{ LANGUAGE_CN, "cn", "Chinese" },
|
||||
{ LANGUAGE_CZ, "cz", "Czech" },
|
||||
{ LANGUAGE_ES, "es", "Spanish" },
|
||||
{ LANGUAGE_HU, "hu", "Hungarian" },
|
||||
{ LANGUAGE_IT, "it", "Italian" },
|
||||
{ LANGUAGE_JP, "jp", "Japanese" },
|
||||
{ LANGUAGE_TR, "tr", "Turkish" },
|
||||
{ LANGUAGE_PT, "pt", "Portuguese"},
|
||||
{ LANGUAGE_KO, "ko", "Korean" },
|
||||
{ LANGUAGE_NL, "nl", "Dutch" },
|
||||
{ LANGUAGE_SV, "sv", "Swedish" },
|
||||
{ LANGUAGE_NO, "no", "Norwegian" },
|
||||
{ LANGUAGE_DA, "da", "Danish" },
|
||||
{ LANGUAGE_FI, "fi", "Finnish" },
|
||||
{ LANGUAGE_PT_BR, "br", "Brazilian Portuguese" }
|
||||
{ LANGUAGE_EN, "en", "English" , "en|eng|english" },
|
||||
{ LANGUAGE_DE, "de", "German" , "de|deu|ger|german" },
|
||||
{ LANGUAGE_FR, "fr", "French" , "fr|fra|fre|french" },
|
||||
{ LANGUAGE_PL, "pl", "Polish" , "pl|pol|polish" },
|
||||
{ LANGUAGE_RU, "ru", "Russian" , "ru|rus|russian" },
|
||||
{ LANGUAGE_CN, "cn", "Chinese" , "cn|zh|zho|chi|chinese" },
|
||||
{ LANGUAGE_CZ, "cz", "Czech" , "cz|cs|ces|cze|czech" },
|
||||
{ LANGUAGE_ES, "es", "Spanish" , "es|spa|spanish" },
|
||||
{ LANGUAGE_HU, "hu", "Hungarian" , "hu|hun|hungarian" },
|
||||
{ LANGUAGE_IT, "it", "Italian" , "it|ita|italian" },
|
||||
{ LANGUAGE_JP, "jp", "Japanese" , "jp|ja|jpn|japanese" },
|
||||
{ LANGUAGE_TR, "tr", "Turkish" , "tr|tur|turkish" },
|
||||
{ LANGUAGE_PT, "pt", "Portuguese", "pt|por|portuguese" },
|
||||
{ LANGUAGE_KO, "ko", "Korean" , "ko|kor|korean" },
|
||||
{ LANGUAGE_NL, "nl", "Dutch" , "nl|nld|dut|dutch" },
|
||||
{ LANGUAGE_SV, "sv", "Swedish" , "sv|swe|swedish" },
|
||||
{ LANGUAGE_NO, "no", "Norwegian" , "no|nor|norwegian" },
|
||||
{ LANGUAGE_DA, "da", "Danish" , "da|dan|danish" },
|
||||
{ LANGUAGE_FI, "fi", "Finnish" , "fi|fin|finnish" },
|
||||
{ LANGUAGE_PT_BR, "br", "Brazilian Portuguese", "br|pt_br|pt-br|ptbr|brazilian_portuguese" }
|
||||
};
|
||||
|
||||
// Platform constants
|
||||
@ -68,9 +68,9 @@ namespace GlobalConstants
|
||||
|
||||
const std::vector<optionsStruct> PLATFORMS =
|
||||
{
|
||||
{ PLATFORM_WINDOWS, "win", "Windows" },
|
||||
{ PLATFORM_MAC, "mac", "Mac" },
|
||||
{ PLATFORM_LINUX, "linux", "Linux" }
|
||||
{ PLATFORM_WINDOWS, "win", "Windows" , "w|win|windows" },
|
||||
{ PLATFORM_MAC, "mac", "Mac" , "m|mac|osx" },
|
||||
{ PLATFORM_LINUX, "linux", "Linux" , "l|lin|linux" }
|
||||
};
|
||||
};
|
||||
|
||||
|
14
main.cpp
14
main.cpp
@ -86,19 +86,19 @@ int main(int argc, char *argv[])
|
||||
unsigned int platform_all = Util::getOptionValue("all", GlobalConstants::PLATFORMS);
|
||||
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
|
||||
{
|
||||
platform_text += std::to_string(GlobalConstants::PLATFORMS[i].id) + " = " + GlobalConstants::PLATFORMS[i].str + "\n";
|
||||
platform_text += GlobalConstants::PLATFORMS[i].str + " = " + GlobalConstants::PLATFORMS[i].regexp + "|" + std::to_string(GlobalConstants::PLATFORMS[i].id) + "\n";
|
||||
}
|
||||
platform_text += std::to_string(platform_all) + " = All";
|
||||
platform_text += "All = all|" + std::to_string(platform_all);
|
||||
|
||||
// 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);
|
||||
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
|
||||
{
|
||||
language_text += std::to_string(GlobalConstants::LANGUAGES[i].id) + " = " + GlobalConstants::LANGUAGES[i].str + "\n";
|
||||
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 = " + std::to_string(language_all) + "\n"
|
||||
+ "French + Polish = " + std::to_string(GlobalConstants::LANGUAGE_FR) + "+" + std::to_string(GlobalConstants::LANGUAGE_PL) + " = " + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL);
|
||||
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) + ")";
|
||||
|
||||
// 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)
|
||||
@ -195,8 +195,8 @@ int main(int argc, char *argv[])
|
||||
("subdir-game", bpo::value<std::string>(&config.sGameSubdir)->default_value("%gamename%"), ("Set subdirectory for game" + subdir_help_text).c_str())
|
||||
("use-cache", bpo::value<bool>(&config.bUseCache)->zero_tokens()->default_value(false), ("Use game details cache"))
|
||||
("cache-valid", bpo::value<int>(&config.iCacheValid)->default_value(2880), ("Set how long cached game details are valid (in minutes)\nDefault: 2880 minutes (48 hours)"))
|
||||
("language-priority", bpo::value<std::string>(&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<std::string>(&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())
|
||||
("language-priority", bpo::value<std::string>(&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<std::string>(&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<bool>(&config.bSaveSerials)->zero_tokens()->default_value(false), "Save serial numbers when downloading")
|
||||
("ignore-dlc-count", bpo::value<std::string>(&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")
|
||||
;
|
||||
|
11
src/util.cpp
11
src/util.cpp
@ -442,7 +442,16 @@ unsigned int Util::getOptionValue(const std::string& str, const std::vector<Glob
|
||||
{
|
||||
for (unsigned int i = 0; i < options.size(); ++i)
|
||||
{
|
||||
if (str == options[i].code)
|
||||
if (!options[i].regexp.empty())
|
||||
{
|
||||
boost::regex expr("^(" + options[i].regexp + ")$", boost::regex::perl | boost::regex::icase);
|
||||
if (boost::regex_search(str, what, expr))
|
||||
{
|
||||
value = options[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (str == options[i].code)
|
||||
{
|
||||
value = options[i].id;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user