Savestates: Implement initial RAM ventilation system

This commit is contained in:
Eladash
2023-10-29 01:46:52 +02:00
committed by Elad Ashkenazi
parent 2db607c716
commit 66d01b688c
15 changed files with 513 additions and 102 deletions
+23 -3
View File
@@ -2255,8 +2255,22 @@ fs::file fs::make_gather(std::vector<fs::file> files)
return result;
}
fs::pending_file::pending_file(std::string_view path)
bool fs::pending_file::open(std::string_view path)
{
file.close();
if (!m_path.empty())
{
fs::remove_file(m_path);
}
if (path.empty())
{
fs::g_tls_error = fs::error::noent;
m_dest.clear();
return false;
}
do
{
m_path = fmt::format(u8"%s/%s.%s.tmp", get_parent_dir(path), path.substr(path.find_last_of(fs::delim) + 1), fmt::base57(utils::get_unique_tsc()));
@@ -2270,6 +2284,8 @@ fs::pending_file::pending_file(std::string_view path)
m_path.clear();
}
while (fs::g_tls_error == fs::error::exist); // Only retry if failed due to existing file
return file.operator bool();
}
fs::pending_file::~pending_file()
@@ -2284,7 +2300,7 @@ fs::pending_file::~pending_file()
bool fs::pending_file::commit(bool overwrite)
{
if (!file || m_path.empty())
if (m_path.empty())
{
fs::g_tls_error = fs::error::noent;
return false;
@@ -2292,7 +2308,11 @@ bool fs::pending_file::commit(bool overwrite)
// The temporary file's contents must be on disk before rename
#ifndef _WIN32
file.sync();
if (file)
{
file.sync();
}
#endif
file.close();
+13 -1
View File
@@ -674,12 +674,24 @@ namespace fs
// This is meant to modify files atomically, overwriting is likely
bool commit(bool overwrite = true);
bool open(std::string_view path);
pending_file() noexcept = default;
pending_file(std::string_view path) noexcept
{
open(path);
}
pending_file(std::string_view path);
pending_file(const pending_file&) = delete;
pending_file& operator=(const pending_file&) = delete;
~pending_file();
const std::string& get_temp_path() const
{
return m_path;
}
private:
std::string m_path{}; // Pending file path
std::string m_dest{}; // Destination file path