Skip to content
Permalink
Browse files

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()
  • Loading branch information...
lioncash committed May 28, 2019
1 parent 27ecb93 commit ab0892e5a59cd415e8e714d18a785d0047617d3a
Showing with 11 additions and 11 deletions.
  1. +11 −11 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);
}
}

0 comments on commit ab0892e

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