diff --git a/BizHawk.MultiClient/BinarySaveStates.cs b/BizHawk.MultiClient/BinarySaveStates.cs index 366f7d07c5..e27931bd2b 100644 --- a/BizHawk.MultiClient/BinarySaveStates.cs +++ b/BizHawk.MultiClient/BinarySaveStates.cs @@ -84,6 +84,11 @@ namespace BizHawk.MultiClient { return GetFileByName(BinaryStateFileNames.framebuffer, false, callback); } + + public void GetInputLogRequired(Action callback) + { + GetFileByName(BinaryStateFileNames.input, true, callback); + } } public class BinaryStateSaver : IDisposable diff --git a/BizHawk.MultiClient/MainForm.Movie.cs b/BizHawk.MultiClient/MainForm.Movie.cs index f18530ab4a..5e8f426d56 100644 --- a/BizHawk.MultiClient/MainForm.Movie.cs +++ b/BizHawk.MultiClient/MainForm.Movie.cs @@ -152,6 +152,14 @@ namespace BizHawk.MultiClient } private bool HandleMovieLoadState(string path) + { + using (var sr = new StreamReader(path)) + { + return HandleMovieLoadState(sr); + } + } + + private bool HandleMovieLoadState(StreamReader reader) { //Note, some of the situations in these IF's may be identical and could be combined but I intentionally separated it out for clarity if (!Global.MovieSession.Movie.IsActive) @@ -164,7 +172,7 @@ namespace BizHawk.MultiClient if (ReadOnly) { - if (!Global.MovieSession.Movie.CheckTimeLines(path, false)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, false)) { return false; //Timeline/GUID error } @@ -177,11 +185,12 @@ namespace BizHawk.MultiClient } else { - if (!Global.MovieSession.Movie.CheckTimeLines(path, true)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, true)) { return false; //GUID Error } - Global.MovieSession.Movie.LoadLogFromSavestateText(path); + reader.BaseStream.Position = 0; + Global.MovieSession.Movie.LoadLogFromSavestateText(reader); } } @@ -189,7 +198,7 @@ namespace BizHawk.MultiClient { if (ReadOnly) { - if (!Global.MovieSession.Movie.CheckTimeLines(path, false)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, false)) { return false; //Timeline/GUID error } @@ -197,13 +206,14 @@ namespace BizHawk.MultiClient } else { - if (!Global.MovieSession.Movie.CheckTimeLines(path, true)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, true)) { return false; //GUID Error } Global.MovieSession.Movie.SwitchToRecord(); SetMainformMovieInfo(); - Global.MovieSession.Movie.LoadLogFromSavestateText(path); + reader.BaseStream.Position = 0; + Global.MovieSession.Movie.LoadLogFromSavestateText(reader); } } else if (Global.MovieSession.Movie.IsFinished) @@ -211,7 +221,7 @@ namespace BizHawk.MultiClient if (ReadOnly) { { - if (!Global.MovieSession.Movie.CheckTimeLines(path, false)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, false)) { return false; //Timeline/GUID error } @@ -229,7 +239,7 @@ namespace BizHawk.MultiClient else { { - if (!Global.MovieSession.Movie.CheckTimeLines(path, true)) + if (!Global.MovieSession.Movie.CheckTimeLines(reader, true)) { return false; //GUID Error } @@ -237,7 +247,8 @@ namespace BizHawk.MultiClient { Global.MovieSession.Movie.StartRecording(); SetMainformMovieInfo(); - Global.MovieSession.Movie.LoadLogFromSavestateText(path); + reader.BaseStream.Position = 0; + Global.MovieSession.Movie.LoadLogFromSavestateText(reader); } } } diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9227f6550c..6d39dcfd18 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -2441,8 +2441,9 @@ namespace BizHawk.MultiClient delegate(Stream s) { StreamWriter sw = new StreamWriter(s); + // this never should have been a core's responsibility + sw.WriteLine("Frame {0}", Global.Emulator.Frame); HandleMovieSaveState(sw); - sw.WriteLine("Frame: {0}", Global.Emulator.Frame); sw.Flush(); }); } @@ -2485,9 +2486,19 @@ namespace BizHawk.MultiClient { try { - // binary mode + bool succeed = false; + if (Global.MovieSession.Movie.IsActive) - throw new Exception("NOT DONE YET BRO"); + { + bw.GetInputLogRequired( + delegate(Stream s) + { + StreamReader sr = new StreamReader(s); + succeed = HandleMovieLoadState(sr); + }); + if (!succeed) + goto cleanup; + } bw.GetCoreState( delegate(Stream s) @@ -2515,6 +2526,8 @@ namespace BizHawk.MultiClient } }); + + } finally { diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index 2f22220def..5bfd6d8419 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -797,10 +797,9 @@ namespace BizHawk.MultiClient return time; } - public bool CheckTimeLines(string path, bool OnlyGUID) + public bool CheckTimeLines(TextReader reader, bool OnlyGUID) { //This function will compare the movie data to the savestate movie data to see if they match - var reader = new StreamReader(path); MovieLog l = new MovieLog(); int stateFrame = 0; @@ -827,13 +826,13 @@ namespace BizHawk.MultiClient if (result == DialogResult.No) { - reader.Close(); + //reader.Close(); return false; } } else if (OnlyGUID) { - reader.Close(); + //reader.Close(); return true; } } @@ -861,11 +860,11 @@ namespace BizHawk.MultiClient l.AppendFrame(line); } - reader.BaseStream.Position = 0; //Reset position because this stream may be read again by other code + //reader.BaseStream.Position = 0; //Reset position because this stream may be read again by other code if (OnlyGUID) { - reader.Close(); + //reader.Close(); return true; } @@ -880,7 +879,7 @@ namespace BizHawk.MultiClient //Future event error MessageBox.Show("The savestate is from frame " + l.Length.ToString() + " which is greater than the current movie length of " + Log.Length.ToString() + ".\nCan not load this savestate.", "Future event Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - reader.Close(); + //reader.Close(); return false; } for (int x = 0; x < stateFrame; x++) @@ -892,7 +891,7 @@ namespace BizHawk.MultiClient //TimeLine Error MessageBox.Show("The savestate input does not match the movie input at frame " + (x + 1).ToString() + ".", "Timeline Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - reader.Close(); + //reader.Close(); return false; } } @@ -914,7 +913,7 @@ namespace BizHawk.MultiClient Mode = MOVIEMODE.PLAY; } - reader.Close(); + //reader.Close(); return true; }