Overlay the user Maps/ over the shared one to avoid copying files

This commit is contained in:
Pierre Bourdon 2013-09-12 01:02:41 +02:00
parent b587af3ea3
commit 6bdb6585d6
7 changed files with 70 additions and 47 deletions

View file

@ -71,59 +71,73 @@ void CBoot::UpdateDebugger_MapLoaded(const char *_gameID)
Host_NotifyMapLoaded(); Host_NotifyMapLoaded();
} }
std::string CBoot::GenerateMapFilename() bool CBoot::FindMapFile(std::string* existing_map_file,
std::string* writable_map_file)
{ {
std::string title_id_str;
SCoreStartupParameter& _StartupPara = SConfig::GetInstance().m_LocalCoreStartupParameter; SCoreStartupParameter& _StartupPara = SConfig::GetInstance().m_LocalCoreStartupParameter;
switch (_StartupPara.m_BootType) switch (_StartupPara.m_BootType)
{ {
case SCoreStartupParameter::BOOT_WII_NAND: case SCoreStartupParameter::BOOT_WII_NAND:
{ {
const DiscIO::INANDContentLoader& Loader = DiscIO::CNANDContentManager::Access().GetNANDLoader(_StartupPara.m_strFilename); const DiscIO::INANDContentLoader& Loader =
DiscIO::CNANDContentManager::Access().GetNANDLoader(_StartupPara.m_strFilename);
if (Loader.IsValid()) if (Loader.IsValid())
{ {
u64 TitleID = Loader.GetTitleID(); u64 TitleID = Loader.GetTitleID();
char tmpBuffer[32]; title_id_str = StringFromFormat("%08X_%08X",
sprintf(tmpBuffer, "%08x_%08x", (u32)(TitleID >> 32) & 0xFFFFFFFF , (u32)TitleID & 0xFFFFFFFF ); (u32)(TitleID >> 32) & 0xFFFFFFFF,
return File::GetUserPath(D_MAPS_IDX) + std::string(tmpBuffer) + ".map"; (u32)TitleID & 0xFFFFFFFF);
} }
break; break;
} }
case SCoreStartupParameter::BOOT_ELF: case SCoreStartupParameter::BOOT_ELF:
case SCoreStartupParameter::BOOT_DOL: case SCoreStartupParameter::BOOT_DOL:
return _StartupPara.m_strFilename.substr(0, _StartupPara.m_strFilename.size()-4) + ".map"; // Strip the .elf/.dol file extension
title_id_str = _StartupPara.m_strFilename.substr(
0, _StartupPara.m_strFilename.size() - 4);
break;
default: default:
return File::GetUserPath(D_MAPS_IDX) + _StartupPara.GetUniqueID() + ".map"; title_id_str = _StartupPara.GetUniqueID();
break;
} }
return std::string("unknown map"); if (writable_map_file)
*writable_map_file = File::GetUserPath(D_MAPS_IDX) + title_id_str + ".map";
bool found = false;
static const std::string maps_directories[] = {
File::GetUserPath(D_MAPS_IDX),
File::GetSysDirectory() + MAPS_DIR DIR_SEP
};
for (size_t i = 0; !found && i < ArraySize(maps_directories); ++i)
{
std::string path = maps_directories[i] + title_id_str + ".map";
if (File::Exists(path))
{
found = true;
if (existing_map_file)
*existing_map_file = path;
}
}
return found;
} }
bool CBoot::LoadMapFromFilename(const std::string &_rFilename, const char *_gameID) bool CBoot::LoadMapFromFilename()
{ {
if (_rFilename.size() == 0) std::string strMapFilename;
return false; bool found = FindMapFile(&strMapFilename, NULL);
if (found && g_symbolDB.LoadMap(strMapFilename.c_str()))
std::string strMapFilename = GenerateMapFilename();
bool success = false;
if (!g_symbolDB.LoadMap(strMapFilename.c_str()))
{ {
if (_gameID != NULL)
{
BuildCompleteFilename(strMapFilename, "maps", std::string(_gameID) + ".map");
success = g_symbolDB.LoadMap(strMapFilename.c_str());
}
}
else
{
success = true;
}
if (success)
UpdateDebugger_MapLoaded(); UpdateDebugger_MapLoaded();
return true;
}
return success; return false;
} }
// If ipl.bin is not found, this function does *some* of what BS1 does: // If ipl.bin is not found, this function does *some* of what BS1 does:
@ -201,10 +215,6 @@ bool CBoot::BootUp()
PanicAlertT("Warning - starting ISO in wrong console mode!"); PanicAlertT("Warning - starting ISO in wrong console mode!");
} }
char gameID[7];
memcpy(gameID, pVolume->GetUniqueID().c_str(), 6);
gameID[6] = 0;
// setup the map from ISOFile ID // setup the map from ISOFile ID
VolumeHandler::SetVolumeName(_StartupPara.m_strFilename); VolumeHandler::SetVolumeName(_StartupPara.m_strFilename);
@ -252,7 +262,7 @@ bool CBoot::BootUp()
/* Try to load the symbol map if there is one, and then scan it for /* Try to load the symbol map if there is one, and then scan it for
and eventually replace code */ and eventually replace code */
if (LoadMapFromFilename(_StartupPara.m_strFilename, gameID)) if (LoadMapFromFilename())
HLE::PatchFunctions(); HLE::PatchFunctions();
// We don't need the volume any more // We don't need the volume any more
@ -298,7 +308,7 @@ bool CBoot::BootUp()
PC = dolLoader.GetEntryPoint(); PC = dolLoader.GetEntryPoint();
} }
if (LoadMapFromFilename(_StartupPara.m_strFilename)) if (LoadMapFromFilename())
HLE::PatchFunctions(); HLE::PatchFunctions();
break; break;
@ -368,7 +378,7 @@ bool CBoot::BootUp()
case SCoreStartupParameter::BOOT_WII_NAND: case SCoreStartupParameter::BOOT_WII_NAND:
Boot_WiiWAD(_StartupPara.m_strFilename.c_str()); Boot_WiiWAD(_StartupPara.m_strFilename.c_str());
if (LoadMapFromFilename(_StartupPara.m_strFilename)) if (LoadMapFromFilename())
HLE::PatchFunctions(); HLE::PatchFunctions();
// load default image or create virtual drive from directory // load default image or create virtual drive from directory
@ -387,7 +397,7 @@ bool CBoot::BootUp()
DVDInterface::SetDiscInside(VolumeHandler::IsValid()); DVDInterface::SetDiscInside(VolumeHandler::IsValid());
if (Load_BS2(_StartupPara.m_strBootROM)) if (Load_BS2(_StartupPara.m_strBootROM))
{ {
if (LoadMapFromFilename(_StartupPara.m_strFilename)) if (LoadMapFromFilename())
HLE::PatchFunctions(); HLE::PatchFunctions();
} }
else else

