From 6711995c5bca6a2f3f5e4a7351317403f2e66782 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Sun, 31 Jul 2011 22:29:56 +0000 Subject: [PATCH] Undo savestate context menu item implemented --- BizHawk.MultiClient/MainForm.MenuItems.cs | 29 +++++++++++++++++------ BizHawk.MultiClient/MainForm.cs | 19 +++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.MenuItems.cs b/BizHawk.MultiClient/MainForm.MenuItems.cs index 3038fd8e87..f86185d1b6 100644 --- a/BizHawk.MultiClient/MainForm.MenuItems.cs +++ b/BizHawk.MultiClient/MainForm.MenuItems.cs @@ -767,11 +767,6 @@ namespace BizHawk.MultiClient } } - private void undoSavestateToolStripMenuItem_Click(object sender, EventArgs e) - { - //TODO - } - private void screenshotToolStripMenuItem1_Click(object sender, EventArgs e) { TakeScreenshot(); @@ -878,9 +873,22 @@ namespace BizHawk.MultiClient else contextMenuStrip1.Items[7].Enabled = true; + string path = Global.Game.SaveStatePrefix + "." + "QuickSave" + SaveSlot.ToString() + ".State.bak"; + var file = new FileInfo(path); + if (file.Exists == true) + { + contextMenuStrip1.Items[13].Enabled = true; + contextMenuStrip1.Items[13].Text = "Undo Save to slot " + SaveSlot.ToString(); + contextMenuStrip1.Items[13].Image = BizHawk.MultiClient.Properties.Resources.undo; + } + else + { + contextMenuStrip1.Items[13].Enabled = false; + contextMenuStrip1.Items[13].Text = "Undo Savestate"; + contextMenuStrip1.Items[13].Image = BizHawk.MultiClient.Properties.Resources.undo; + } - //TODO: - contextMenuStrip1.Items[13].Enabled = false; + //contextMenuStrip1.Items[13].Enabled = false; } @@ -1296,5 +1304,12 @@ namespace BizHawk.MultiClient { Global.Config.BackupSavestates ^= true; } + + private void undoSavestateToolStripMenuItem_Click(object sender, EventArgs e) + { + string path = Global.Game.SaveStatePrefix + "." + "QuickSave" + SaveSlot.ToString() + ".State"; + SwapBackupSavestate(path); + Global.RenderPanel.AddMessage("Save slot " + SaveSlot.ToString() + " restored."); + } } } \ No newline at end of file diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9894cddc77..0b6b1326ce 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -2178,5 +2178,24 @@ namespace BizHawk.MultiClient AVIStatusLabel.Image = BizHawk.MultiClient.Properties.Resources.Blank; AVIStatusLabel.ToolTipText = ""; } + + private void SwapBackupSavestate(string path) + { + //Takes the .state and .bak files and swaps them + var state = new FileInfo(path); + var backup = new FileInfo(path + ".bak"); + var temp = new FileInfo(path + ".bak.tmp"); + + if (state.Exists == false) return; + if (backup.Exists == false) return; + if (temp.Exists == true) temp.Delete(); + + backup.CopyTo(path + ".bak.tmp"); + backup.Delete(); + state.CopyTo(path + ".bak"); + state.Delete(); + temp.CopyTo(path); + temp.Delete(); + } } } \ No newline at end of file