2017-12-31 19:33:36 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "UICommon/GameFile.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iterator>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2018-03-10 21:41:49 +00:00
|
|
|
#include <tuple>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/CommonPaths.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
2018-06-09 20:15:14 +00:00
|
|
|
#include "Common/File.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2018-07-30 01:16:37 +00:00
|
|
|
#include "Common/HttpRequest.h"
|
2018-03-10 21:41:49 +00:00
|
|
|
#include "Common/Image.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/NandPaths.h"
|
|
|
|
#include "Common/StringUtil.h"
|
2018-03-10 21:41:49 +00:00
|
|
|
#include "Common/Swap.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2018-07-30 01:16:37 +00:00
|
|
|
#include "Core/Config/UISettings.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/IOS/ES/Formats.h"
|
|
|
|
#include "Core/TitleDatabase.h"
|
|
|
|
|
|
|
|
#include "DiscIO/Blob.h"
|
|
|
|
#include "DiscIO/Enums.h"
|
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
#include "DiscIO/WiiSaveBanner.h"
|
|
|
|
|
|
|
|
namespace UICommon
|
|
|
|
{
|
2019-05-28 11:18:10 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr char COVER_URL[] = "https://art.gametdb.com/wii/cover/%s/%s.png";
|
|
|
|
|
|
|
|
const std::string EMPTY_STRING;
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2019-05-28 11:18:10 +00:00
|
|
|
bool UseGameCovers()
|
2018-07-30 15:40:59 +00:00
|
|
|
{
|
|
|
|
// We ifdef this out on Android because accessing the config before emulation start makes us crash.
|
2019-02-23 18:18:16 +00:00
|
|
|
// The Android GUI handles covers in Java anyway, so this doesn't make us lose any functionality.
|
2018-07-30 15:40:59 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return Config::Get(Config::MAIN_USE_GAME_COVERS);
|
|
|
|
#endif
|
|
|
|
}
|
2019-05-28 11:18:10 +00:00
|
|
|
} // Anonymous namespace
|
2018-07-30 15:40:59 +00:00
|
|
|
|
2019-02-23 18:18:16 +00:00
|
|
|
DiscIO::Language GameFile::GetConfigLanguage() const
|
|
|
|
{
|
|
|
|
#ifdef ANDROID
|
|
|
|
// TODO: Make the Android app load the config at app start instead of emulation start
|
|
|
|
// so that we can access the user's preference here
|
|
|
|
return DiscIO::Language::English;
|
|
|
|
#else
|
2019-06-30 09:48:49 +00:00
|
|
|
return SConfig::GetInstance().GetLanguageAdjustedForRegion(DiscIO::IsWii(m_platform), m_region);
|
2019-02-23 18:18:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
bool operator==(const GameBanner& lhs, const GameBanner& rhs)
|
|
|
|
{
|
|
|
|
return std::tie(lhs.buffer, lhs.width, lhs.height) == std::tie(rhs.buffer, rhs.width, rhs.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const GameBanner& lhs, const GameBanner& rhs)
|
|
|
|
{
|
|
|
|
return !operator==(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
const std::string& GameFile::Lookup(DiscIO::Language language,
|
|
|
|
const std::map<DiscIO::Language, std::string>& strings)
|
|
|
|
{
|
|
|
|
auto end = strings.end();
|
|
|
|
auto it = strings.find(language);
|
|
|
|
if (it != end)
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
// English tends to be a good fallback when the requested language isn't available
|
2018-03-31 12:04:13 +00:00
|
|
|
if (language != DiscIO::Language::English)
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
2018-03-31 12:04:13 +00:00
|
|
|
it = strings.find(DiscIO::Language::English);
|
2017-12-31 19:33:36 +00:00
|
|
|
if (it != end)
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If English isn't available either, just pick something
|
|
|
|
if (!strings.empty())
|
|
|
|
return strings.cbegin()->second;
|
|
|
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string&
|
|
|
|
GameFile::LookupUsingConfigLanguage(const std::map<DiscIO::Language, std::string>& strings) const
|
|
|
|
{
|
2019-02-23 18:18:16 +00:00
|
|
|
return Lookup(GetConfigLanguage(), strings);
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 09:53:36 +00:00
|
|
|
GameFile::GameFile() = default;
|
|
|
|
|
2019-05-28 10:57:46 +00:00
|
|
|
GameFile::GameFile(std::string path) : m_file_path(std::move(path))
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string name, extension;
|
|
|
|
SplitPath(m_file_path, nullptr, &name, &extension);
|
|
|
|
m_file_name = name + extension;
|
|
|
|
|
2019-07-14 13:49:42 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolume(m_file_path));
|
2017-12-31 19:33:36 +00:00
|
|
|
if (volume != nullptr)
|
|
|
|
{
|
|
|
|
m_platform = volume->GetVolumeType();
|
|
|
|
|
|
|
|
m_short_names = volume->GetShortNames();
|
|
|
|
m_long_names = volume->GetLongNames();
|
|
|
|
m_short_makers = volume->GetShortMakers();
|
|
|
|
m_long_makers = volume->GetLongMakers();
|
|
|
|
m_descriptions = volume->GetDescriptions();
|
|
|
|
|
|
|
|
m_region = volume->GetRegion();
|
|
|
|
m_country = volume->GetCountry();
|
|
|
|
m_blob_type = volume->GetBlobType();
|
|
|
|
m_file_size = volume->GetRawSize();
|
|
|
|
m_volume_size = volume->GetSize();
|
|
|
|
|
|
|
|
m_internal_name = volume->GetInternalName();
|
|
|
|
m_game_id = volume->GetGameID();
|
2019-02-23 16:49:06 +00:00
|
|
|
m_gametdb_id = volume->GetGameTDBID();
|
2017-12-31 19:33:36 +00:00
|
|
|
m_title_id = volume->GetTitleID().value_or(0);
|
|
|
|
m_maker_id = volume->GetMakerID();
|
|
|
|
m_revision = volume->GetRevision().value_or(0);
|
|
|
|
m_disc_number = volume->GetDiscNumber().value_or(0);
|
|
|
|
m_apploader_date = volume->GetApploaderDate();
|
|
|
|
|
|
|
|
m_volume_banner.buffer = volume->GetBanner(&m_volume_banner.width, &m_volume_banner.height);
|
|
|
|
|
|
|
|
m_valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsValid() && IsElfOrDol())
|
|
|
|
{
|
|
|
|
m_valid = true;
|
2019-02-23 15:17:39 +00:00
|
|
|
m_file_size = m_volume_size = File::GetSize(m_file_path);
|
2018-03-31 12:04:13 +00:00
|
|
|
m_platform = DiscIO::Platform::ELFOrDOL;
|
2017-12-31 19:33:36 +00:00
|
|
|
m_blob_type = DiscIO::BlobType::DIRECTORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 09:53:36 +00:00
|
|
|
GameFile::~GameFile() = default;
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
bool GameFile::IsValid() const
|
|
|
|
{
|
|
|
|
if (!m_valid)
|
|
|
|
return false;
|
|
|
|
|
2018-03-31 12:04:13 +00:00
|
|
|
if (m_platform == DiscIO::Platform::WiiWAD && !IOS::ES::IsChannel(m_title_id))
|
2017-12-31 19:33:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-30 01:16:37 +00:00
|
|
|
bool GameFile::CustomCoverChanged()
|
|
|
|
{
|
2018-07-30 15:40:59 +00:00
|
|
|
if (!m_custom_cover.buffer.empty() || !UseGameCovers())
|
2018-07-30 01:16:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string path, name;
|
|
|
|
SplitPath(m_file_path, &path, &name, nullptr);
|
|
|
|
|
|
|
|
std::string contents;
|
|
|
|
|
|
|
|
// 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.
|
2019-05-28 11:05:35 +00:00
|
|
|
const std::string cover_path = path + name + ".cover.png";
|
|
|
|
bool success = File::Exists(cover_path) && File::ReadFileToString(cover_path, contents);
|
2018-07-30 01:16:37 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
2019-05-28 11:05:35 +00:00
|
|
|
const std::string alt_cover_path = path + "cover.png";
|
|
|
|
success = File::Exists(alt_cover_path) && File::ReadFileToString(alt_cover_path, contents);
|
2018-07-30 01:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
m_pending.custom_cover.buffer = {contents.begin(), contents.end()};
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameFile::DownloadDefaultCover()
|
|
|
|
{
|
2018-07-30 15:40:59 +00:00
|
|
|
if (!m_default_cover.buffer.empty() || !UseGameCovers())
|
2018-07-30 01:16:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP;
|
2019-05-28 11:05:35 +00:00
|
|
|
const auto png_path = cover_path + m_gametdb_id + ".png";
|
2018-07-30 01:16:37 +00:00
|
|
|
|
2019-02-23 16:49:06 +00:00
|
|
|
// If the cover has already been downloaded, abort
|
2019-05-28 11:05:35 +00:00
|
|
|
if (File::Exists(png_path))
|
2018-07-30 01:16:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::string region_code;
|
|
|
|
switch (m_region)
|
|
|
|
{
|
|
|
|
case DiscIO::Region::NTSC_J:
|
|
|
|
region_code = "JA";
|
|
|
|
break;
|
|
|
|
case DiscIO::Region::NTSC_U:
|
|
|
|
region_code = "US";
|
|
|
|
break;
|
|
|
|
case DiscIO::Region::NTSC_K:
|
|
|
|
region_code = "KO";
|
|
|
|
break;
|
|
|
|
case DiscIO::Region::PAL:
|
2019-05-28 11:05:35 +00:00
|
|
|
{
|
|
|
|
const auto user_lang = SConfig::GetInstance().GetCurrentLanguage(DiscIO::IsWii(GetPlatform()));
|
2018-07-30 01:16:37 +00:00
|
|
|
switch (user_lang)
|
|
|
|
{
|
|
|
|
case DiscIO::Language::German:
|
|
|
|
region_code = "DE";
|
|
|
|
break;
|
|
|
|
case DiscIO::Language::French:
|
|
|
|
region_code = "FR";
|
|
|
|
break;
|
|
|
|
case DiscIO::Language::Spanish:
|
|
|
|
region_code = "ES";
|
|
|
|
break;
|
|
|
|
case DiscIO::Language::Italian:
|
|
|
|
region_code = "IT";
|
|
|
|
break;
|
|
|
|
case DiscIO::Language::Dutch:
|
|
|
|
region_code = "NL";
|
|
|
|
break;
|
|
|
|
case DiscIO::Language::English:
|
|
|
|
default:
|
|
|
|
region_code = "EN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-05-28 11:05:35 +00:00
|
|
|
}
|
2018-07-30 01:16:37 +00:00
|
|
|
case DiscIO::Region::Unknown:
|
|
|
|
region_code = "EN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-28 11:05:35 +00:00
|
|
|
Common::HttpRequest request;
|
2019-05-28 11:12:59 +00:00
|
|
|
const auto response =
|
2019-02-23 16:49:06 +00:00
|
|
|
request.Get(StringFromFormat(COVER_URL, region_code.c_str(), m_gametdb_id.c_str()));
|
2018-07-30 01:16:37 +00:00
|
|
|
|
2019-05-28 11:12:59 +00:00
|
|
|
if (!response)
|
|
|
|
return;
|
|
|
|
|
2019-05-28 21:45:36 +00:00
|
|
|
File::WriteStringToFile(png_path, std::string(response->begin(), response->end()));
|
2018-07-30 01:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GameFile::DefaultCoverChanged()
|
|
|
|
{
|
2018-07-30 15:40:59 +00:00
|
|
|
if (!m_default_cover.buffer.empty() || !UseGameCovers())
|
2018-07-30 01:16:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto cover_path = File::GetUserPath(D_COVERCACHE_IDX) + DIR_SEP;
|
|
|
|
|
|
|
|
std::string contents;
|
|
|
|
|
2019-02-23 16:49:06 +00:00
|
|
|
File::ReadFileToString(cover_path + m_gametdb_id + ".png", contents);
|
2018-07-30 01:16:37 +00:00
|
|
|
|
|
|
|
if (contents.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_pending.default_cover.buffer = {contents.begin(), contents.end()};
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameFile::CustomCoverCommit()
|
|
|
|
{
|
|
|
|
m_custom_cover = std::move(m_pending.custom_cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameFile::DefaultCoverCommit()
|
|
|
|
{
|
|
|
|
m_default_cover = std::move(m_pending.default_cover);
|
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
void GameBanner::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
p.Do(buffer);
|
|
|
|
p.Do(width);
|
|
|
|
p.Do(height);
|
|
|
|
}
|
|
|
|
|
2018-07-30 01:16:37 +00:00
|
|
|
void GameCover::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
p.Do(buffer);
|
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
void GameFile::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
p.Do(m_valid);
|
|
|
|
p.Do(m_file_path);
|
|
|
|
p.Do(m_file_name);
|
|
|
|
|
|
|
|
p.Do(m_file_size);
|
|
|
|
p.Do(m_volume_size);
|
|
|
|
|
|
|
|
p.Do(m_short_names);
|
|
|
|
p.Do(m_long_names);
|
|
|
|
p.Do(m_short_makers);
|
|
|
|
p.Do(m_long_makers);
|
|
|
|
p.Do(m_descriptions);
|
|
|
|
p.Do(m_internal_name);
|
|
|
|
p.Do(m_game_id);
|
2019-02-23 16:49:06 +00:00
|
|
|
p.Do(m_gametdb_id);
|
2017-12-31 19:33:36 +00:00
|
|
|
p.Do(m_title_id);
|
|
|
|
p.Do(m_maker_id);
|
|
|
|
|
|
|
|
p.Do(m_region);
|
|
|
|
p.Do(m_country);
|
|
|
|
p.Do(m_platform);
|
|
|
|
p.Do(m_blob_type);
|
|
|
|
p.Do(m_revision);
|
|
|
|
p.Do(m_disc_number);
|
|
|
|
p.Do(m_apploader_date);
|
|
|
|
|
|
|
|
m_volume_banner.DoState(p);
|
2018-03-10 21:41:49 +00:00
|
|
|
m_custom_banner.DoState(p);
|
2018-07-30 01:16:37 +00:00
|
|
|
m_default_cover.DoState(p);
|
|
|
|
m_custom_cover.DoState(p);
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GameFile::IsElfOrDol() const
|
|
|
|
{
|
|
|
|
if (m_file_path.size() < 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string name_end = m_file_path.substr(m_file_path.size() - 4);
|
|
|
|
std::transform(name_end.begin(), name_end.end(), name_end.begin(), ::tolower);
|
|
|
|
return name_end == ".elf" || name_end == ".dol";
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
bool GameFile::WiiBannerChanged()
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
// Wii banners can only be read if there is a save file.
|
|
|
|
// In case the cache was created without a save file existing,
|
|
|
|
// let's try reading the save file again, because it might exist now.
|
|
|
|
|
|
|
|
if (!m_volume_banner.empty())
|
|
|
|
return false;
|
|
|
|
if (!DiscIO::IsWii(m_platform))
|
|
|
|
return false;
|
|
|
|
|
2018-03-30 10:01:55 +00:00
|
|
|
m_pending.volume_banner.buffer =
|
|
|
|
DiscIO::WiiSaveBanner(m_title_id)
|
|
|
|
.GetBanner(&m_pending.volume_banner.width, &m_pending.volume_banner.height);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2018-03-31 12:52:21 +00:00
|
|
|
// We only reach here if the old banner was empty, so if the new banner isn't empty,
|
|
|
|
// the new banner is guaranteed to be different from the old banner
|
|
|
|
return !m_pending.volume_banner.buffer.empty();
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
void GameFile::WiiBannerCommit()
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
m_volume_banner = std::move(m_pending.volume_banner);
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
bool GameFile::ReadPNGBanner(const std::string& path)
|
|
|
|
{
|
|
|
|
File::IOFile file(path, "rb");
|
|
|
|
if (!file)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<u8> png_data(file.GetSize());
|
|
|
|
if (!file.ReadBytes(png_data.data(), png_data.size()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
GameBanner& banner = m_pending.custom_banner;
|
|
|
|
std::vector<u8> data_out;
|
|
|
|
if (!Common::LoadPNG(png_data, &data_out, &banner.width, &banner.height))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Make an ARGB copy of the RGBA data
|
|
|
|
banner.buffer.resize(data_out.size() / sizeof(u32));
|
|
|
|
for (size_t i = 0; i < banner.buffer.size(); i++)
|
|
|
|
{
|
|
|
|
const size_t j = i * sizeof(u32);
|
|
|
|
banner.buffer[i] = (Common::swap32(data_out.data() + j) >> 8) + (data_out[j] << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GameFile::CustomBannerChanged()
|
|
|
|
{
|
|
|
|
std::string path, name;
|
|
|
|
SplitPath(m_file_path, &path, &name, nullptr);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (!ReadPNGBanner(path + name + ".png"))
|
|
|
|
{
|
|
|
|
// Homebrew Channel icon naming. Typical for DOLs and ELFs, but we also support it for volumes.
|
|
|
|
if (!ReadPNGBanner(path + "icon.png"))
|
|
|
|
{
|
|
|
|
// If no custom icon is found, go back to the non-custom one.
|
|
|
|
m_pending.custom_banner = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_pending.custom_banner != m_custom_banner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameFile::CustomBannerCommit()
|
|
|
|
{
|
|
|
|
m_custom_banner = std::move(m_pending.custom_banner);
|
|
|
|
}
|
|
|
|
|
2018-06-03 10:07:53 +00:00
|
|
|
const std::string& GameFile::GetName(const Core::TitleDatabase& title_database) const
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
2019-02-23 18:18:16 +00:00
|
|
|
const std::string& custom_name = title_database.GetTitleName(m_gametdb_id, GetConfigLanguage());
|
2018-06-03 10:07:53 +00:00
|
|
|
return custom_name.empty() ? GetName() : custom_name;
|
|
|
|
}
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2018-06-03 10:07:53 +00:00
|
|
|
const std::string& GameFile::GetName(bool long_name) const
|
|
|
|
{
|
2017-12-31 19:33:36 +00:00
|
|
|
const std::string& name = long_name ? GetLongName() : GetShortName();
|
|
|
|
if (!name.empty())
|
|
|
|
return name;
|
|
|
|
|
|
|
|
// No usable name, return filename (better than nothing)
|
|
|
|
return m_file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& GameFile::GetMaker(bool long_maker) const
|
|
|
|
{
|
|
|
|
const std::string& maker = long_maker ? GetLongMaker() : GetShortMaker();
|
|
|
|
if (!maker.empty())
|
|
|
|
return maker;
|
|
|
|
|
|
|
|
if (m_game_id.size() >= 6)
|
|
|
|
return DiscIO::GetCompanyFromID(m_maker_id);
|
|
|
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DiscIO::Language> GameFile::GetLanguages() const
|
|
|
|
{
|
|
|
|
std::vector<DiscIO::Language> languages;
|
|
|
|
// TODO: What if some languages don't have long names but have other strings?
|
2018-06-19 16:25:13 +00:00
|
|
|
for (const auto& name : m_long_names)
|
2017-12-31 19:33:36 +00:00
|
|
|
languages.push_back(name.first);
|
|
|
|
return languages;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameFile::GetUniqueIdentifier() const
|
|
|
|
{
|
|
|
|
std::vector<std::string> info;
|
|
|
|
if (!GetGameID().empty())
|
|
|
|
info.push_back(GetGameID());
|
|
|
|
if (GetRevision() != 0)
|
|
|
|
info.push_back("Revision " + std::to_string(GetRevision()));
|
|
|
|
|
2019-04-20 10:38:40 +00:00
|
|
|
std::string name = GetLongName(DiscIO::Language::English);
|
|
|
|
if (name.empty())
|
|
|
|
{
|
|
|
|
// Use the file name as a fallback. Not necessarily consistent, but it's the best we have
|
|
|
|
name = m_file_name;
|
|
|
|
}
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
int disc_number = GetDiscNumber() + 1;
|
|
|
|
|
|
|
|
std::string lower_name = name;
|
|
|
|
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
|
|
|
|
if (disc_number > 1 &&
|
|
|
|
lower_name.find(StringFromFormat("disc %i", disc_number)) == std::string::npos &&
|
|
|
|
lower_name.find(StringFromFormat("disc%i", disc_number)) == std::string::npos)
|
|
|
|
{
|
|
|
|
std::string disc_text = "Disc ";
|
|
|
|
info.push_back(disc_text + std::to_string(disc_number));
|
|
|
|
}
|
|
|
|
if (info.empty())
|
|
|
|
return name;
|
|
|
|
std::ostringstream ss;
|
|
|
|
std::copy(info.begin(), info.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
|
|
|
|
ss << info.back();
|
|
|
|
return name + " (" + ss.str() + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameFile::GetWiiFSPath() const
|
|
|
|
{
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(DiscIO::IsWii(m_platform));
|
2017-12-31 19:33:36 +00:00
|
|
|
return Common::GetTitleDataPath(m_title_id, Common::FROM_CONFIGURED_ROOT);
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
const GameBanner& GameFile::GetBannerImage() const
|
|
|
|
{
|
|
|
|
return m_custom_banner.empty() ? m_volume_banner : m_custom_banner;
|
|
|
|
}
|
|
|
|
|
2018-07-30 01:16:37 +00:00
|
|
|
const GameCover& GameFile::GetCoverImage() const
|
|
|
|
{
|
|
|
|
return m_custom_cover.empty() ? m_default_cover : m_custom_cover;
|
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
} // namespace UICommon
|