BizHawk/BizHawk.Client.Common/SaveSlotManager.cs

103 lines
2.1 KiB
C#
Raw Normal View History

2013-04-15 02:14:14 +00:00
using System.IO;
2020-01-12 20:58:02 +00:00
using BizHawk.Common;
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];
Remove PathManager code that had dependencies on Globals (#1881) * move one usage of Firwmare method into Firmware config where it is better suited * PathManager - remove unused code * move some PathEntry specific logic out of PathManger and into PathEntryCollection extension methods * PathManager - detangle some exe pathing logic from Global.Config usage, clarify what a completely broken method should actuall do * move more logic from PathManager to PathEntryCollection extension method * move absolute path creation to PathEntryCollection, lots of refactoring and simplifying of PathEntries usage * simplify PathEntryColleciton usage more * simplify PathEntryCollection more * break PathEntry classes into separate files, a bit of cleanup * move Rom path logic out of PathManager into PathEntryCollectionExtensions * move config UseRecentForRoms and LastRomPath into PathEntries, note that this is a breaking change for previous configs, those values will revert back to default values * move SaveRamPath logic from PathManager to PathEntryCollections * move cheats path logic from PathManager to PathEntryCollection * move another method out of PathManager * move some Retro hacks to PathEntryCollections, exposes more implicit dependencies * move savestate logic out of PathManager to PathEntryCollection * move more logic out of PathManager * move some savestate logic out of PathManager, move most to MainForm where it is used, detangle some implicit dependencies from SaveSlotManager * rename method * move more logic from PathManager to PathCollectionEntry * movie final Global.Config.PathEntries logic out of PathManager and into PathEnties
2020-03-15 20:12:36 +00:00
public void Update(string saveStatePrefix)
{
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++)
{
if (Global.MovieSession.Movie is TasMovie tasMovie)
{
_slots[i] = i < tasMovie.Branches.Count;
}
else
{
Remove PathManager code that had dependencies on Globals (#1881) * move one usage of Firwmare method into Firmware config where it is better suited * PathManager - remove unused code * move some PathEntry specific logic out of PathManger and into PathEntryCollection extension methods * PathManager - detangle some exe pathing logic from Global.Config usage, clarify what a completely broken method should actuall do * move more logic from PathManager to PathEntryCollection extension method * move absolute path creation to PathEntryCollection, lots of refactoring and simplifying of PathEntries usage * simplify PathEntryColleciton usage more * simplify PathEntryCollection more * break PathEntry classes into separate files, a bit of cleanup * move Rom path logic out of PathManager into PathEntryCollectionExtensions * move config UseRecentForRoms and LastRomPath into PathEntries, note that this is a breaking change for previous configs, those values will revert back to default values * move SaveRamPath logic from PathManager to PathEntryCollections * move cheats path logic from PathManager to PathEntryCollection * move another method out of PathManager * move some Retro hacks to PathEntryCollections, exposes more implicit dependencies * move savestate logic out of PathManager to PathEntryCollection * move more logic out of PathManager * move some savestate logic out of PathManager, move most to MainForm where it is used, detangle some implicit dependencies from SaveSlotManager * rename method * move more logic from PathManager to PathCollectionEntry * movie final Global.Config.PathEntries logic out of PathManager and into PathEnties
2020-03-15 20:12:36 +00:00
var file = new FileInfo($"{saveStatePrefix}.QuickSave{i}.State");
if (file.Directory != null && file.Directory.Exists == false)
{
file.Directory.Create();
}
2014-01-08 03:53:53 +00:00
_slots[i] = file.Exists;
}
}
}
Remove PathManager code that had dependencies on Globals (#1881) * move one usage of Firwmare method into Firmware config where it is better suited * PathManager - remove unused code * move some PathEntry specific logic out of PathManger and into PathEntryCollection extension methods * PathManager - detangle some exe pathing logic from Global.Config usage, clarify what a completely broken method should actuall do * move more logic from PathManager to PathEntryCollection extension method * move absolute path creation to PathEntryCollection, lots of refactoring and simplifying of PathEntries usage * simplify PathEntryColleciton usage more * simplify PathEntryCollection more * break PathEntry classes into separate files, a bit of cleanup * move Rom path logic out of PathManager into PathEntryCollectionExtensions * move config UseRecentForRoms and LastRomPath into PathEntries, note that this is a breaking change for previous configs, those values will revert back to default values * move SaveRamPath logic from PathManager to PathEntryCollections * move cheats path logic from PathManager to PathEntryCollection * move another method out of PathManager * move some Retro hacks to PathEntryCollections, exposes more implicit dependencies * move savestate logic out of PathManager to PathEntryCollection * move more logic out of PathManager * move some savestate logic out of PathManager, move most to MainForm where it is used, detangle some implicit dependencies from SaveSlotManager * rename method * move more logic from PathManager to PathCollectionEntry * movie final Global.Config.PathEntries logic out of PathManager and into PathEnties
2020-03-15 20:12:36 +00:00
public bool HasSlot(int slot, string savestatePrefix)
{
if (!Global.Emulator.HasSavestates())
{
return false;
}
2020-01-12 20:58:02 +00:00
if (!0.RangeTo(10).Contains(slot))
{
return false;
}
Remove PathManager code that had dependencies on Globals (#1881) * move one usage of Firwmare method into Firmware config where it is better suited * PathManager - remove unused code * move some PathEntry specific logic out of PathManger and into PathEntryCollection extension methods * PathManager - detangle some exe pathing logic from Global.Config usage, clarify what a completely broken method should actuall do * move more logic from PathManager to PathEntryCollection extension method * move absolute path creation to PathEntryCollection, lots of refactoring and simplifying of PathEntries usage * simplify PathEntryColleciton usage more * simplify PathEntryCollection more * break PathEntry classes into separate files, a bit of cleanup * move Rom path logic out of PathManager into PathEntryCollectionExtensions * move config UseRecentForRoms and LastRomPath into PathEntries, note that this is a breaking change for previous configs, those values will revert back to default values * move SaveRamPath logic from PathManager to PathEntryCollections * move cheats path logic from PathManager to PathEntryCollection * move another method out of PathManager * move some Retro hacks to PathEntryCollections, exposes more implicit dependencies * move savestate logic out of PathManager to PathEntryCollection * move more logic out of PathManager * move some savestate logic out of PathManager, move most to MainForm where it is used, detangle some implicit dependencies from SaveSlotManager * rename method * move more logic from PathManager to PathCollectionEntry * movie final Global.Config.PathEntries logic out of PathManager and into PathEnties
2020-03-15 20:12:36 +00:00
Update(savestatePrefix);
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)
{
2020-01-12 20:58:02 +00:00
if (0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie)) _redo[slot] ^= true;
}
2020-01-12 20:58:02 +00:00
public bool IsRedo(int slot) => 0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie) && _redo[slot];
public void SwapBackupSavestate(string path)
{
// Takes the .state and .bak files and swaps them
var state = new FileInfo(path);
2019-03-20 05:01:12 +00:00
var backup = new FileInfo($"{path}.bak");
var temp = new FileInfo($"{path}.bak.tmp");
if (!state.Exists || !backup.Exists)
{
return;
}
if (temp.Exists)
{
temp.Delete();
}
2019-03-20 05:01:12 +00:00
backup.CopyTo($"{path}.bak.tmp");
backup.Delete();
2019-03-20 05:01:12 +00:00
state.CopyTo($"{path}.bak");
state.Delete();
temp.CopyTo(path);
temp.Delete();
ToggleRedo(Global.Config.SaveSlot);
}
}
}