Skip to content

Commit

Permalink
RMG-Core: add another version of CoreGetSaveStatePath()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Apr 30, 2024
1 parent 8660efe commit 642e768
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
47 changes: 26 additions & 21 deletions Source/RMG-Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,14 @@ bool CoreDecreaseSaveStateSlot(void)
return CoreSetSaveStateSlot(slot - 1);
}

bool CoreGetSaveStatePath(int slot, std::filesystem::path& path)
bool CoreGetSaveStatePath(CoreRomHeader header, CoreRomSettings settings, int slot, std::filesystem::path& path)
{
// TODO: this should probably be an API function
// in mupen64plus-core instead

std::filesystem::path saveStatePath;
std::filesystem::path oldSaveStatePath;
std::string saveStateFileName;
std::filesystem::path saveStateExtension;
CoreRomHeader romHeader;
CoreRomSettings romSettings;

// attempt to retrieve the current
// rom header and settings
if (!CoreGetCurrentRomHeader(romHeader) ||
!CoreGetCurrentRomSettings(romSettings))
{
return false;
}

// retrieve save state directory
saveStatePath = CoreGetSaveStateDirectory();
Expand All @@ -154,7 +143,7 @@ bool CoreGetSaveStatePath(int slot, std::filesystem::path& path)

// construct old save state path
oldSaveStatePath = saveStatePath;
oldSaveStatePath += romSettings.GoodName;
oldSaveStatePath += settings.GoodName;
oldSaveStatePath += saveStateExtension;

// use old filename if it exists
Expand All @@ -168,32 +157,32 @@ bool CoreGetSaveStatePath(int slot, std::filesystem::path& path)
int format = CoreSettingsGetIntValue(SettingsID::Core_SaveFileNameFormat);
if (format == 0)
{
saveStatePath += romHeader.Name;
saveStatePath += header.Name;
saveStatePath += saveStateExtension;
}
else
{
if (romSettings.GoodName.find("(unknown rom)") == std::string::npos)
if (settings.GoodName.find("(unknown rom)") == std::string::npos)
{
if (romSettings.GoodName.size() < 32)
if (settings.GoodName.size() < 32)
{
saveStatePath += romSettings.GoodName;
saveStatePath += settings.GoodName;
}
else
{
saveStatePath += romSettings.GoodName.substr(0, 32);
saveStatePath += settings.GoodName.substr(0, 32);
}
}
else if (!romHeader.Name.empty())
else if (!header.Name.empty())
{
saveStatePath += romHeader.Name;
saveStatePath += header.Name;
}
else
{
saveStatePath += "unknown";
}
saveStatePath += "-";
saveStatePath += romSettings.MD5.substr(0, 8);
saveStatePath += settings.MD5.substr(0, 8);
saveStatePath += saveStateExtension;
}

Expand All @@ -210,6 +199,22 @@ bool CoreGetSaveStatePath(int slot, std::filesystem::path& path)
return true;
}

bool CoreGetSaveStatePath(int slot, std::filesystem::path& path)
{
CoreRomHeader romHeader;
CoreRomSettings romSettings;

// attempt to retrieve the current
// rom header and settings
if (!CoreGetCurrentRomHeader(romHeader) ||
!CoreGetCurrentRomSettings(romSettings))
{
return false;
}

return CoreGetSaveStatePath(romHeader, romSettings, slot, path);
}

bool CoreSaveState(void)
{
std::string error;
Expand Down
9 changes: 9 additions & 0 deletions Source/RMG-Core/SaveState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifndef CORE_SAVESTATE_HPP
#define CORE_SAVESTATE_HPP

#include "RomHeader.hpp"
#include "RomSettings.hpp"

#include <filesystem>

// sets save state slot
Expand All @@ -27,8 +30,14 @@ bool CoreDecreaseSaveStateSlot(void);

// retrieves the file path for
// the save state in the given slot
// for the currently opened ROM
bool CoreGetSaveStatePath(int slot, std::filesystem::path& path);

// retrieves the file path for
// the save state in the given slot
bool CoreGetSaveStatePath(CoreRomHeader header, CoreRomSettings settings, int slot, std::filesystem::path& path);


// saves state
bool CoreSaveState(void);

Expand Down

0 comments on commit 642e768

Please sign in to comment.