2013-04-15 02:14:14 +00:00
|
|
|
|
using System.IO;
|
2014-01-08 03:53:53 +00:00
|
|
|
|
using System.Linq;
|
2011-07-01 01:28:25 +00:00
|
|
|
|
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2013-10-27 07:54:00 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2013-11-01 19:55:03 +00:00
|
|
|
|
public class SaveSlotManager
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
private readonly bool[] _slots = new bool[10];
|
|
|
|
|
private readonly bool[] _redo = new bool[10];
|
2011-07-01 01:28:25 +00:00
|
|
|
|
|
2013-11-01 19:55:03 +00:00
|
|
|
|
public SaveSlotManager()
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if (Global.Game == null || Global.Emulator == null)
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2013-11-01 19:55:03 +00:00
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
_slots[i] = false;
|
2013-11-01 19:55:03 +00:00
|
|
|
|
}
|
2014-01-08 03:53:53 +00:00
|
|
|
|
|
2011-07-01 01:28:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-08 03:53:53 +00:00
|
|
|
|
|
2013-11-01 19:55:03 +00:00
|
|
|
|
for (int i = 0; i < 10; i++)
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2013-11-01 19:55:03 +00:00
|
|
|
|
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)
|
2013-11-01 19:55:03 +00:00
|
|
|
|
{
|
2011-07-01 01:28:25 +00:00
|
|
|
|
file.Directory.Create();
|
2013-11-01 19:55:03 +00:00
|
|
|
|
}
|
2014-01-08 03:53:53 +00:00
|
|
|
|
|
|
|
|
|
_slots[i] = file.Exists;
|
2011-07-01 01:28:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 07:54:00 +00:00
|
|
|
|
public bool HasSavestateSlots
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2013-10-27 07:54:00 +00:00
|
|
|
|
get
|
2011-07-01 01:28:25 +00:00
|
|
|
|
{
|
2013-10-27 07:54:00 +00:00
|
|
|
|
Update();
|
2014-01-08 03:53:53 +00:00
|
|
|
|
return _slots.Any(slot => slot);
|
2011-07-01 01:28:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasSlot(int slot)
|
|
|
|
|
{
|
2013-11-03 02:51:21 +00:00
|
|
|
|
if (Global.Emulator is NullEmulator)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 19:55:03 +00:00
|
|
|
|
if (slot < 0 || slot > 10)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-01 01:28:25 +00:00
|
|
|
|
|
|
|
|
|
Update();
|
2014-01-08 03:53:53 +00:00
|
|
|
|
return _slots[slot];
|
2011-07-01 01:28:25 +00:00
|
|
|
|
}
|
2011-07-31 23:25:00 +00:00
|
|
|
|
|
|
|
|
|
public void ClearRedoList()
|
|
|
|
|
{
|
2013-11-01 19:55:03 +00:00
|
|
|
|
for (int i = 0; i < 10; i++)
|
2011-07-31 23:25:00 +00:00
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
|
_redo[i] = false;
|
2011-07-31 23:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleRedo(int slot)
|
|
|
|
|
{
|
|
|
|
|
if (slot < 0 || slot > 9)
|
2013-11-01 19:55:03 +00:00
|
|
|
|
{
|
2011-07-31 23:25:00 +00:00
|
|
|
|
return;
|
2013-11-01 19:55:03 +00:00
|
|
|
|
}
|
2011-07-31 23:25:00 +00:00
|
|
|
|
|
2014-01-08 03:53:53 +00:00
|
|
|
|
_redo[slot] ^= true;
|
2011-07-31 23:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsRedo(int slot)
|
|
|
|
|
{
|
|
|
|
|
if (slot < 0 || slot > 9)
|
2013-11-01 19:55:03 +00:00
|
|
|
|
{
|
2011-07-31 23:25:00 +00:00
|
|
|
|
return false;
|
2013-11-01 19:55:03 +00:00
|
|
|
|
}
|
2011-07-31 23:25:00 +00:00
|
|
|
|
|
2014-01-08 03:53:53 +00:00
|
|
|
|
return _redo[slot];
|
2011-07-31 23:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
ClearRedoList();
|
|
|
|
|
Update();
|
|
|
|
|
}
|
2013-12-24 22:20:18 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2011-07-01 01:28:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|