diff --git a/include/util.h b/include/util.h index 865791d..d8d2813 100644 --- a/include/util.h +++ b/include/util.h @@ -47,6 +47,7 @@ namespace Util std::string getCacheHome(); std::vector tokenize(const std::string& str, const std::string& separator = ","); unsigned int getOptionValue(const std::string& str, const std::vector& options); + std::string getOptionNameString(const unsigned int& value, const std::vector& options); } #endif // UTIL_H diff --git a/src/downloader.cpp b/src/downloader.cpp index 0c49a19..7a44e1d 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -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 tags; diff --git a/src/util.cpp b/src/util.cpp index 0accd6e..fcfb93e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -460,3 +460,14 @@ unsigned int Util::getOptionValue(const std::string& str, const std::vector& 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; +}