diff --git a/src/Platform.h b/src/Platform.h index 03233715..56f2c2e1 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -34,6 +34,7 @@ void StopEmu(); // instance ID, for local multiplayer int InstanceID(); +std::string InstanceFileSuffix(); // configuration values diff --git a/src/SPI.cpp b/src/SPI.cpp index df3d0ea8..e990b3a7 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -79,16 +79,6 @@ bool VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset) return (crc_stored == crc_calced); } -std::string InstanceSuffix() -{ - int inst = Platform::InstanceID(); - if (inst == 0) return ""; - - char suffix[16] = {0}; - snprintf(suffix, 15, ".%d", inst+1); - return suffix; -} - bool Init() { @@ -225,7 +215,7 @@ void LoadDefaultFirmware() // wifi access points // TODO: WFC ID?? - FILE* f = Platform::OpenLocalFile("wfcsettings.bin"+InstanceSuffix(), "rb"); + FILE* f = Platform::OpenLocalFile("wfcsettings.bin"+Platform::InstanceFileSuffix(), "rb"); if (!f) f = Platform::OpenLocalFile("wfcsettings.bin", "rb"); if (f) { @@ -348,7 +338,7 @@ void Reset() bool makecopy = false; std::string origpath = FirmwarePath; - FirmwarePath += InstanceSuffix(); + FirmwarePath += Platform::InstanceFileSuffix(); FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb"); if (!f) diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index dd2a5d7b..68bdd3ea 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -158,6 +158,16 @@ int InstanceID() return IPCInstanceID; } +std::string InstanceFileSuffix() +{ + int inst = IPCInstanceID; + if (inst == 0) return ""; + + char suffix[16] = {0}; + snprintf(suffix, 15, ".%d", inst+1); + return suffix; +} + int GetConfigInt(ConfigEntry entry) { diff --git a/src/frontend/qt_sdl/ROMManager.cpp b/src/frontend/qt_sdl/ROMManager.cpp index 304862eb..716a4543 100644 --- a/src/frontend/qt_sdl/ROMManager.cpp +++ b/src/frontend/qt_sdl/ROMManager.cpp @@ -326,6 +326,7 @@ bool LoadState(std::string filename) std::string savefile = filename.substr(LastSep(filename)+1); savefile = GetAssetPath(false, Config::SaveFilePath, ".sav", savefile); + savefile += Platform::InstanceFileSuffix(); NDSSave->SetPath(savefile, true); } @@ -350,6 +351,7 @@ bool SaveState(std::string filename) { std::string savefile = filename.substr(LastSep(filename)+1); savefile = GetAssetPath(false, Config::SaveFilePath, ".sav", savefile); + savefile += Platform::InstanceFileSuffix(); NDSSave->SetPath(savefile, false); } @@ -432,6 +434,7 @@ void Reset() { std::string oldsave = NDSSave->GetPath(); std::string newsave = GetAssetPath(false, Config::SaveFilePath, ".sav"); + newsave += Platform::InstanceFileSuffix(); if (oldsave != newsave) NDSSave->SetPath(newsave, false); } @@ -440,6 +443,7 @@ void Reset() { std::string oldsave = GBASave->GetPath(); std::string newsave = GetAssetPath(true, Config::SaveFilePath, ".sav"); + newsave += Platform::InstanceFileSuffix(); if (oldsave != newsave) GBASave->SetPath(newsave, false); } @@ -562,7 +566,11 @@ bool LoadROM(QStringList filepath, bool reset) u8* savedata = nullptr; std::string savname = GetAssetPath(false, Config::SaveFilePath, ".sav"); + std::string origsav = savname; + savname += Platform::InstanceFileSuffix(); + FILE* sav = Platform::OpenFile(savname, "rb", true); + if (!sav) sav = Platform::OpenFile(origsav, "rb", true); if (sav) { fseek(sav, 0, SEEK_END); @@ -711,7 +719,11 @@ bool LoadGBAROM(QStringList filepath) u8* savedata = nullptr; std::string savname = GetAssetPath(true, Config::SaveFilePath, ".sav"); + std::string origsav = savname; + savname += Platform::InstanceFileSuffix(); + FILE* sav = Platform::OpenFile(savname, "rb", true); + if (!sav) sav = Platform::OpenFile(origsav, "rb", true); if (sav) { fseek(sav, 0, SEEK_END);