summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2017-12-28 10:13:53 +0100
committermahdihijazi <mahdi.hijaz@hotmail.com>2017-12-28 23:15:48 +0100
commit82a6701f795a883d80c3b0167b4d3f3e224a5cd8 (patch)
treeaa1a58476598667185b5c77541d70719a9b3028b /Source/Core
parentf9a05119370dbc3a261cda61d97b17c261db7b0b (diff)
Optionally delete savestate that gets loaded at boot
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Boot/Boot.h1
-rw-r--r--Source/Core/Core/Core.cpp20
2 files changed, 15 insertions, 6 deletions
diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h
index 7581b2abb8..a6b7391b44 100644
--- a/Source/Core/Core/Boot/Boot.h
+++ b/Source/Core/Core/Boot/Boot.h
@@ -76,6 +76,7 @@ struct BootParameters
Parameters parameters;
std::optional<std::string> savestate_path;
+ bool delete_savestate = false;
};
class CBoot
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp
index 1d77f4e2fc..500885ffbb 100644
--- a/Source/Core/Core/Core.cpp
+++ b/Source/Core/Core/Core.cpp
@@ -318,7 +318,7 @@ static void CPUSetInitialExecutionState()
}
// Create the CPU thread, which is a CPU + Video thread in Single Core mode.
-static void CpuThread(const std::optional<std::string>& savestate_path)
+static void CpuThread(const std::optional<std::string>& savestate_path, bool delete_savestate)
{
DeclareAsCPUThread();
@@ -342,7 +342,13 @@ static void CpuThread(const std::optional<std::string>& savestate_path)
EMM::InstallExceptionHandler(); // Let's run under memory watch
if (savestate_path)
- QueueHostJob([&savestate_path] { ::State::LoadAs(*savestate_path); });
+ {
+ QueueHostJob([&savestate_path, delete_savestate] {
+ ::State::LoadAs(*savestate_path);
+ if (delete_savestate)
+ File::Delete(*savestate_path);
+ });
+ }
s_is_started = true;
CPUSetInitialExecutionState();
@@ -380,7 +386,8 @@ static void CpuThread(const std::optional<std::string>& savestate_path)
EMM::UninstallExceptionHandler();
}
-static void FifoPlayerThread(const std::optional<std::string>& savestate_path)
+static void FifoPlayerThread(const std::optional<std::string>& savestate_path,
+ bool delete_savestate)
{
DeclareAsCPUThread();
const SConfig& _CoreParameter = SConfig::GetInstance();
@@ -517,6 +524,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
}
const std::optional<std::string> savestate_path = boot->savestate_path;
+ const bool delete_savestate = boot->delete_savestate;
// Load and Init Wiimotes - only if we are booting in Wii mode
if (core_parameter.bWii && !SConfig::GetInstance().m_bt_passthrough_enabled)
@@ -556,7 +564,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
PowerPC::SetMode(PowerPC::CoreMode::Interpreter);
// Determine the CPU thread function
- void (*cpuThreadFunc)(const std::optional<std::string>& savestate_path);
+ void (*cpuThreadFunc)(const std::optional<std::string>& savestate_path, bool delete_savestate);
if (std::holds_alternative<BootParameters::DFF>(boot->parameters))
cpuThreadFunc = FifoPlayerThread;
else
@@ -597,7 +605,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
Host_Message(WM_USER_CREATE);
// Spawn the CPU thread
- s_cpu_thread = std::thread(cpuThreadFunc, savestate_path);
+ s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
// become the GPU thread
Fifo::RunGpuLoop();
@@ -615,7 +623,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
Common::SetCurrentThreadName("Emuthread - Idle");
// Spawn the CPU+GPU thread
- s_cpu_thread = std::thread(cpuThreadFunc, savestate_path);
+ s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
while (CPU::GetState() != CPU::State::PowerDown)
{