BizHawk/BizHawk.Client.Common/SaveSlotManager.cs

131 lines
2.1 KiB
C#
Raw Normal View History

2013-04-15 02:14:14 +00:00
using System.IO;
2014-01-08 03:53:53 +00:00
using System.Linq;
using BizHawk.Emulation.Common;
2013-10-27 07:54:00 +00:00
namespace BizHawk.Client.Common
{
public class SaveSlotManager
{
2014-01-08 03:53:53 +00:00
private readonly bool[] _slots = new bool[10];
private readonly bool[] _redo = new bool[10];
public SaveSlotManager()
{
Update();
}
public void Update()
{
if (Global.Game == null || Global.Emulator == null)
{
for (int i = 0; i < 10; i++)
{
2014-01-08 03:53:53 +00:00
_slots[i] = false;
}
2014-01-08 03:53:53 +00:00
return;
}
2014-01-08 03:53:53 +00:00
for (int i = 0; i < 10; i++)
{
var file = new FileInfo(
PathManager.SaveStatePrefix(Global.Game) + "." + "QuickSave" + i + ".State"
);
2013-04-15 02:14:14 +00:00
if (file.Directory != null && file.Directory.Exists == false)
{
file.Directory.Create();
}
2014-01-08 03:53:53 +00:00
_slots[i] = file.Exists;
}
}
2013-10-27 07:54:00 +00:00
public bool HasSavestateSlots
{
2013-10-27 07:54:00 +00:00
get
{
2013-10-27 07:54:00 +00:00
Update();
2014-01-08 03:53:53 +00:00
return _slots.Any(slot => slot);
}
}
public bool HasSlot(int slot)
{
if (Global.Emulator is NullEmulator)
{
return false;
}
if (slot < 0 || slot > 10)
{
return false;
}
Update();
2014-01-08 03:53:53 +00:00
return _slots[slot];
}
public void ClearRedoList()
{
for (int i = 0; i < 10; i++)
{
2014-01-08 03:53:53 +00:00
_redo[i] = false;
}
}
public void ToggleRedo(int slot)
{
if (slot < 0 || slot > 9)
{
return;
}
2014-01-08 03:53:53 +00:00
_redo[slot] ^= true;
}
public bool IsRedo(int slot)
{
if (slot < 0 || slot > 9)
{
return false;
}
2014-01-08 03:53:53 +00:00
return _redo[slot];
}
public void Clear()
{
ClearRedoList();
Update();
}
public 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 || !backup.Exists)
{
return;
}
if (temp.Exists)
{
temp.Delete();
}
backup.CopyTo(path + ".bak.tmp");
backup.Delete();
state.CopyTo(path + ".bak");
state.Delete();
temp.CopyTo(path);
temp.Delete();
ToggleRedo(Global.Config.SaveSlot);
}
}
}