From 6b99b746c822d85d65618b163d52c289550e276d Mon Sep 17 00:00:00 2001 From: rog Date: Thu, 18 Oct 2012 04:11:14 -0400 Subject: [PATCH] fix undo load state and load last overwritten state while recording --- Source/Core/Core/Src/State.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/Src/State.cpp b/Source/Core/Core/Src/State.cpp index f7d6523b05..9b5ae9edb3 100644 --- a/Source/Core/Core/Src/State.cpp +++ b/Source/Core/Core/Src/State.cpp @@ -196,9 +196,16 @@ void CompressAndDumpState(CompressAndDumpState_args save_args) { if (File::Exists(File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav")) File::Delete((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav")); + if (File::Exists(File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav.dtm")) + File::Delete((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav.dtm")); - if (!File::Rename(filename, File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav")) + if (!File::Rename(filename, File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav") || !File::Rename(filename + ".dtm", File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav.dtm")) Core::DisplayMessage("Failed to move previous state to state undo backup", 1000); + + if ((Movie::IsRecordingInput() || Movie::IsPlayingInput()) && !Movie::IsJustStartingRecordingInputFromSaveState()) + Movie::SaveRecording((filename + ".dtm").c_str()); + else if (!Movie::IsRecordingInput() && !Movie::IsPlayingInput()) + File::Delete(filename + ".dtm"); } File::IOFile f(filename, "wb"); @@ -273,10 +280,6 @@ void SaveAs(const std::string& filename) if (p.GetMode() == PointerWrap::MODE_WRITE) { Core::DisplayMessage("Saving State...", 1000); - if ((Movie::IsRecordingInput() || Movie::IsPlayingInput()) && !Movie::IsJustStartingRecordingInputFromSaveState()) - Movie::SaveRecording((filename + ".dtm").c_str()); - else if (!Movie::IsRecordingInput() && !Movie::IsPlayingInput()) - File::Delete(filename + ".dtm"); CompressAndDumpState_args save_args; save_args.buffer_vector = &g_current_buffer; @@ -386,6 +389,7 @@ void LoadAs(const std::string& filename) { std::lock_guard lk(g_cs_undo_load_buffer); SaveToBuffer(g_undo_load_buffer); + Movie::SaveRecording("undo.dtm"); } bool loaded = false; @@ -534,7 +538,16 @@ void UndoLoadState() { std::lock_guard lk(g_cs_undo_load_buffer); if (!g_undo_load_buffer.empty()) - LoadFromBuffer(g_undo_load_buffer); + { + if (File::Exists("undo.dtm") || (!Movie::IsRecordingInput() && !Movie::IsPlayingInput())) + { + LoadFromBuffer(g_undo_load_buffer); + if (Movie::IsRecordingInput() || Movie::IsPlayingInput()) + Movie::LoadInput("undo.dtm"); + } + else + PanicAlert("No undo.dtm found, aborting undo load state to prevent movie desyncs"); + } else PanicAlert("There is nothing to undo!"); } @@ -542,7 +555,7 @@ void UndoLoadState() // Load the state that the last save state overwritten on void UndoSaveState() { - LoadAs((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav").c_str()); + LoadAs((File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav").c_str()); } } // namespace State