fully support read-only movie opening. I hope this fixes #453

This commit is contained in:
zeromus 2015-08-05 17:00:39 -05:00
parent a283b2d1b9
commit b981e00889
11 changed files with 46 additions and 33 deletions

View File

@ -19,7 +19,7 @@ namespace BizHawk.Client.Common
if (Path.GetExtension(path).EndsWith("bkm"))
{
var bkm = new BkmMovie(path);
bkm.Load();
bkm.Load(false);
// Hackery to fix how things used to work
if (bkm.SystemID == "GBC")

View File

@ -182,7 +182,7 @@ namespace BizHawk.Client.Common
public bool MovieLoad()
{
MovieControllerAdapter = Movie.LogGeneratorInstance().MovieControllerAdapter;
return Movie.Load();
return Movie.Load(false);
}
public void StopMovie(bool saveChanges = true)
@ -463,7 +463,7 @@ namespace BizHawk.Client.Common
{
if (!record) // The semantics of record is that we are starting a new movie, and even wiping a pre-existing movie with the same path, but non-record means we are loading an existing movie into playback mode
{
movie.Load();
movie.Load(false);
if (movie.SystemID != emulator.SystemId)
{
throw new MoviePlatformMismatchException(

View File

@ -32,7 +32,7 @@ namespace BizHawk.Client.Common
Write(backupName);
}
public virtual bool Load()
public virtual bool Load(bool preload)
{
var file = new FileInfo(Filename);
if (!file.Exists)
@ -158,7 +158,6 @@ namespace BizHawk.Client.Common
public bool PreLoadHeaderAndLength(HawkFile hawkFile)
{
// For now, preload simply loads everything
var file = new FileInfo(Filename);
if (!file.Exists)
{
@ -166,7 +165,7 @@ namespace BizHawk.Client.Common
}
Filename = file.FullName;
return Load();
return Load(true);
}
protected virtual void Write(string fn)

View File

@ -58,7 +58,7 @@ namespace BizHawk.Client.Common
Write(backupName);
}
public bool Load()
public bool Load(bool preload)
{
var file = new FileInfo(Filename);

View File

@ -34,6 +34,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
}
var tas = new TasMovie(newFilename, old.StartsFromSavestate);
tas.TasStateManager.MountWriteAccess();
for (var i = 0; i < old.InputLogLength; i++)
{

View File

@ -140,7 +140,7 @@ namespace BizHawk.Client.Common
break;
case ".BKM":
m.Filename = path;
m.Load();
m.Load(false);
break;
}
}

View File

@ -99,7 +99,7 @@ namespace BizHawk.Client.Common
/// Tells the movie to load the contents of Filename
/// </summary>
/// <returns>Return whether or not the file was successfully loaded</returns>
bool Load();
bool Load(bool preload);
/// <summary>
/// Instructs the movie to save the current contents to Filename

View File

@ -107,7 +107,7 @@ namespace BizHawk.Client.Common
Changes = false;
}
public override bool Load()
public override bool Load(bool preload)
{
var file = new FileInfo(Filename);
if (!file.Exists)
@ -221,16 +221,20 @@ namespace BizHawk.Client.Common
StateManager.Settings.PopulateFromString(tr.ReadToEnd());
});
if (StateManager.Settings.SaveStateHistory)
if(!preload)
{
bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
if (StateManager.Settings.SaveStateHistory)
{
StateManager.Load(br);
});
bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
{
StateManager.Load(br);
});
}
// Movie should always have a state at frame 0.
if (!this.StartsFromSavestate)
StateManager.Capture();
}
// Movie should always have a state at frame 0.
if (!this.StartsFromSavestate)
StateManager.Capture();
bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
{

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.Common
}
private Guid guid = Guid.NewGuid();
private readonly SortedList<int, byte[]> States = new SortedList<int, byte[]>();
private SortedList<int, byte[]> States = new SortedList<int, byte[]>();
private string statePath
{
get
@ -46,6 +46,7 @@ namespace BizHawk.Client.Common
}
}
private bool _isMountedForWrite;
private readonly TasMovie _movie;
private ulong _expectedStateSize = 0;
@ -80,6 +81,25 @@ namespace BizHawk.Client.Common
Settings = new TasStateManagerSettings(Global.Config.DefaultTasProjSettings);
accessed = new List<int>();
}
/// <summary>
/// Mounts this instance for write access. Prior to that it's read-only
/// </summary>
public void MountWriteAccess()
{
if (_isMountedForWrite)
return;
_isMountedForWrite = true;
if (Directory.Exists(statePath))
{
Directory.Delete(statePath, true); // To delete old files that may still exist.
}
Directory.CreateDirectory(statePath);
int limit = 0;
_expectedStateSize = (ulong)Core.SaveStateBinary().Length;
@ -90,20 +110,6 @@ namespace BizHawk.Client.Common
}
States = new SortedList<int, byte[]>(limit);
accessed = new List<int>();
}
/// <summary>
/// Mounts this instance for write access. Prior to that it's read-only
/// </summary>
public void MountWriteAccess()
{
if (Directory.Exists(statePath))
{
Directory.Delete(statePath, true); // To delete old files that may still exist.
}
Directory.CreateDirectory(statePath);
}
public TasStateManagerSettings Settings { get; set; }

View File

@ -30,6 +30,9 @@ namespace BizHawk.Client.EmuHawk
try
{
var tasmovie = (movie as TasMovie);
if (tasmovie != null)
tasmovie.TasStateManager.MountWriteAccess();
Global.MovieSession.QueueNewMovie(movie, record, Global.Emulator);
}
catch (MoviePlatformMismatchException ex)

View File

@ -407,7 +407,7 @@ namespace BizHawk.Client.EmuHawk
CurrentTasMovie.Filename = file.FullName;
try
{
CurrentTasMovie.Load();
CurrentTasMovie.Load(false);
}
catch
{