2017-12-31 19:33:36 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
#include "UICommon/GameFile.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2020-06-07 20:58:03 +00:00
|
|
|
#include <array>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iterator>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2020-06-07 20:58:03 +00:00
|
|
|
#include <string_view>
|
2018-03-10 21:41:49 +00:00
|
|
|
#include <tuple>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-11-24 00:15:52 +00:00
|
|
|
#include <fmt/format.h>
|
2019-08-13 16:01:27 +00:00
|
|
|
#include <pugixml.hpp>
|
|
|
|
|
2021-11-13 20:15:45 +00:00
|
|
|
#include "Common/BitUtils.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/CommonPaths.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
2022-07-24 05:45:10 +00:00
|
|
|
#include "Common/Crypto/SHA1.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"
|
2020-09-15 10:29:41 +00:00
|
|
|
#include "Common/IOFile.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"
|
2020-10-06 11:00:58 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#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"
|
2020-04-11 11:06:45 +00:00
|
|
|
#include "DiscIO/DiscExtractor.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2021-10-26 00:01:16 +00:00
|
|
|
#include "DiscIO/GameModDescriptor.h"
|
2017-12-31 19:33:36 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
#include "DiscIO/WiiSaveBanner.h"
|
|
|
|
|
|
|
|
namespace UICommon
|
|
|
|
{
|
2019-05-28 11:18:10 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
const std::string EMPTY_STRING;
|
2020-10-11 17:32:27 +00:00
|
|
|
|
|
|
|
bool UseGameCovers()
|
|
|
|
{
|
|
|
|
#ifdef ANDROID
|
|
|
|
// Android has its own code for handling covers, written completely in Java.
|
|
|
|
// It's best if we disable the C++ cover code on Android to avoid duplicated data and such.
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-03-16 20:03:21 +00:00
|
|
|
m_file_name = PathToFileName(m_file_path);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2020-03-16 20:03:21 +00:00
|
|
|
{
|
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();
|
2020-06-21 18:41:50 +00:00
|
|
|
m_block_size = volume->GetBlobReader().GetBlockSize();
|
|
|
|
m_compression_method = volume->GetBlobReader().GetCompressionMethod();
|
2017-12-31 19:33:36 +00:00
|
|
|
m_file_size = volume->GetRawSize();
|
2022-08-01 09:53:30 +00:00
|
|
|
m_volume_size = volume->GetDataSize();
|
|
|
|
m_volume_size_type = volume->GetDataSizeType();
|
2020-07-04 12:51:13 +00:00
|
|
|
m_is_datel_disc = volume->IsDatelDisc();
|
2020-10-06 11:00:58 +00:00
|
|
|
m_is_nkit = volume->IsNKit();
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
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);
|
2024-04-11 23:35:18 +00:00
|
|
|
m_is_two_disc_game = CheckIfTwoDiscGame(m_game_id);
|
2017-12-31 19:33:36 +00:00
|
|
|
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);
|
2021-01-21 15:47:07 +00:00
|
|
|
m_game_id = SConfig::MakeGameID(m_file_name);
|
2022-08-01 09:53:30 +00:00
|
|
|
m_volume_size_type = DiscIO::DataSizeType::Accurate;
|
2020-04-11 11:06:45 +00:00
|
|
|
m_is_datel_disc = false;
|
2020-10-06 11:00:58 +00:00
|
|
|
m_is_nkit = false;
|
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;
|
|
|
|
}
|
2021-10-26 00:01:16 +00:00
|
|
|
|
|
|
|
if (!IsValid() && GetExtension() == ".json")
|
|
|
|
{
|
|
|
|
auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path);
|
|
|
|
if (descriptor)
|
|
|
|
{
|
|
|
|
GameFile proxy(descriptor->base_file);
|
|
|
|
if (proxy.IsValid())
|
|
|
|
{
|
|
|
|
m_valid = true;
|
|
|
|
m_file_size = File::GetSize(m_file_path);
|
|
|
|
m_long_names.emplace(DiscIO::Language::English, std::move(descriptor->display_name));
|
2022-01-02 05:06:53 +00:00
|
|
|
if (!descriptor->maker.empty())
|
|
|
|
m_long_makers.emplace(DiscIO::Language::English, std::move(descriptor->maker));
|
2021-10-26 00:01:16 +00:00
|
|
|
m_internal_name = proxy.GetInternalName();
|
|
|
|
m_game_id = proxy.GetGameID();
|
|
|
|
m_gametdb_id = proxy.GetGameTDBID();
|
|
|
|
m_title_id = proxy.GetTitleID();
|
|
|
|
m_maker_id = proxy.GetMakerID();
|
|
|
|
m_region = proxy.GetRegion();
|
|
|
|
m_country = proxy.GetCountry();
|
|
|
|
m_platform = proxy.GetPlatform();
|
|
|
|
m_revision = proxy.GetRevision();
|
|
|
|
m_disc_number = proxy.GetDiscNumber();
|
|
|
|
m_blob_type = DiscIO::BlobType::MOD_DESCRIPTOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2020-10-11 17:32:27 +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()
|
|
|
|
{
|
2021-07-11 16:13:54 +00:00
|
|
|
if (!m_default_cover.buffer.empty() || !UseGameCovers() || m_gametdb_id.empty())
|
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;
|
|
|
|
|
2023-04-12 02:08:14 +00:00
|
|
|
const std::string region_code =
|
|
|
|
SConfig::GetInstance().GetGameTDBImageRegionCode(DiscIO::IsWii(GetPlatform()), m_region);
|
2018-07-30 01:16:37 +00:00
|
|
|
|
2019-05-28 11:05:35 +00:00
|
|
|
Common::HttpRequest request;
|
2022-06-11 13:39:04 +00:00
|
|
|
static constexpr char cover_url[] = "https://art.gametdb.com/wii/cover/{}/{}.png";
|
2019-11-24 00:15:52 +00:00
|
|
|
const auto response = request.Get(fmt::format(cover_url, region_code, m_gametdb_id));
|
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()
|
|
|
|
{
|
2020-10-11 17:32:27 +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);
|
2022-08-01 09:53:30 +00:00
|
|
|
p.Do(m_volume_size_type);
|
2020-04-11 11:06:45 +00:00
|
|
|
p.Do(m_is_datel_disc);
|
2020-10-06 11:00:58 +00:00
|
|
|
p.Do(m_is_nkit);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
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);
|
2020-06-21 18:41:50 +00:00
|
|
|
p.Do(m_block_size);
|
|
|
|
p.Do(m_compression_method);
|
2017-12-31 19:33:36 +00:00
|
|
|
p.Do(m_revision);
|
|
|
|
p.Do(m_disc_number);
|
2024-04-11 23:35:18 +00:00
|
|
|
p.Do(m_is_two_disc_game);
|
2017-12-31 19:33:36 +00:00
|
|
|
p.Do(m_apploader_date);
|
|
|
|
|
2019-08-13 16:01:27 +00:00
|
|
|
p.Do(m_custom_name);
|
|
|
|
p.Do(m_custom_description);
|
|
|
|
p.Do(m_custom_maker);
|
2017-12-31 19:33:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-19 19:18:42 +00:00
|
|
|
std::string GameFile::GetExtension() const
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
2020-07-19 19:18:42 +00:00
|
|
|
std::string extension;
|
|
|
|
SplitPath(m_file_path, nullptr, nullptr, &extension);
|
2022-01-13 20:06:02 +00:00
|
|
|
Common::ToLower(&extension);
|
2020-07-19 19:18:42 +00:00
|
|
|
return extension;
|
|
|
|
}
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2020-07-19 19:18:42 +00:00
|
|
|
bool GameFile::IsElfOrDol() const
|
|
|
|
{
|
|
|
|
const std::string extension = GetExtension();
|
|
|
|
return extension == ".elf" || extension == ".dol";
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-13 16:01:27 +00:00
|
|
|
bool GameFile::ReadXMLMetadata(const std::string& path)
|
|
|
|
{
|
|
|
|
std::string data;
|
|
|
|
if (!File::ReadFileToString(path, data))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
// We use load_buffer instead of load_file to avoid path encoding problems on Windows
|
|
|
|
if (!doc.load_buffer(data.data(), data.size()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const pugi::xml_node app_node = doc.child("app");
|
|
|
|
m_pending.custom_name = app_node.child("name").text().as_string();
|
|
|
|
m_pending.custom_maker = app_node.child("coder").text().as_string();
|
|
|
|
m_pending.custom_description = app_node.child("short_description").text().as_string();
|
|
|
|
|
|
|
|
// Elements that we aren't using:
|
|
|
|
// version (can be written in any format)
|
|
|
|
// release_date (YYYYmmddHHMMSS format)
|
|
|
|
// long_description (can be several screens long!)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GameFile::XMLMetadataChanged()
|
|
|
|
{
|
|
|
|
std::string path, name;
|
|
|
|
SplitPath(m_file_path, &path, &name, nullptr);
|
|
|
|
|
|
|
|
// This XML file naming format is intended as an alternative to the Homebrew Channel naming
|
|
|
|
// for those who don't want to have a Homebrew Channel style folder structure.
|
|
|
|
if (!ReadXMLMetadata(path + name + ".xml"))
|
|
|
|
{
|
|
|
|
// Homebrew Channel naming. Typical for DOLs and ELFs, but we also support it for volumes.
|
|
|
|
if (!ReadXMLMetadata(path + "meta.xml"))
|
|
|
|
{
|
|
|
|
// If no XML metadata is found, remove any old XML metadata from memory.
|
|
|
|
m_pending.custom_banner = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_pending.custom_name != m_custom_name && m_pending.custom_maker != m_custom_maker &&
|
|
|
|
m_pending.custom_description != m_custom_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameFile::XMLMetadataCommit()
|
|
|
|
{
|
|
|
|
m_custom_name = std::move(m_pending.custom_name);
|
|
|
|
m_custom_description = std::move(m_pending.custom_description);
|
|
|
|
m_custom_maker = std::move(m_pending.custom_maker);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-10-26 00:01:16 +00:00
|
|
|
bool GameFile::TryLoadGameModDescriptorBanner()
|
|
|
|
{
|
|
|
|
if (m_blob_type != DiscIO::BlobType::MOD_DESCRIPTOR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path);
|
|
|
|
if (!descriptor)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ReadPNGBanner(descriptor->banner);
|
|
|
|
}
|
|
|
|
|
2018-03-10 21:41:49 +00:00
|
|
|
bool GameFile::CustomBannerChanged()
|
|
|
|
{
|
|
|
|
std::string path, name;
|
|
|
|
SplitPath(m_file_path, &path, &name, nullptr);
|
|
|
|
|
2019-08-13 16:01:27 +00:00
|
|
|
// This icon naming format is intended as an alternative to the Homebrew Channel naming
|
2018-03-10 21:41:49 +00:00
|
|
|
// 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"))
|
|
|
|
{
|
2021-10-26 00:01:16 +00:00
|
|
|
// If it's a game mod descriptor file, it may specify its own custom banner.
|
|
|
|
if (!TryLoadGameModDescriptorBanner())
|
|
|
|
{
|
|
|
|
// If no custom icon is found, go back to the non-custom one.
|
|
|
|
m_pending.custom_banner = {};
|
|
|
|
}
|
2018-03-10 21:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-13 16:01:27 +00:00
|
|
|
if (!m_custom_name.empty())
|
|
|
|
return m_custom_name;
|
2021-10-26 00:01:16 +00:00
|
|
|
if (IsModDescriptor())
|
|
|
|
return GetName(Variant::LongAndPossiblyCustom);
|
2019-08-13 16:01:27 +00:00
|
|
|
|
|
|
|
const std::string& database_name = title_database.GetTitleName(m_gametdb_id, GetConfigLanguage());
|
2019-09-25 09:36:45 +00:00
|
|
|
return database_name.empty() ? GetName(Variant::LongAndPossiblyCustom) : database_name;
|
2018-06-03 10:07:53 +00:00
|
|
|
}
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2019-09-25 09:36:45 +00:00
|
|
|
const std::string& GameFile::GetName(Variant variant) const
|
2018-06-03 10:07:53 +00:00
|
|
|
{
|
2019-09-25 09:36:45 +00:00
|
|
|
if (variant == Variant::LongAndPossiblyCustom && !m_custom_name.empty())
|
2019-08-13 16:01:27 +00:00
|
|
|
return m_custom_name;
|
|
|
|
|
2019-09-25 09:36:45 +00:00
|
|
|
const std::string& name = variant == Variant::ShortAndNotCustom ? GetShortName() : GetLongName();
|
2017-12-31 19:33:36 +00:00
|
|
|
if (!name.empty())
|
|
|
|
return name;
|
|
|
|
|
|
|
|
// No usable name, return filename (better than nothing)
|
|
|
|
return m_file_name;
|
|
|
|
}
|
|
|
|
|
2019-09-25 09:36:45 +00:00
|
|
|
const std::string& GameFile::GetMaker(Variant variant) const
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
2019-09-25 09:36:45 +00:00
|
|
|
if (variant == Variant::LongAndPossiblyCustom && !m_custom_maker.empty())
|
2019-08-13 16:01:27 +00:00
|
|
|
return m_custom_maker;
|
|
|
|
|
2019-09-25 09:36:45 +00:00
|
|
|
const std::string& maker =
|
|
|
|
variant == Variant::ShortAndNotCustom ? GetShortMaker() : GetLongMaker();
|
2017-12-31 19:33:36 +00:00
|
|
|
if (!maker.empty())
|
|
|
|
return maker;
|
|
|
|
|
|
|
|
if (m_game_id.size() >= 6)
|
|
|
|
return DiscIO::GetCompanyFromID(m_maker_id);
|
|
|
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
|
|
|
|
2019-09-25 09:36:45 +00:00
|
|
|
const std::string& GameFile::GetDescription(Variant variant) const
|
2019-08-13 16:01:27 +00:00
|
|
|
{
|
2019-09-25 09:36:45 +00:00
|
|
|
if (variant == Variant::LongAndPossiblyCustom && !m_custom_description.empty())
|
2019-08-13 16:01:27 +00:00
|
|
|
return m_custom_description;
|
|
|
|
|
|
|
|
return LookupUsingConfigLanguage(m_descriptions);
|
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-04-11 23:35:18 +00:00
|
|
|
bool GameFile::CheckIfTwoDiscGame(const std::string& game_id) const
|
|
|
|
{
|
|
|
|
constexpr size_t GAME_ID_PREFIX_SIZE = 3;
|
|
|
|
if (game_id.size() < GAME_ID_PREFIX_SIZE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
static constexpr std::array<std::string_view, 30> two_disc_game_id_prefixes = {
|
|
|
|
// Resident Evil
|
|
|
|
"DBJ",
|
|
|
|
// The Lord of the Rings: The Third Age
|
|
|
|
"G3A",
|
|
|
|
// Teenage Mutant Ninja Turtles 3: Mutant Nightmare
|
|
|
|
"G3Q",
|
|
|
|
// Resident Evil 4
|
|
|
|
"G4B",
|
|
|
|
// Tiger Woods PGA Tour 2005
|
|
|
|
"G5T",
|
|
|
|
// Resident Evil
|
|
|
|
"GBI",
|
|
|
|
// Resident Evil Zero
|
|
|
|
"GBZ",
|
|
|
|
// Conan
|
|
|
|
"GC9",
|
|
|
|
// Resident Evil Code: Veronica X
|
|
|
|
"GCD",
|
|
|
|
// Tom Clancy's Splinter Cell: Chaos Theory
|
|
|
|
"GCJ",
|
|
|
|
// Freaky Flyers
|
|
|
|
"GFF",
|
|
|
|
// GoldenEye: Rogue Agent
|
|
|
|
"GGI",
|
|
|
|
// Metal Gear Solid: The Twin Snakes
|
|
|
|
"GGS",
|
|
|
|
// Baten Kaitos Origins
|
|
|
|
"GK4",
|
|
|
|
// Killer7
|
|
|
|
"GK7",
|
|
|
|
// Baten Kaitos: Eternal Wings and the Lost Ocean
|
|
|
|
"GKB",
|
|
|
|
// Lupin the 3rd: Lost Treasure by the Sea
|
|
|
|
"GL3",
|
|
|
|
// Enter the Matrix
|
|
|
|
"GMX",
|
|
|
|
// Teenage Mutant Ninja Turtles 2: Battle Nexus
|
|
|
|
"GNI",
|
|
|
|
// GoldenEye: Rogue Agent
|
|
|
|
"GOY",
|
|
|
|
// Tales of Symphonia
|
|
|
|
"GQS",
|
|
|
|
// Medal of Honor: Rising Sun
|
|
|
|
"GR8",
|
|
|
|
"GRZ",
|
|
|
|
// Tales of Symphonia
|
|
|
|
"GTO",
|
|
|
|
// Tiger Woods PGA Tour 2004
|
|
|
|
"GW4",
|
|
|
|
// Tom Clancy's Splinter Cell: Double Agent (GC)
|
|
|
|
"GWY",
|
|
|
|
// Dragon Quest X: Mezameshi Itsutsu no Shuzoku Online
|
|
|
|
"S4M",
|
|
|
|
"S4S",
|
|
|
|
"S6T",
|
|
|
|
"SDQ",
|
|
|
|
};
|
2024-09-29 05:23:45 +00:00
|
|
|
static_assert(std::ranges::is_sorted(two_disc_game_id_prefixes));
|
2024-04-11 23:35:18 +00:00
|
|
|
|
|
|
|
std::string_view game_id_prefix(game_id.data(), GAME_ID_PREFIX_SIZE);
|
|
|
|
return std::binary_search(two_disc_game_id_prefixes.begin(), two_disc_game_id_prefixes.end(),
|
|
|
|
game_id_prefix);
|
|
|
|
}
|
|
|
|
|
2020-06-10 16:49:22 +00:00
|
|
|
std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database) const
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
std::vector<std::string> info;
|
|
|
|
if (!GetGameID().empty())
|
|
|
|
info.push_back(GetGameID());
|
|
|
|
if (GetRevision() != 0)
|
|
|
|
info.push_back("Revision " + std::to_string(GetRevision()));
|
|
|
|
|
2020-06-10 16:49:22 +00:00
|
|
|
const std::string name = GetName(title_database);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
int disc_number = GetDiscNumber() + 1;
|
|
|
|
|
|
|
|
std::string lower_name = name;
|
2022-01-17 00:38:11 +00:00
|
|
|
Common::ToLower(&lower_name);
|
2017-12-31 19:33:36 +00:00
|
|
|
if (disc_number > 1 &&
|
2019-11-24 00:15:52 +00:00
|
|
|
lower_name.find(fmt::format("disc {}", disc_number)) == std::string::npos &&
|
|
|
|
lower_name.find(fmt::format("disc{}", disc_number)) == std::string::npos)
|
2017-12-31 19:33:36 +00:00
|
|
|
{
|
|
|
|
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() + ")";
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
static Common::SHA1::Digest GetHash(u32 value)
|
2021-11-13 20:15:45 +00:00
|
|
|
{
|
|
|
|
auto data = Common::BitCastToArray<u8>(value);
|
2022-07-24 05:45:10 +00:00
|
|
|
return Common::SHA1::CalculateDigest(data);
|
2021-11-13 20:15:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
static Common::SHA1::Digest GetHash(std::string_view str)
|
2021-11-13 20:15:45 +00:00
|
|
|
{
|
2022-07-24 05:45:10 +00:00
|
|
|
return Common::SHA1::CalculateDigest(str);
|
2021-11-13 20:15:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
static std::optional<Common::SHA1::Digest> GetFileHash(const std::string& path)
|
2021-11-13 20:15:45 +00:00
|
|
|
{
|
|
|
|
std::string buffer;
|
|
|
|
if (!File::ReadFileToString(path, buffer))
|
|
|
|
return std::nullopt;
|
|
|
|
return GetHash(buffer);
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
static std::optional<Common::SHA1::Digest> MixHash(const std::optional<Common::SHA1::Digest>& lhs,
|
|
|
|
const std::optional<Common::SHA1::Digest>& rhs)
|
2021-11-13 20:15:45 +00:00
|
|
|
{
|
|
|
|
if (!lhs && !rhs)
|
|
|
|
return std::nullopt;
|
|
|
|
if (!lhs || !rhs)
|
|
|
|
return !rhs ? lhs : rhs;
|
2022-07-24 05:45:10 +00:00
|
|
|
Common::SHA1::Digest result;
|
2021-11-13 20:15:45 +00:00
|
|
|
for (size_t i = 0; i < result.size(); ++i)
|
|
|
|
result[i] = (*lhs)[i] ^ (*rhs)[(i + 1) % result.size()];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
Common::SHA1::Digest GameFile::GetSyncHash() const
|
2020-06-07 20:58:03 +00:00
|
|
|
{
|
2022-07-24 05:45:10 +00:00
|
|
|
std::optional<Common::SHA1::Digest> hash;
|
2020-06-07 20:58:03 +00:00
|
|
|
|
|
|
|
if (m_platform == DiscIO::Platform::ELFOrDOL)
|
|
|
|
{
|
2021-11-13 20:15:45 +00:00
|
|
|
hash = GetFileHash(m_file_path);
|
|
|
|
}
|
|
|
|
else if (m_blob_type == DiscIO::BlobType::MOD_DESCRIPTOR)
|
|
|
|
{
|
|
|
|
auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path);
|
|
|
|
if (descriptor)
|
|
|
|
{
|
|
|
|
GameFile proxy(descriptor->base_file);
|
|
|
|
if (proxy.IsValid())
|
|
|
|
hash = proxy.GetSyncHash();
|
|
|
|
|
|
|
|
// add patches to hash if they're enabled
|
|
|
|
if (descriptor->riivolution)
|
|
|
|
{
|
|
|
|
for (const auto& patch : descriptor->riivolution->patches)
|
|
|
|
{
|
|
|
|
hash = MixHash(hash, GetFileHash(patch.xml));
|
|
|
|
for (const auto& option : patch.options)
|
|
|
|
{
|
|
|
|
hash = MixHash(hash, GetHash(option.section_name));
|
|
|
|
hash = MixHash(hash, GetHash(option.option_id));
|
|
|
|
hash = MixHash(hash, GetHash(option.option_name));
|
|
|
|
hash = MixHash(hash, GetHash(option.choice));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-07 20:58:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (std::unique_ptr<DiscIO::Volume> volume = DiscIO::CreateVolume(m_file_path))
|
|
|
|
hash = volume->GetSyncHash();
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:45:10 +00:00
|
|
|
return hash.value_or(Common::SHA1::Digest{});
|
2020-06-07 20:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NetPlay::SyncIdentifier GameFile::GetSyncIdentifier() const
|
|
|
|
{
|
|
|
|
const u64 dol_elf_size = m_platform == DiscIO::Platform::ELFOrDOL ? m_file_size : 0;
|
|
|
|
return NetPlay::SyncIdentifier{dol_elf_size, m_game_id, m_revision,
|
|
|
|
m_disc_number, m_is_datel_disc, GetSyncHash()};
|
|
|
|
}
|
|
|
|
|
|
|
|
NetPlay::SyncIdentifierComparison
|
|
|
|
GameFile::CompareSyncIdentifier(const NetPlay::SyncIdentifier& sync_identifier) const
|
|
|
|
{
|
|
|
|
const bool is_elf_or_dol = m_platform == DiscIO::Platform::ELFOrDOL;
|
|
|
|
if ((is_elf_or_dol ? m_file_size : 0) != sync_identifier.dol_elf_size)
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
|
|
|
|
2022-05-21 05:25:33 +00:00
|
|
|
if (m_is_datel_disc != sync_identifier.is_datel)
|
2020-06-07 20:58:03 +00:00
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
|
|
|
|
2022-05-21 05:25:33 +00:00
|
|
|
if (m_game_id.size() != sync_identifier.game_id.size())
|
2020-06-07 20:58:03 +00:00
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
|
|
|
|
2022-05-21 05:25:33 +00:00
|
|
|
if (!is_elf_or_dol && !m_is_datel_disc && m_game_id.size() >= 4 && m_game_id.size() <= 6)
|
|
|
|
{
|
|
|
|
// This is a game ID, following specific rules which we can use to give clearer information to
|
|
|
|
// the user.
|
|
|
|
|
|
|
|
// If the first 3 characters don't match, then these are probably different games.
|
|
|
|
// (There are exceptions; in particular Japanese-region games sometimes use a different ID;
|
|
|
|
// for instance, GOYE69, GOYP69, and GGIJ13 are used by GoldenEye: Rogue Agent.)
|
|
|
|
if (std::string_view(&m_game_id[0], 3) != std::string_view(&sync_identifier.game_id[0], 3))
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
|
|
|
|
|
|
|
// If the first 3 characters match but the region doesn't match, reject it as such.
|
|
|
|
if (m_game_id[3] != sync_identifier.game_id[3])
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentRegion;
|
|
|
|
|
|
|
|
// If the maker code is present, and doesn't match between the two but the main ID does,
|
|
|
|
// these might be different revisions of the same game (e.g. a rerelease with a different
|
|
|
|
// publisher), which we should treat as a different revision.
|
|
|
|
if (std::string_view(&m_game_id[4]) != std::string_view(&sync_identifier.game_id[4]))
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentRevision;
|
|
|
|
}
|
|
|
|
else
|
2020-06-07 20:58:03 +00:00
|
|
|
{
|
2022-05-21 05:25:33 +00:00
|
|
|
// Numeric title ID or another generated ID that does not follow the rules above
|
|
|
|
if (m_game_id != sync_identifier.game_id)
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
2020-06-07 20:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_revision != sync_identifier.revision)
|
2022-05-21 05:25:33 +00:00
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentRevision;
|
|
|
|
|
|
|
|
if (m_disc_number != sync_identifier.disc_number)
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentDiscNumber;
|
|
|
|
|
|
|
|
if (GetSyncHash() != sync_identifier.sync_hash)
|
|
|
|
{
|
|
|
|
// Most Datel titles re-use the same game ID (GNHE5d, with that lowercase D, or DTLX01).
|
|
|
|
// So if the hash differs, then it's probably a different game even if the game ID matches.
|
|
|
|
if (m_is_datel_disc)
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentGame;
|
|
|
|
else
|
|
|
|
return NetPlay::SyncIdentifierComparison::DifferentHash;
|
|
|
|
}
|
2020-06-07 20:58:03 +00:00
|
|
|
|
2022-05-21 05:25:33 +00:00
|
|
|
return NetPlay::SyncIdentifierComparison::SameGame;
|
2020-06-07 20:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-31 19:33:36 +00:00
|
|
|
std::string GameFile::GetWiiFSPath() const
|
|
|
|
{
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(DiscIO::IsWii(m_platform));
|
2023-06-13 20:22:56 +00:00
|
|
|
return Common::GetTitleDataPath(m_title_id, Common::FromWhichRoot::Configured);
|
2017-12-31 19:33:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 18:41:50 +00:00
|
|
|
bool GameFile::ShouldShowFileFormatDetails() const
|
|
|
|
{
|
|
|
|
switch (m_blob_type)
|
|
|
|
{
|
|
|
|
case DiscIO::BlobType::PLAIN:
|
|
|
|
break;
|
|
|
|
case DiscIO::BlobType::DRIVE:
|
2021-10-26 00:01:16 +00:00
|
|
|
case DiscIO::BlobType::MOD_DESCRIPTOR:
|
2020-06-21 18:41:50 +00:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_platform)
|
|
|
|
{
|
|
|
|
case DiscIO::Platform::WiiWAD:
|
|
|
|
return false;
|
|
|
|
case DiscIO::Platform::ELFOrDOL:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 19:18:42 +00:00
|
|
|
std::string GameFile::GetFileFormatName() const
|
|
|
|
{
|
|
|
|
switch (m_platform)
|
|
|
|
{
|
|
|
|
case DiscIO::Platform::WiiWAD:
|
|
|
|
return "WAD";
|
2020-10-06 11:00:58 +00:00
|
|
|
|
2020-07-19 19:18:42 +00:00
|
|
|
case DiscIO::Platform::ELFOrDOL:
|
|
|
|
{
|
|
|
|
std::string extension = GetExtension();
|
2022-01-17 00:38:11 +00:00
|
|
|
Common::ToUpper(&extension);
|
2020-07-19 19:18:42 +00:00
|
|
|
|
|
|
|
// substr removes the dot
|
|
|
|
return extension.substr(std::min<size_t>(1, extension.size()));
|
|
|
|
}
|
2020-10-06 11:00:58 +00:00
|
|
|
|
2020-07-19 19:18:42 +00:00
|
|
|
default:
|
2020-10-06 11:00:58 +00:00
|
|
|
{
|
|
|
|
std::string name = DiscIO::GetName(m_blob_type, true);
|
|
|
|
if (m_is_nkit)
|
2020-10-14 18:50:38 +00:00
|
|
|
name = Common::FmtFormatT("{0} (NKit)", name);
|
2020-10-06 11:00:58 +00:00
|
|
|
return name;
|
|
|
|
}
|
2020-07-19 19:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-27 10:35:18 +00:00
|
|
|
bool GameFile::ShouldAllowConversion() const
|
|
|
|
{
|
2022-08-01 09:53:30 +00:00
|
|
|
return DiscIO::IsDisc(m_platform) && m_volume_size_type == DiscIO::DataSizeType::Accurate;
|
2020-06-27 10:35:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 00:01:16 +00:00
|
|
|
bool GameFile::IsModDescriptor() const
|
|
|
|
{
|
|
|
|
return m_blob_type == DiscIO::BlobType::MOD_DESCRIPTOR;
|
|
|
|
}
|
|
|
|
|
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
|