Merge pull request #8129 from lioncash/gamefile

UICommon/GameFile: Minor cleanup
This commit is contained in:
JosJuice 2019-05-28 17:58:41 +02:00 committed by GitHub
commit 992c8bfc4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 43 deletions

View File

@ -22,7 +22,6 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/File.h" #include "Common/File.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/Hash.h"
#include "Common/HttpRequest.h" #include "Common/HttpRequest.h"
#include "Common/Image.h" #include "Common/Image.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
@ -30,7 +29,6 @@
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/Swap.h" #include "Common/Swap.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/UISettings.h" #include "Core/Config/UISettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
@ -41,13 +39,15 @@
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "DiscIO/WiiSaveBanner.h" #include "DiscIO/WiiSaveBanner.h"
constexpr const char* COVER_URL = "https://art.gametdb.com/wii/cover/%s/%s.png";
namespace UICommon 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. // 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. // 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); return Config::Get(Config::MAIN_USE_GAME_COVERS);
#endif #endif
} }
} // Anonymous namespace
DiscIO::Language GameFile::GetConfigLanguage() const DiscIO::Language GameFile::GetConfigLanguage() const
{ {
@ -111,8 +112,9 @@ GameFile::LookupUsingConfigLanguage(const std::map<DiscIO::Language, std::string
return Lookup(GetConfigLanguage(), strings); return Lookup(GetConfigLanguage(), strings);
} }
GameFile::GameFile(const std::string& path) GameFile::GameFile() = default;
: m_file_path(path), m_region(DiscIO::Region::Unknown), m_country(DiscIO::Country::Unknown)
GameFile::GameFile(std::string path) : m_file_path(std::move(path))
{ {
{ {
std::string name, extension; std::string name, extension;
@ -160,6 +162,8 @@ GameFile::GameFile(const std::string& path)
} }
} }
GameFile::~GameFile() = default;
bool GameFile::IsValid() const bool GameFile::IsValid() const
{ {
if (!m_valid) if (!m_valid)
@ -183,13 +187,13 @@ bool GameFile::CustomCoverChanged()
// This icon naming format is intended as an alternative to Homebrew Channel icons // 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. // for those who don't want to have a Homebrew Channel style folder structure.
bool success = File::Exists(path + name + ".cover.png") && const std::string cover_path = path + name + ".cover.png";
File::ReadFileToString(path + name + ".cover.png", contents); bool success = File::Exists(cover_path) && File::ReadFileToString(cover_path, contents);
if (!success) if (!success)
{ {
success = const std::string alt_cover_path = path + "cover.png";
File::Exists(path + "cover.png") && File::ReadFileToString(path + "cover.png", contents); success = File::Exists(alt_cover_path) && File::ReadFileToString(alt_cover_path, contents);
} }
if (success) if (success)
@ -204,17 +208,13 @@ void GameFile::DownloadDefaultCover()
return; return;
const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP; 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 the cover has already been downloaded, abort
if (File::Exists(cover_path + m_gametdb_id + ".png")) if (File::Exists(png_path))
return; return;
Common::HttpRequest request;
std::string region_code; std::string region_code;
auto user_lang = SConfig::GetInstance().GetCurrentLanguage(DiscIO::IsWii(GetPlatform()));
switch (m_region) switch (m_region)
{ {
case DiscIO::Region::NTSC_J: case DiscIO::Region::NTSC_J:
@ -227,6 +227,8 @@ void GameFile::DownloadDefaultCover()
region_code = "KO"; region_code = "KO";
break; break;
case DiscIO::Region::PAL: case DiscIO::Region::PAL:
{
const auto user_lang = SConfig::GetInstance().GetCurrentLanguage(DiscIO::IsWii(GetPlatform()));
switch (user_lang) switch (user_lang)
{ {
case DiscIO::Language::German: case DiscIO::Language::German:
@ -250,19 +252,20 @@ void GameFile::DownloadDefaultCover()
break; break;
} }
break; break;
}
case DiscIO::Region::Unknown: case DiscIO::Region::Unknown:
region_code = "EN"; region_code = "EN";
break; break;
} }
auto response = Common::HttpRequest request;
const auto response =
request.Get(StringFromFormat(COVER_URL, region_code.c_str(), m_gametdb_id.c_str())); request.Get(StringFromFormat(COVER_URL, region_code.c_str(), m_gametdb_id.c_str()));
if (response) if (!response)
{ return;
File::WriteStringToFile(std::string(response.value().begin(), response.value().end()),
cover_path + m_gametdb_id + ".png"); File::WriteStringToFile(std::string(response->begin(), response->end()), png_path);
}
} }
bool GameFile::DefaultCoverChanged() bool GameFile::DefaultCoverChanged()

View File

@ -23,7 +23,7 @@ namespace UICommon
{ {
struct GameBanner struct GameBanner
{ {
std::vector<u32> buffer{}; std::vector<u32> buffer;
u32 width{}; u32 width{};
u32 height{}; u32 height{};
bool empty() const { return buffer.empty(); } bool empty() const { return buffer.empty(); }
@ -32,7 +32,7 @@ struct GameBanner
struct GameCover struct GameCover
{ {
std::vector<u8> buffer{}; std::vector<u8> buffer;
bool empty() const { return buffer.empty(); } bool empty() const { return buffer.empty(); }
void DoState(PointerWrap& p); void DoState(PointerWrap& p);
}; };
@ -44,9 +44,9 @@ bool operator!=(const GameBanner& lhs, const GameBanner& rhs);
class GameFile final class GameFile final
{ {
public: public:
GameFile() = default; GameFile();
explicit GameFile(const std::string& path); explicit GameFile(std::string path);
~GameFile() = default; ~GameFile();
bool IsValid() const; bool IsValid() const;
const std::string& GetFilePath() const { return m_file_path; } const std::string& GetFilePath() const { return m_file_path; }
@ -109,30 +109,30 @@ private:
// CACHE_REVISION in GameFileCache.cpp is incremented. // CACHE_REVISION in GameFileCache.cpp is incremented.
bool m_valid{}; bool m_valid{};
std::string m_file_path{}; std::string m_file_path;
std::string m_file_name{}; std::string m_file_name;
u64 m_file_size{}; u64 m_file_size{};
u64 m_volume_size{}; u64 m_volume_size{};
std::map<DiscIO::Language, std::string> m_short_names{}; std::map<DiscIO::Language, std::string> m_short_names;
std::map<DiscIO::Language, std::string> m_long_names{}; std::map<DiscIO::Language, std::string> m_long_names;
std::map<DiscIO::Language, std::string> m_short_makers{}; std::map<DiscIO::Language, std::string> m_short_makers;
std::map<DiscIO::Language, std::string> m_long_makers{}; std::map<DiscIO::Language, std::string> m_long_makers;
std::map<DiscIO::Language, std::string> m_descriptions{}; std::map<DiscIO::Language, std::string> m_descriptions;
std::string m_internal_name{}; std::string m_internal_name;
std::string m_game_id{}; std::string m_game_id;
std::string m_gametdb_id{}; std::string m_gametdb_id;
u64 m_title_id{}; u64 m_title_id{};
std::string m_maker_id{}; std::string m_maker_id;
DiscIO::Region m_region{}; DiscIO::Region m_region{DiscIO::Region::Unknown};
DiscIO::Country m_country{}; DiscIO::Country m_country{DiscIO::Country::Unknown};
DiscIO::Platform m_platform{}; DiscIO::Platform m_platform{};
DiscIO::BlobType m_blob_type{}; DiscIO::BlobType m_blob_type{};
u16 m_revision{}; u16 m_revision{};
u8 m_disc_number{}; u8 m_disc_number{};
std::string m_apploader_date{}; std::string m_apploader_date;
GameBanner m_volume_banner{}; GameBanner m_volume_banner{};
GameBanner m_custom_banner{}; GameBanner m_custom_banner{};