From 49ca31467d1ee413fd91555b761a4b99cdede4b6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 05:51:47 -0400 Subject: UICommon/GameFile: Use in-class initializers where applicable Allows deduplicating code within the constructor initializer list. --- Source/Core/UICommon/GameFile.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index b990b744ca..95d22129f6 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -111,8 +111,7 @@ GameFile::LookupUsingConfigLanguage(const std::map Date: Tue, 28 May 2019 05:53:36 -0400 Subject: UICommon/GameFile: Default no-arg constructor and destructor within the cpp file A GameFile instance contains quite a lot of non-trivial types, so default construction and destruction in the same translation unit. --- Source/Core/UICommon/GameFile.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 95d22129f6..884d7f6b36 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -111,6 +111,8 @@ GameFile::LookupUsingConfigLanguage(const std::map Date: Tue, 28 May 2019 06:57:46 -0400 Subject: UICommon/GameFile: std::move std::string argument in constructor Allows for calling code to move the argument into the constructor, avoiding a copy. --- Source/Core/UICommon/GameFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 884d7f6b36..dc758ffac6 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -113,7 +113,7 @@ GameFile::LookupUsingConfigLanguage(const std::map Date: Tue, 28 May 2019 07:05:35 -0400 Subject: UICommon/GameFile: Deduplicate string paths where applicable Rather than construct strings twice, we can just construct it once and reuse it. While we're at it, we can move variables closer to where they're actually used within DownloadDefaultCover() --- Source/Core/UICommon/GameFile.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index dc758ffac6..328ba936d9 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -186,13 +186,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) @@ -207,17 +207,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: @@ -230,6 +226,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: @@ -253,18 +251,20 @@ void GameFile::DownloadDefaultCover() break; } break; + } case DiscIO::Region::Unknown: region_code = "EN"; break; } + Common::HttpRequest request; 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"); + png_path); } } -- cgit v1.2.3 From 80786cd295426244068718d6553c5cb59abcb81f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:12:59 -0400 Subject: UICommon/GameFile: Remove unnecessary value() calls in DownloadDefaultCover() We already check ahead of time if the optional contains a value within it before accessing it, so we don't need to use the throwing value() accessor. We can just directly use operator-> --- Source/Core/UICommon/GameFile.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 328ba936d9..6cd07e4136 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -258,14 +258,13 @@ void GameFile::DownloadDefaultCover() } Common::HttpRequest request; - auto response = + 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()), - png_path); - } + if (!response) + return; + + File::WriteStringToFile(std::string(response->begin(), response->end()), png_path); } bool GameFile::DefaultCoverChanged() -- cgit v1.2.3 From 8229ada9223d0fa03e3f26401ef5b43d5b0f89c0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:15:31 -0400 Subject: UICommon/GameFile: Remove unused includes Nothing within the source file makes use of anything in those includes, so they can be removed. --- Source/Core/UICommon/GameFile.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 6cd07e4136..87a390a1e1 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" -- cgit v1.2.3 From b4470ad4c215aad3765eb6acfc739548fdc53064 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:18:10 -0400 Subject: UICommon/GameFile: Make COVER_URL a plain C string Same behavior but doesn't take up 8 bytes in the executable to store a pointer. While we're at it, move it into an anonymous namespace within the UICommon namespace. --- Source/Core/UICommon/GameFile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Source/Core/UICommon/GameFile.cpp') diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 87a390a1e1..4e5ad6f9c2 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -39,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"; + +const std::string EMPTY_STRING; -static bool UseGameCovers() +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. @@ -55,6 +57,7 @@ static bool UseGameCovers() return Config::Get(Config::MAIN_USE_GAME_COVERS); #endif } +} // Anonymous namespace DiscIO::Language GameFile::GetConfigLanguage() const { -- cgit v1.2.3