mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Use same structure for language and platform structs
This commit is contained in:
parent
2473b6f24d
commit
a8e09a7f48
@ -12,6 +12,7 @@
|
||||
|
||||
namespace GlobalConstants
|
||||
{
|
||||
struct optionsStruct {const unsigned int id; const std::string code; const std::string str;};
|
||||
const std::string PROTOCOL_PREFIX = "gogdownloader://";
|
||||
|
||||
// Language constants
|
||||
@ -36,8 +37,7 @@ namespace GlobalConstants
|
||||
const unsigned int LANGUAGE_FI = 1 << 18;
|
||||
const unsigned int LANGUAGE_PT_BR = 1 << 19;
|
||||
|
||||
struct languageStruct {const unsigned int languageId; const std::string languageCode; const std::string languageString;};
|
||||
const std::vector<languageStruct> LANGUAGES =
|
||||
const std::vector<optionsStruct> LANGUAGES =
|
||||
{
|
||||
{ LANGUAGE_EN, "en", "English" },
|
||||
{ LANGUAGE_DE, "de", "German" },
|
||||
@ -66,8 +66,7 @@ namespace GlobalConstants
|
||||
const unsigned int PLATFORM_MAC = 1 << 1;
|
||||
const unsigned int PLATFORM_LINUX = 1 << 2;
|
||||
|
||||
struct platformStruct {const unsigned int platformId; const std::string platformCode; const std::string platformString;};
|
||||
const std::vector<platformStruct> PLATFORMS =
|
||||
const std::vector<optionsStruct> PLATFORMS =
|
||||
{
|
||||
{ PLATFORM_WINDOWS, "win", "Windows" },
|
||||
{ PLATFORM_MAC, "mac", "Mac" },
|
||||
|
12
main.cpp
12
main.cpp
@ -78,8 +78,8 @@ int main(int argc, char *argv[])
|
||||
unsigned int platform_sum = 0;
|
||||
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
|
||||
{
|
||||
platform_text += std::to_string(GlobalConstants::PLATFORMS[i].platformId) + " = " + GlobalConstants::PLATFORMS[i].platformString + "\n";
|
||||
platform_sum += GlobalConstants::LANGUAGES[i].languageId;
|
||||
platform_text += std::to_string(GlobalConstants::PLATFORMS[i].id) + " = " + GlobalConstants::PLATFORMS[i].str + "\n";
|
||||
platform_sum += GlobalConstants::LANGUAGES[i].id;
|
||||
}
|
||||
platform_text += std::to_string(platform_sum) + " = All";
|
||||
|
||||
@ -88,8 +88,8 @@ int main(int argc, char *argv[])
|
||||
unsigned int language_sum = 0;
|
||||
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
|
||||
{
|
||||
language_text += std::to_string(GlobalConstants::LANGUAGES[i].languageId) + " = " + GlobalConstants::LANGUAGES[i].languageString + "\n";
|
||||
language_sum += GlobalConstants::LANGUAGES[i].languageId;
|
||||
language_text += std::to_string(GlobalConstants::LANGUAGES[i].id) + " = " + GlobalConstants::LANGUAGES[i].str + "\n";
|
||||
language_sum += GlobalConstants::LANGUAGES[i].id;
|
||||
}
|
||||
language_text += "Add the values to download multiple languages\nAll = " + std::to_string(language_sum) + "\n"
|
||||
+ "French + Polish = " + std::to_string(GlobalConstants::LANGUAGE_FR) + "+" + std::to_string(GlobalConstants::LANGUAGE_PL) + " = " + std::to_string(GlobalConstants::LANGUAGE_FR | GlobalConstants::LANGUAGE_PL);
|
||||
@ -355,13 +355,13 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (config.iInstallerType < GlobalConstants::PLATFORMS[0].platformId || config.iInstallerType > platform_sum)
|
||||
if (config.iInstallerType < GlobalConstants::PLATFORMS[0].id || config.iInstallerType > platform_sum)
|
||||
{
|
||||
std::cout << "Invalid value for --platform" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (config.iInstallerLanguage < GlobalConstants::LANGUAGES[0].languageId || config.iInstallerLanguage > language_sum)
|
||||
if (config.iInstallerLanguage < GlobalConstants::LANGUAGES[0].id || config.iInstallerLanguage > language_sum)
|
||||
{
|
||||
std::cout << "Invalid value for --language" << std::endl;
|
||||
return 1;
|
||||
|
34
src/api.cpp
34
src/api.cpp
@ -305,19 +305,19 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
std::vector<gameFileInfo> installers;
|
||||
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
|
||||
{ // Check against the specified platforms
|
||||
if (type & GlobalConstants::PLATFORMS[i].platformId)
|
||||
if (type & GlobalConstants::PLATFORMS[i].id)
|
||||
{
|
||||
std::string installer = "installer_" + GlobalConstants::PLATFORMS[i].platformCode + "_";
|
||||
std::string installer = "installer_" + GlobalConstants::PLATFORMS[i].code + "_";
|
||||
for (unsigned int j = 0; j < GlobalConstants::LANGUAGES.size(); ++j)
|
||||
{ // Check against the specified languages
|
||||
if (lang & GlobalConstants::LANGUAGES[j].languageId)
|
||||
if (lang & GlobalConstants::LANGUAGES[j].id)
|
||||
{ // Make sure that the installer exists in the JSON
|
||||
if (root["game"].isMember(installer+GlobalConstants::LANGUAGES[j].languageCode))
|
||||
if (root["game"].isMember(installer+GlobalConstants::LANGUAGES[j].code))
|
||||
{
|
||||
gameFileInfo installerInfo;
|
||||
installerInfo.jsonNode = root["game"][installer+GlobalConstants::LANGUAGES[j].languageCode];
|
||||
installerInfo.platform = GlobalConstants::PLATFORMS[i].platformId;
|
||||
installerInfo.language = GlobalConstants::LANGUAGES[j].languageId;
|
||||
installerInfo.jsonNode = root["game"][installer+GlobalConstants::LANGUAGES[j].code];
|
||||
installerInfo.platform = GlobalConstants::PLATFORMS[i].id;
|
||||
installerInfo.language = GlobalConstants::LANGUAGES[j].id;
|
||||
installers.push_back(installerInfo);
|
||||
}
|
||||
}
|
||||
@ -383,10 +383,10 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
// Patch details
|
||||
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
|
||||
{ // Check against the specified languages
|
||||
if (lang & GlobalConstants::LANGUAGES[i].languageId)
|
||||
if (lang & GlobalConstants::LANGUAGES[i].id)
|
||||
{
|
||||
// Try to find a patch
|
||||
_regex_namespace_::regex re(GlobalConstants::LANGUAGES[i].languageCode + "\\d+patch\\d+", _regex_namespace_::regex_constants::icase); // regex for patch node names
|
||||
_regex_namespace_::regex re(GlobalConstants::LANGUAGES[i].code + "\\d+patch\\d+", _regex_namespace_::regex_constants::icase); // regex for patch node names
|
||||
std::vector<gameFileInfo> patches;
|
||||
for (unsigned int j = 0; j < membernames.size(); ++j)
|
||||
{
|
||||
@ -394,7 +394,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
{ // Regex matches, we have a patch node
|
||||
gameFileInfo patchInfo;
|
||||
patchInfo.jsonNode = root["game"][membernames[j]];
|
||||
patchInfo.language = GlobalConstants::LANGUAGES[i].languageId;
|
||||
patchInfo.language = GlobalConstants::LANGUAGES[i].id;
|
||||
if (patchInfo.jsonNode["link"].asString().find("/mac/") != std::string::npos)
|
||||
patchInfo.platform = GlobalConstants::PLATFORM_MAC;
|
||||
else if (patchInfo.jsonNode["link"].asString().find("/linux/") != std::string::npos)
|
||||
@ -426,7 +426,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
{
|
||||
if (game.patches[j].path == patch["link"].asString())
|
||||
{
|
||||
game.patches[j].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch
|
||||
game.patches[j].language |= GlobalConstants::LANGUAGES[i].id; // Add language code to patch
|
||||
bDuplicate = true;
|
||||
break;
|
||||
}
|
||||
@ -441,7 +441,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
patch["name"].asString(),
|
||||
patch["link"].asString(),
|
||||
patch["size"].asString(),
|
||||
GlobalConstants::LANGUAGES[i].languageId,
|
||||
GlobalConstants::LANGUAGES[i].id,
|
||||
patches[j].platform
|
||||
)
|
||||
);
|
||||
@ -457,7 +457,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
{
|
||||
if (game.patches[k].path == patchnode["link"].asString())
|
||||
{
|
||||
game.patches[k].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch
|
||||
game.patches[k].language |= GlobalConstants::LANGUAGES[i].id; // Add language code to patch
|
||||
bDuplicate = true;
|
||||
break;
|
||||
}
|
||||
@ -472,7 +472,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
patchnode["name"].asString(),
|
||||
patchnode["link"].asString(),
|
||||
patchnode["size"].asString(),
|
||||
GlobalConstants::LANGUAGES[i].languageId,
|
||||
GlobalConstants::LANGUAGES[i].id,
|
||||
patches[j].platform
|
||||
)
|
||||
);
|
||||
@ -485,10 +485,10 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
// Language pack details
|
||||
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
|
||||
{ // Check against the specified languages
|
||||
if (lang & GlobalConstants::LANGUAGES[i].languageId)
|
||||
if (lang & GlobalConstants::LANGUAGES[i].id)
|
||||
{
|
||||
// Try to find a language pack
|
||||
_regex_namespace_::regex re(GlobalConstants::LANGUAGES[i].languageCode + "\\d+langpack\\d+", _regex_namespace_::regex_constants::icase); // regex for language pack node names
|
||||
_regex_namespace_::regex re(GlobalConstants::LANGUAGES[i].code + "\\d+langpack\\d+", _regex_namespace_::regex_constants::icase); // regex for language pack node names
|
||||
std::vector<std::string> langpacknames;
|
||||
for (unsigned int j = 0; j < membernames.size(); ++j)
|
||||
{
|
||||
@ -507,7 +507,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
|
||||
langpack["name"].asString(),
|
||||
langpack["link"].asString(),
|
||||
langpack["size"].asString(),
|
||||
GlobalConstants::LANGUAGES[i].languageId
|
||||
GlobalConstants::LANGUAGES[i].id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -408,8 +408,8 @@ void Downloader::listGames()
|
||||
std::string languages;
|
||||
for (unsigned int k = 0; k < GlobalConstants::LANGUAGES.size(); k++) // Check which languages the installer supports
|
||||
{
|
||||
if (games[i].installers[j].language & GlobalConstants::LANGUAGES[k].languageId)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].languageString;
|
||||
if (games[i].installers[j].language & GlobalConstants::LANGUAGES[k].id)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].str;
|
||||
}
|
||||
|
||||
std::cout << "\tid: " << games[i].installers[j].id << std::endl
|
||||
@ -460,8 +460,8 @@ void Downloader::listGames()
|
||||
std::string languages;
|
||||
for (unsigned int k = 0; k < GlobalConstants::LANGUAGES.size(); k++) // Check which languages the patch supports
|
||||
{
|
||||
if (games[i].patches[j].language & GlobalConstants::LANGUAGES[k].languageId)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].languageString;
|
||||
if (games[i].patches[j].language & GlobalConstants::LANGUAGES[k].id)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].str;
|
||||
}
|
||||
|
||||
std::cout << "\tid: " << games[i].patches[j].id << std::endl
|
||||
@ -2448,7 +2448,7 @@ void Downloader::checkOrphans()
|
||||
platformIds.push_back(0);
|
||||
for (unsigned int j = 0; j < GlobalConstants::PLATFORMS.size(); ++j)
|
||||
{
|
||||
platformIds.push_back(GlobalConstants::PLATFORMS[j].platformId);
|
||||
platformIds.push_back(GlobalConstants::PLATFORMS[j].id);
|
||||
}
|
||||
for (unsigned int j = 0; j < platformIds.size(); ++j)
|
||||
{
|
||||
@ -3106,9 +3106,9 @@ void Downloader::updateCache()
|
||||
unsigned int all_platforms = GlobalConstants::PLATFORM_WINDOWS;
|
||||
unsigned int all_languages = GlobalConstants::LANGUAGE_EN;
|
||||
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
|
||||
all_platforms |= GlobalConstants::PLATFORMS[i].platformId;
|
||||
all_platforms |= GlobalConstants::PLATFORMS[i].id;
|
||||
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
|
||||
all_languages |= GlobalConstants::LANGUAGES[i].languageId;
|
||||
all_languages |= GlobalConstants::LANGUAGES[i].id;
|
||||
|
||||
config.bExtras = true;
|
||||
config.bInstallers = true;
|
||||
@ -3271,9 +3271,9 @@ void Downloader::showWishlist()
|
||||
|
||||
for (unsigned int j = 0; j < GlobalConstants::PLATFORMS.size(); ++j)
|
||||
{
|
||||
if (GlobalConstants::PLATFORMS[j].platformId & platform)
|
||||
if (GlobalConstants::PLATFORMS[j].id & platform)
|
||||
{
|
||||
platforms_text += (platforms_text.empty() ? "" : ", ")+GlobalConstants::PLATFORMS[j].platformString;
|
||||
platforms_text += (platforms_text.empty() ? "" : ", ")+GlobalConstants::PLATFORMS[j].str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,9 +287,9 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g
|
||||
std::string platform;
|
||||
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
|
||||
{
|
||||
if ((platformId & GlobalConstants::PLATFORMS[i].platformId) == GlobalConstants::PLATFORMS[i].platformId)
|
||||
if ((platformId & GlobalConstants::PLATFORMS[i].id) == GlobalConstants::PLATFORMS[i].id)
|
||||
{
|
||||
platform = boost::algorithm::to_lower_copy(GlobalConstants::PLATFORMS[i].platformString);
|
||||
platform = boost::algorithm::to_lower_copy(GlobalConstants::PLATFORMS[i].str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user