mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Add Util::getOptionNameString to reduce some duplicate code
This commit is contained in:
parent
ba27e4fbcc
commit
d648d3a073
@ -47,6 +47,7 @@ namespace Util
|
||||
std::string getCacheHome();
|
||||
std::vector<std::string> tokenize(const std::string& str, const std::string& separator = ",");
|
||||
unsigned int getOptionValue(const std::string& str, const std::vector<GlobalConstants::optionsStruct>& options);
|
||||
std::string getOptionNameString(const unsigned int& value, const std::vector<GlobalConstants::optionsStruct>& options);
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
@ -409,12 +409,7 @@ void Downloader::listGames()
|
||||
continue;
|
||||
}
|
||||
|
||||
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].id)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].str;
|
||||
}
|
||||
std::string languages = Util::getOptionNameString(games[i].installers[j].language, GlobalConstants::LANGUAGES);
|
||||
|
||||
std::cout << "\tid: " << games[i].installers[j].id << std::endl
|
||||
<< "\tname: " << games[i].installers[j].name << std::endl
|
||||
@ -461,12 +456,7 @@ void Downloader::listGames()
|
||||
continue;
|
||||
}
|
||||
|
||||
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].id)
|
||||
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].str;
|
||||
}
|
||||
std::string languages = Util::getOptionNameString(games[i].patches[j].language, GlobalConstants::LANGUAGES);
|
||||
|
||||
std::cout << "\tid: " << games[i].patches[j].id << std::endl
|
||||
<< "\tname: " << games[i].patches[j].name << std::endl
|
||||
@ -3268,13 +3258,7 @@ void Downloader::showWishlist()
|
||||
if (config.bPlatformDetection && !(platform & config.iInstallerPlatform))
|
||||
continue;
|
||||
|
||||
for (unsigned int j = 0; j < GlobalConstants::PLATFORMS.size(); ++j)
|
||||
{
|
||||
if (GlobalConstants::PLATFORMS[j].id & platform)
|
||||
{
|
||||
platforms_text += (platforms_text.empty() ? "" : ", ")+GlobalConstants::PLATFORMS[j].str;
|
||||
}
|
||||
}
|
||||
platforms_text = Util::getOptionNameString(platform, GlobalConstants::PLATFORMS);
|
||||
}
|
||||
|
||||
std::vector<std::string> tags;
|
||||
|
11
src/util.cpp
11
src/util.cpp
@ -460,3 +460,14 @@ unsigned int Util::getOptionValue(const std::string& str, const std::vector<Glob
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string Util::getOptionNameString(const unsigned int& value, const std::vector<GlobalConstants::optionsStruct>& options)
|
||||
{
|
||||
std::string str;
|
||||
for (unsigned int i = 0; i < options.size(); ++i)
|
||||
{
|
||||
if (value & options[i].id)
|
||||
str += (str.empty() ? "" : ", ")+options[i].str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user