From 49ca31467d1ee413fd91555b761a4b99cdede4b6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 05:51:47 -0400 Subject: [PATCH 1/8] UICommon/GameFile: Use in-class initializers where applicable Allows deduplicating code within the constructor initializer list. --- Source/Core/UICommon/GameFile.cpp | 3 +-- Source/Core/UICommon/GameFile.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) 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: [PATCH 2/8] 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 ++++ Source/Core/UICommon/GameFile.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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: [PATCH 3/8] 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 +- Source/Core/UICommon/GameFile.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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:00:04 -0400 Subject: [PATCH 4/8] UICommon/GameFile: Remove unnecessary initializers All of the standardized types have constructors that will automatically initialize them, so the explicit initializers are redundant. --- Source/Core/UICommon/GameFile.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/Core/UICommon/GameFile.h b/Source/Core/UICommon/GameFile.h index 13086c5c33..aced331685 100644 --- a/Source/Core/UICommon/GameFile.h +++ b/Source/Core/UICommon/GameFile.h @@ -23,7 +23,7 @@ namespace UICommon { struct GameBanner { - std::vector buffer{}; + std::vector buffer; u32 width{}; u32 height{}; bool empty() const { return buffer.empty(); } @@ -32,7 +32,7 @@ struct GameBanner struct GameCover { - std::vector buffer{}; + std::vector buffer; bool empty() const { return buffer.empty(); } void DoState(PointerWrap& p); }; @@ -109,22 +109,22 @@ private: // CACHE_REVISION in GameFileCache.cpp is incremented. bool m_valid{}; - std::string m_file_path{}; - std::string m_file_name{}; + std::string m_file_path; + std::string m_file_name; u64 m_file_size{}; u64 m_volume_size{}; - std::map m_short_names{}; - std::map m_long_names{}; - std::map m_short_makers{}; - std::map m_long_makers{}; - std::map m_descriptions{}; - std::string m_internal_name{}; - std::string m_game_id{}; - std::string m_gametdb_id{}; + std::map m_short_names; + std::map m_long_names; + std::map m_short_makers; + std::map m_long_makers; + std::map m_descriptions; + std::string m_internal_name; + std::string m_game_id; + std::string m_gametdb_id; u64 m_title_id{}; - std::string m_maker_id{}; + std::string m_maker_id; DiscIO::Region m_region{DiscIO::Region::Unknown}; DiscIO::Country m_country{DiscIO::Country::Unknown}; @@ -132,7 +132,7 @@ private: DiscIO::BlobType m_blob_type{}; u16 m_revision{}; u8 m_disc_number{}; - std::string m_apploader_date{}; + std::string m_apploader_date; GameBanner m_volume_banner{}; GameBanner m_custom_banner{}; From ab0892e5a59cd415e8e714d18a785d0047617d3a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:05:35 -0400 Subject: [PATCH 5/8] 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(-) 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); } } From 80786cd295426244068718d6553c5cb59abcb81f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:12:59 -0400 Subject: [PATCH 6/8] 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(-) 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() From 8229ada9223d0fa03e3f26401ef5b43d5b0f89c0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:15:31 -0400 Subject: [PATCH 7/8] 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(-) 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" From b4470ad4c215aad3765eb6acfc739548fdc53064 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 07:18:10 -0400 Subject: [PATCH 8/8] 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(-) 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"; -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. @@ -55,6 +57,7 @@ static bool UseGameCovers() return Config::Get(Config::MAIN_USE_GAME_COVERS); #endif } +} // Anonymous namespace DiscIO::Language GameFile::GetConfigLanguage() const {