Rewrite FlushSaveRAM to write the newest sram to disk first, then move older data.
Moved autosave timer sets to save/load sram methods Manual saves won't reset the autosave timer Remove excess ticks when lowering the autosave timer
This commit is contained in:
parent
89059673f0
commit
bdb197ac23
|
@ -453,22 +453,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
FlushSaveRAM();
|
FlushSaveRAM();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AutoFlushMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
switch (((ToolStripMenuItem)sender).Text)
|
|
||||||
{
|
|
||||||
case "Off": Global.Config.FlushSaveRamFrames = 0; break;
|
|
||||||
case "1s": Global.Config.FlushSaveRamFrames = 1 * 60; break;
|
|
||||||
case "5s": Global.Config.FlushSaveRamFrames = 5 * 60; break;
|
|
||||||
case "15s": Global.Config.FlushSaveRamFrames = 15 * 60; break;
|
|
||||||
case "30s": Global.Config.FlushSaveRamFrames = 30 * 60; break;
|
|
||||||
case "1m": Global.Config.FlushSaveRamFrames = 60 * 60; break;
|
|
||||||
case "5m": Global.Config.FlushSaveRamFrames = 300 * 60; break;
|
|
||||||
}
|
|
||||||
if (_flushSaveRamIn > Global.Config.FlushSaveRamFrames)
|
|
||||||
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReadonlyMenuItem_Click(object sender, EventArgs e)
|
private void ReadonlyMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleReadOnly();
|
ToggleReadOnly();
|
||||||
|
|
|
@ -406,8 +406,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
PauseEmulator();
|
PauseEmulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
|
||||||
|
|
||||||
// start dumping, if appropriate
|
// start dumping, if appropriate
|
||||||
if (argParse.cmdDumpType != null && argParse.cmdDumpName != null)
|
if (argParse.cmdDumpType != null && argParse.cmdDumpName != null)
|
||||||
{
|
{
|
||||||
|
@ -1418,6 +1416,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public PresentationPanel PresentationPanel { get; }
|
public PresentationPanel PresentationPanel { get; }
|
||||||
|
|
||||||
private int _flushSaveRamIn;
|
private int _flushSaveRamIn;
|
||||||
|
public int FlushSaveRamIn { get { return _flushSaveRamIn; } set { _flushSaveRamIn = value; } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private methods
|
#region Private methods
|
||||||
|
@ -1599,6 +1598,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
Emulator.AsSaveRam().StoreSaveRam(sram);
|
Emulator.AsSaveRam().StoreSaveRam(sram);
|
||||||
|
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
@ -1613,36 +1613,47 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
var path = PathManager.SaveRamPath(Global.Game);
|
var path = PathManager.SaveRamPath(Global.Game);
|
||||||
if (autosave)
|
if (autosave)
|
||||||
path=path.Insert(path.Length-8, ".autosave"); //becomes path\name.autosave.SaveRAM
|
|
||||||
var f = new FileInfo(path);
|
|
||||||
if (f.Directory != null && !f.Directory.Exists)
|
|
||||||
{
|
{
|
||||||
f.Directory.Create();
|
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
||||||
|
path = path.Insert(path.Length - 8, ".autosave"); //becomes path\name.autosave.SaveRAM
|
||||||
|
}
|
||||||
|
var file = new FileInfo(path);
|
||||||
|
var newPath = path + ".new";
|
||||||
|
var newFile = new FileInfo(newPath);
|
||||||
|
var backupPath = path + ".bak";
|
||||||
|
var backupFile = new FileInfo(backupPath);
|
||||||
|
if (file.Directory != null && !file.Directory.Exists)
|
||||||
|
{
|
||||||
|
file.Directory.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make backup first
|
var writer = new BinaryWriter(new FileStream(newPath, FileMode.Create, FileAccess.Write));
|
||||||
if (Global.Config.BackupSaveram && f.Exists)
|
|
||||||
{
|
|
||||||
var backup = path + ".bak";
|
|
||||||
var backupFile = new FileInfo(backup);
|
|
||||||
if (backupFile.Exists)
|
|
||||||
{
|
|
||||||
backupFile.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
f.CopyTo(backup);
|
|
||||||
}
|
|
||||||
|
|
||||||
var writer = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write));
|
|
||||||
var saveram = Emulator.AsSaveRam().CloneSaveRam();
|
var saveram = Emulator.AsSaveRam().CloneSaveRam();
|
||||||
|
|
||||||
if (saveram != null)
|
if (saveram != null)
|
||||||
{
|
{
|
||||||
writer.Write(saveram, 0, saveram.Length);
|
writer.Write(saveram, 0, saveram.Length);
|
||||||
}
|
}
|
||||||
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
|
||||||
|
|
||||||
writer.Close();
|
writer.Close();
|
||||||
|
|
||||||
|
if (file.Exists)
|
||||||
|
{
|
||||||
|
if (Global.Config.BackupSaveram)
|
||||||
|
{
|
||||||
|
if (backupFile.Exists)
|
||||||
|
{
|
||||||
|
backupFile.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
file.MoveTo(backupPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file.Delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newFile.MoveTo(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2912,13 +2923,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
Global.MovieSession.HandleMovieOnFrameLoop();
|
Global.MovieSession.HandleMovieOnFrameLoop();
|
||||||
|
|
||||||
if (Global.Config.AutosaveSaveRAM && Global.Config.FlushSaveRamFrames > 0)
|
if (Global.Config.AutosaveSaveRAM)
|
||||||
{
|
{
|
||||||
_flushSaveRamIn -= 1;
|
if (FlushSaveRamIn-- <= 0)
|
||||||
if (_flushSaveRamIn <= 0)
|
|
||||||
{
|
{
|
||||||
FlushSaveRAM(true);
|
FlushSaveRAM(true);
|
||||||
_flushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// why not skip audio if the user doesnt want sound
|
// why not skip audio if the user doesnt want sound
|
||||||
|
|
|
@ -89,6 +89,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Global.Config.BackupSaveram = BackupSRamCheckbox.Checked;
|
Global.Config.BackupSaveram = BackupSRamCheckbox.Checked;
|
||||||
Global.Config.AutosaveSaveRAM = AutosaveSRAMCheckbox.Checked;
|
Global.Config.AutosaveSaveRAM = AutosaveSRAMCheckbox.Checked;
|
||||||
Global.Config.FlushSaveRamFrames = AutosaveSaveRAMSeconds * 60;
|
Global.Config.FlushSaveRamFrames = AutosaveSaveRAMSeconds * 60;
|
||||||
|
if (GlobalWin.MainForm.FlushSaveRamIn > Global.Config.FlushSaveRamFrames)
|
||||||
|
GlobalWin.MainForm.FlushSaveRamIn = Global.Config.FlushSaveRamFrames;
|
||||||
Global.Config.SkipLagFrame = FrameAdvSkipLagCheckbox.Checked;
|
Global.Config.SkipLagFrame = FrameAdvSkipLagCheckbox.Checked;
|
||||||
Global.Config.WIN32_CONSOLE = LogWindowAsConsoleCheckbox.Checked;
|
Global.Config.WIN32_CONSOLE = LogWindowAsConsoleCheckbox.Checked;
|
||||||
Global.Config.RunLuaDuringTurbo = LuaDuringTurboCheckbox.Checked;
|
Global.Config.RunLuaDuringTurbo = LuaDuringTurboCheckbox.Checked;
|
||||||
|
|
Loading…
Reference in New Issue