diff options
| author | JosJuice <josjuice@gmail.com> | 2019-05-28 17:58:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-28 17:58:41 +0200 |
| commit | 992c8bfc4e2394ad5786f5116f5e62ae595b5c44 (patch) | |
| tree | 43415ba19091b1e099cce61e59b7dbdaeb819c8d /Source/Core/UICommon/GameFile.cpp | |
| parent | 800d875faaa830c6e267f647f6a3221f463a6b78 (diff) | |
| parent | b4470ad4c215aad3765eb6acfc739548fdc53064 (diff) | |
Merge pull request #8129 from lioncash/gamefile
UICommon/GameFile: Minor cleanup
Diffstat (limited to 'Source/Core/UICommon/GameFile.cpp')
| -rw-r--r-- | Source/Core/UICommon/GameFile.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index b990b744ca..4e5ad6f9c2 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -22,7 +22,6 @@ #include "Common/CommonTypes.h" #include "Common/File.h" #include "Common/FileUtil.h" -#include "Common/Hash.h" #include "Common/HttpRequest.h" #include "Common/Image.h" #include "Common/IniFile.h" @@ -30,7 +29,6 @@ #include "Common/StringUtil.h" #include "Common/Swap.h" -#include "Core/Boot/Boot.h" #include "Core/Config/UISettings.h" #include "Core/ConfigManager.h" #include "Core/IOS/ES/Formats.h" @@ -41,13 +39,15 @@ #include "DiscIO/Volume.h" #include "DiscIO/WiiSaveBanner.h" -constexpr const char* COVER_URL = "https://art.gametdb.com/wii/cover/%s/%s.png"; - namespace UICommon { -static const std::string EMPTY_STRING; +namespace +{ +constexpr char COVER_URL[] = "https://art.gametdb.com/wii/cover/%s/%s.png"; -static bool UseGameCovers() +const std::string EMPTY_STRING; + +bool UseGameCovers() { // We ifdef this out on Android because accessing the config before emulation start makes us crash. // The Android GUI handles covers in Java anyway, so this doesn't make us lose any functionality. @@ -57,6 +57,7 @@ static bool UseGameCovers() return Config::Get(Config::MAIN_USE_GAME_COVERS); #endif } +} // Anonymous namespace DiscIO::Language GameFile::GetConfigLanguage() const { @@ -111,8 +112,9 @@ GameFile::LookupUsingConfigLanguage(const std::map<DiscIO::Language, std::string return Lookup(GetConfigLanguage(), strings); } -GameFile::GameFile(const std::string& path) - : m_file_path(path), m_region(DiscIO::Region::Unknown), m_country(DiscIO::Country::Unknown) +GameFile::GameFile() = default; + +GameFile::GameFile(std::string path) : m_file_path(std::move(path)) { { std::string name, extension; @@ -160,6 +162,8 @@ GameFile::GameFile(const std::string& path) } } +GameFile::~GameFile() = default; + bool GameFile::IsValid() const { if (!m_valid) @@ -183,13 +187,13 @@ bool GameFile::CustomCoverChanged() // This icon naming format is intended as an alternative to Homebrew Channel icons // for those who don't want to have a Homebrew Channel style folder structure. - bool success = File::Exists(path + name + ".cover.png") && - File::ReadFileToString(path + name + ".cover.png", contents); + const std::string cover_path = path + name + ".cover.png"; + bool success = File::Exists(cover_path) && File::ReadFileToString(cover_path, contents); if (!success) { - success = - File::Exists(path + "cover.png") && File::ReadFileToString(path + "cover.png", contents); + const std::string alt_cover_path = path + "cover.png"; + success = File::Exists(alt_cover_path) && File::ReadFileToString(alt_cover_path, contents); } if (success) @@ -204,17 +208,13 @@ void GameFile::DownloadDefaultCover() return; const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP; + const auto png_path = cover_path + m_gametdb_id + ".png"; // If the cover has already been downloaded, abort - if (File::Exists(cover_path + m_gametdb_id + ".png")) + if (File::Exists(png_path)) return; - Common::HttpRequest request; - std::string region_code; - - auto user_lang = SConfig::GetInstance().GetCurrentLanguage(DiscIO::IsWii(GetPlatform())); - switch (m_region) { case DiscIO::Region::NTSC_J: @@ -227,6 +227,8 @@ void GameFile::DownloadDefaultCover() region_code = "KO"; break; case DiscIO::Region::PAL: + { + const auto user_lang = SConfig::GetInstance().GetCurrentLanguage(DiscIO::IsWii(GetPlatform())); switch (user_lang) { case DiscIO::Language::German: @@ -250,19 +252,20 @@ void GameFile::DownloadDefaultCover() break; } break; + } case DiscIO::Region::Unknown: region_code = "EN"; break; } - auto response = + Common::HttpRequest request; + const auto response = request.Get(StringFromFormat(COVER_URL, region_code.c_str(), m_gametdb_id.c_str())); - if (response) - { - File::WriteStringToFile(std::string(response.value().begin(), response.value().end()), - cover_path + m_gametdb_id + ".png"); - } + if (!response) + return; + + File::WriteStringToFile(std::string(response->begin(), response->end()), png_path); } bool GameFile::DefaultCoverChanged() |