View file

@ -16,14 +16,26 @@ public:
static bool BootUp(); static bool BootUp();
static bool IsElfWii(const char *filename); static bool IsElfWii(const char *filename);
static std::string GenerateMapFilename();
// Tries to find a map file for the current game by looking first in the
// local user directory, then in the shared user directory.
//
// If existing_map_file is not NULL and a map file exists, it is set to the
// path to the existing map file.
//
// If writable_map_file is not NULL, it is set to the path to where a map
// 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);
private: private:
static void RunFunction(u32 _iAddr); static void RunFunction(u32 _iAddr);
static void UpdateDebugger_MapLoaded(const char* _gameID = NULL); static void UpdateDebugger_MapLoaded(const char* _gameID = NULL);
static bool LoadMapFromFilename(const std::string& _rFilename, const char* _gameID = NULL); static bool LoadMapFromFilename();
static bool Boot_ELF(const char *filename); static bool Boot_ELF(const char *filename);
static bool Boot_WiiWAD(const char *filename); static bool Boot_WiiWAD(const char *filename);

View file

@ -68,7 +68,7 @@ bool CBoot::Boot_ELF(const char *filename)
reader.LoadInto(0x80000000); reader.LoadInto(0x80000000);
if (!reader.LoadSymbols()) if (!reader.LoadSymbols())
{ {
if (LoadMapFromFilename(filename)) if (LoadMapFromFilename())
HLE::PatchFunctions(); HLE::PatchFunctions();
} }
else else

