Skip to content
Permalink
Browse files

Merge pull request #8129 from lioncash/gamefile

UICommon/GameFile: Minor cleanup
  • Loading branch information...
JosJuice committed May 28, 2019
2 parents 800d875 + b4470ad commit 992c8bfc4e2394ad5786f5116f5e62ae595b5c44
Showing with 46 additions and 43 deletions.
  1. +27 −24 Source/Core/UICommon/GameFile.cpp
  2. +19 −19 Source/Core/UICommon/GameFile.h
@@ -22,15 +22,13 @@
#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"
#include "Common/NandPaths.h"
#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()
@@ -23,7 +23,7 @@ namespace UICommon
{
struct GameBanner
{
std::vector<u32> buffer{};
std::vector<u32> buffer;
u32 width{};
u32 height{};
bool empty() const { return buffer.empty(); }
@@ -32,7 +32,7 @@ struct GameBanner

struct GameCover
{
std::vector<u8> buffer{};
std::vector<u8> buffer;
bool empty() const { return buffer.empty(); }
void DoState(PointerWrap& p);
};
@@ -44,9 +44,9 @@ bool operator!=(const GameBanner& lhs, const GameBanner& rhs);
class GameFile final
{
public:
GameFile() = default;
explicit GameFile(const std::string& path);
~GameFile() = default;
GameFile();
explicit GameFile(std::string path);
~GameFile();

bool IsValid() const;
const std::string& GetFilePath() const { return m_file_path; }
@@ -109,30 +109,30 @@ class GameFile final
// 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<DiscIO::Language, std::string> m_short_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_long_makers{};
std::map<DiscIO::Language, std::string> m_descriptions{};
std::string m_internal_name{};
std::string m_game_id{};
std::string m_gametdb_id{};
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_short_makers;
std::map<DiscIO::Language, std::string> m_long_makers;
std::map<DiscIO::Language, std::string> 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::Country m_country{};
DiscIO::Region m_region{DiscIO::Region::Unknown};
DiscIO::Country m_country{DiscIO::Country::Unknown};
DiscIO::Platform m_platform{};
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{};

0 comments on commit 992c8bf

Please sign in to comment.
You can’t perform that action at this time.