Merge pull request #9461 from cbartondock/master

Working Game IDs for Elf/Dol files
This commit is contained in:
Léo Lam 2021-02-10 22:50:40 +01:00 committed by GitHub
commit ddacbf83f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 6 deletions

View file

@ -4,11 +4,14 @@
#include "Core/ConfigManager.h"
#include <algorithm>
#include <cinttypes>
#include <climits>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
#include <variant>
#include <fmt/format.h>
@ -653,6 +656,11 @@ void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd, DiscIO::Plat
}
}
void SConfig::SetRunningGameMetadata(const std::string& game_id)
{
SetRunningGameMetadata(game_id, "", 0, 0, DiscIO::Region::Unknown);
}
void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id,
u64 title_id, u16 revision, DiscIO::Region region)
{
@ -770,6 +778,15 @@ bool SConfig::IsUSBDeviceWhitelisted(const std::pair<u16, u16> vid_pid) const
return m_usb_passthrough_devices.find(vid_pid) != m_usb_passthrough_devices.end();
}
// Static method to make a simple game ID for elf/dol files
std::string SConfig::MakeGameID(std::string_view file_name)
{
size_t lastdot = file_name.find_last_of(".");
if (lastdot == std::string::npos)
return "ID-" + std::string(file_name);
return "ID-" + std::string(file_name.substr(0, lastdot));
}
// The reason we need this function is because some memory card code
// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii.
DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region)
@ -840,6 +857,13 @@ struct SetGameMetadata
// Strip the .elf/.dol file extension and directories before the name
SplitPath(executable.path, nullptr, &config->m_debugger_game_id, nullptr);
// Set DOL/ELF game ID appropriately
std::string executable_path = executable.path;
constexpr char BACKSLASH = '\\';
constexpr char FORWARDSLASH = '/';
std::replace(executable_path.begin(), executable_path.end(), BACKSLASH, FORWARDSLASH);
config->SetRunningGameMetadata(SConfig::MakeGameID(PathToFileName(executable_path)));
Host_TitleChanged();
return true;

View file

@ -8,6 +8,7 @@
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
@ -195,8 +196,9 @@ struct SConfig
void ResetRunningGameMetadata();
void SetRunningGameMetadata(const DiscIO::Volume& volume, const DiscIO::Partition& partition);
void SetRunningGameMetadata(const IOS::ES::TMDReader& tmd, DiscIO::Platform platform);
void SetRunningGameMetadata(const std::string& game_id);
void LoadDefaults();
static std::string MakeGameID(std::string_view file_name);
// Replaces NTSC-K with some other region, and doesn't replace non-NTSC-K regions
static DiscIO::Region ToGameCubeRegion(DiscIO::Region region);
// The region argument must be valid for GameCube (i.e. must not be NTSC-K)

View file

@ -318,15 +318,14 @@ void GameList::ShowContextMenu(const QPoint&)
{
const auto game = GetSelectedGame();
DiscIO::Platform platform = game->GetPlatform();
menu->addAction(tr("&Properties"), this, &GameList::OpenProperties);
if (platform != DiscIO::Platform::ELFOrDOL)
{
menu->addAction(tr("&Properties"), this, &GameList::OpenProperties);
menu->addAction(tr("&Wiki"), this, &GameList::OpenWiki);
menu->addSeparator();
}
menu->addSeparator();
if (DiscIO::IsDisc(platform))
{
menu->addAction(tr("Set as &Default ISO"), this, &GameList::SetDefaultISO);

View file

@ -157,6 +157,7 @@ GameFile::GameFile(std::string path) : m_file_path(std::move(path))
{
m_valid = true;
m_file_size = m_volume_size = File::GetSize(m_file_path);
m_game_id = SConfig::MakeGameID(m_file_name);
m_volume_size_is_accurate = true;
m_is_datel_disc = false;
m_is_nkit = false;

View file

@ -27,7 +27,7 @@
namespace UICommon
{
static constexpr u32 CACHE_REVISION = 19; // Last changed in PR 9135
static constexpr u32 CACHE_REVISION = 20; // Last changed in PR 9461
std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
bool recursive_scan)