View file

@ -211,7 +211,9 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
if (Core::GetState() == Core::CORE_UNINITIALIZED) return; if (Core::GetState() == Core::CORE_UNINITIALIZED) return;
std::string mapfile = CBoot::GenerateMapFilename(); std::string existing_map_file, writable_map_file;
bool map_exists = CBoot::FindMapFile(&existing_map_file,
&writable_map_file);
switch (event.GetId()) switch (event.GetId())
{ {
case IDM_CLEARSYMBOLS: case IDM_CLEARSYMBOLS:
@ -238,28 +240,28 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
break; break;
} }
case IDM_LOADMAPFILE: case IDM_LOADMAPFILE:
if (!File::Exists(mapfile)) if (!map_exists)
{ {
g_symbolDB.Clear(); g_symbolDB.Clear();
PPCAnalyst::FindFunctions(0x81300000, 0x81800000, &g_symbolDB); PPCAnalyst::FindFunctions(0x81300000, 0x81800000, &g_symbolDB);
SignatureDB db; SignatureDB db;
if (db.Load((File::GetSysDirectory() + TOTALDB).c_str())) if (db.Load((File::GetSysDirectory() + TOTALDB).c_str()))
db.Apply(&g_symbolDB); db.Apply(&g_symbolDB);
Parent->StatusBarMessage("'%s' not found, scanning for common functions instead", mapfile.c_str()); Parent->StatusBarMessage("'%s' not found, scanning for common functions instead", writable_map_file.c_str());
} }
else else
{ {
g_symbolDB.LoadMap(mapfile.c_str()); g_symbolDB.LoadMap(existing_map_file.c_str());
Parent->StatusBarMessage("Loaded symbols from '%s'", mapfile.c_str()); Parent->StatusBarMessage("Loaded symbols from '%s'", existing_map_file.c_str());
} }
HLE::PatchFunctions(); HLE::PatchFunctions();
NotifyMapLoaded(); NotifyMapLoaded();
break; break;
case IDM_SAVEMAPFILE: case IDM_SAVEMAPFILE:
g_symbolDB.SaveMap(mapfile.c_str()); g_symbolDB.SaveMap(writable_map_file.c_str());
break; break;
case IDM_SAVEMAPFILEWITHCODES: case IDM_SAVEMAPFILEWITHCODES:
g_symbolDB.SaveMap(mapfile.c_str(), true); g_symbolDB.SaveMap(writable_map_file.c_str(), true);
break; break;
case IDM_RENAME_SYMBOLS: case IDM_RENAME_SYMBOLS:

View file

@ -253,8 +253,6 @@ bool DolphinApp::OnInit()
//TODO : detect the revision and upgrade where necessary //TODO : detect the revision and upgrade where necessary
File::CopyDir(std::string(SHARED_USER_DIR GAMECONFIG_DIR DIR_SEP), File::CopyDir(std::string(SHARED_USER_DIR GAMECONFIG_DIR DIR_SEP),
File::GetUserPath(D_GAMECONFIG_IDX)); File::GetUserPath(D_GAMECONFIG_IDX));
File::CopyDir(std::string(SHARED_USER_DIR MAPS_DIR DIR_SEP),
File::GetUserPath(D_MAPS_IDX));
File::CopyDir(std::string(SHARED_USER_DIR SHADERS_DIR DIR_SEP), File::CopyDir(std::string(SHARED_USER_DIR SHADERS_DIR DIR_SEP),
File::GetUserPath(D_SHADERS_IDX)); File::GetUserPath(D_SHADERS_IDX));
File::CopyDir(std::string(SHARED_USER_DIR WII_USER_DIR DIR_SEP), File::CopyDir(std::string(SHARED_USER_DIR WII_USER_DIR DIR_SEP),
@ -272,6 +270,7 @@ bool DolphinApp::OnInit()
File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX));
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX)); File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX));
File::CreateFullPath(File::GetUserPath(D_MAPS_IDX));
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP); File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP);
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP); File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP);
File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP); File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP);