fix undo load state and load last overwritten state while recording

This commit is contained in:
rog 2012-10-18 04:11:14 -04:00
parent 7f624cda10
commit 6b99b746c8

View File

@ -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<std::mutex> 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<std::mutex> 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