Merge pull request #14767 from JosJuice/state-nand-open-file

IOS/FS: Fix loading savestate when files are open
This commit is contained in:
JosJuice
2026-08-08 13:02:54 +02:00
committed by GitHub
2 changed files with 120 additions and 2 deletions
+14 -2
View File
@@ -279,8 +279,18 @@ HostFileSystem::FstEntry* HostFileSystem::GetFstEntryForPath(const std::string&
void HostFileSystem::DoState(PointerWrap& p)
{
// Temporarily close the file, to prevent any issues with the savestating of files/folders.
for (Handle& handle : m_handles)
// This piece of code is handling four separate problems:
// 1. Close host handles by calling reset on them, in case DoStateRead needs to modify a file that
// was open.
// 2. Close guest handles by setting opened to false on each element in m_handles, in case
// DoStateRead needs to modify a file that was open.
// 3. Close guest handles by setting opened to false on each element in m_handles, because if all
// of them were open, it would make DoStateRead/DoStateWriteOrMeasure's calls to OpenFile fail.
// 4. Create a copy of m_handles that we can restore later in case we're writing/measuring,
// because OpenFile happily stomps over elements in m_handles that have opened set to false.
auto handles_copy = std::move(m_handles);
m_handles = {};
for (Handle& handle : handles_copy)
handle.host_file.reset();
// The format for the next part of the save state is follows:
@@ -316,6 +326,8 @@ void HostFileSystem::DoState(PointerWrap& p)
memcpy(nand_size_ptr, &size_of_nand, sizeof(size_of_nand));
}
}
m_handles = std::move(handles_copy);
}
else // case where we're in read mode.
{