PPCSymbolDB: Move function for finding file path to PPCSymbolDB, so MenuBar doesn't have to randomly access boot.cpp to get the file path.

This commit is contained in:
TryTwo
2025-06-17 22:16:12 -07:00
parent c2aaca2b16
commit 5836ca133c
5 changed files with 28 additions and 26 deletions

View File

@ -354,30 +354,10 @@ bool CBoot::DVDReadDiscID(Core::System& system, const DiscIO::VolumeDisc& disc,
return true;
}
// Get map file paths for the active title.
bool CBoot::FindMapFile(std::string* existing_map_file, std::string* writable_map_file)
{
const std::string& game_id = SConfig::GetInstance().m_debugger_game_id;
std::string path = File::GetUserPath(D_MAPS_IDX) + game_id + ".map";
if (writable_map_file)
*writable_map_file = path;
if (File::Exists(path))
{
if (existing_map_file)
*existing_map_file = std::move(path);
return true;
}
return false;
}
bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db)
{
std::string strMapFilename;
bool found = FindMapFile(&strMapFilename, nullptr);
bool found = ppc_symbol_db.FindMapFile(&strMapFilename, nullptr);
if (found && ppc_symbol_db.LoadMap(guard, strMapFilename))
{
Host_PPCSymbolsChanged();

View File

@ -169,7 +169,6 @@ public:
// file should be saved.
//
// Returns true if a map file exists, false if none could be found.
static bool FindMapFile(std::string* existing_map_file, std::string* writable_map_file);
static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db);
private:

View File

@ -15,10 +15,12 @@
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/IOFile.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Common/Unreachable.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/Debugger/DebugInterface.h"
#include "Core/PowerPC/MMU.h"
@ -279,6 +281,26 @@ void PPCSymbolDB::LogFunctionCall(u32 addr)
f.num_calls++;
}
// Get map file paths for the active title.
bool PPCSymbolDB::FindMapFile(std::string* existing_map_file, std::string* writable_map_file)
{
const std::string& game_id = SConfig::GetInstance().m_debugger_game_id;
std::string path = File::GetUserPath(D_MAPS_IDX) + game_id + ".map";
if (writable_map_file)
*writable_map_file = path;
if (File::Exists(path))
{
if (existing_map_file)
*existing_map_file = std::move(path);
return true;
}
return false;
}
// The use case for handling bad map files is when you have a game with a map file on the disc,
// but you can't tell whether that map file is for the particular release version used in that game,
// or when you know that the map file is not for that build, but perhaps half the functions in the

View File

@ -44,4 +44,6 @@ public:
void PrintCalls(u32 funcAddr) const;
void PrintCallers(u32 funcAddr) const;
void LogFunctionCall(u32 addr);
static bool FindMapFile(std::string* existing_map_file, std::string* writable_map_file);
};

View File

@ -26,7 +26,6 @@
#include "Common/StringUtil.h"
#include "Core/AchievementManager.h"
#include "Core/Boot/Boot.h"
#include "Core/CommonTitles.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/MainSettings.h"
@ -1714,7 +1713,7 @@ void MenuBar::LoadSymbolMap()
auto& ppc_symbol_db = system.GetPPCSymbolDB();
std::string existing_map_file, writable_map_file;
bool map_exists = CBoot::FindMapFile(&existing_map_file, &writable_map_file);
bool map_exists = PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file);
if (!map_exists)
{
@ -1752,7 +1751,7 @@ void MenuBar::LoadSymbolMap()
void MenuBar::SaveSymbolMap()
{
std::string existing_map_file, writable_map_file;
CBoot::FindMapFile(&existing_map_file, &writable_map_file);
PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file);
TrySaveSymbolMap(QString::fromStdString(writable_map_file));
}
@ -1808,7 +1807,7 @@ void MenuBar::SaveSymbolMapAs()
void MenuBar::SaveCode()
{
std::string existing_map_file, writable_map_file;
CBoot::FindMapFile(&existing_map_file, &writable_map_file);
PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file);
const std::string path =
writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map";