diff --git a/BizHawk.Client.Common/movie/MovieService.cs b/BizHawk.Client.Common/movie/MovieService.cs index 5a27e9bcbc..984e97124a 100644 --- a/BizHawk.Client.Common/movie/MovieService.cs +++ b/BizHawk.Client.Common/movie/MovieService.cs @@ -13,9 +13,17 @@ namespace BizHawk.Client.Common public static IMovie Get(string path) { // TODO: open the file and determine the format, and instantiate the appropriate implementation - // Currently we just assume it is a bkm implementation + // Currently we just use the file extension // TODO: change IMovies to take HawkFiles only and not path - return new BkmMovie(path); + // TOOD: tasproj + if (Path.GetExtension(path).EndsWith("bk2")) + { + return new Bk2Movie(path); + } + else + { + return new BkmMovie(path); + } } /// @@ -23,7 +31,15 @@ namespace BizHawk.Client.Common /// public static string DefaultExtension { - get { return "bkm"; } + get + { + if (VersionInfo.DeveloperBuild) + { + return "bk2"; + } + + return "bkm"; + } } /// @@ -58,6 +74,11 @@ namespace BizHawk.Client.Common { get { + if (VersionInfo.DeveloperBuild) + { + return new Bk2Movie(); + } + return new BkmMovie(); } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index cbb794df07..b10b24c9a3 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -50,20 +50,97 @@ namespace BizHawk.Client.Common return false; } - Header.Clear(); - _log.Clear(); - Subtitles.Clear(); - Comments.Clear(); - _syncSettingsJson = string.Empty; - _savestateBlob = string.Empty; + ClearBeforeLoad(); + + bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + var pair = line.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); + Header.Add(pair[0], pair[1]); + } + } + }); + + bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + Comments.Add(line); + } + } + }); + + bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + Subtitles.AddFromString(line); + } + } + }); + + bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + _syncSettingsJson = line; + } + } + }); + + bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (line != null && line.StartsWith("|")) + { + _log.AppendFrame(line); + } + } + }); + + // Movies 2.0 TODO: be smart about text or binary state + if (StartsFromSavestate) + { + bl.GetLump(BinaryStateLump.CorestateText, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + // TODO: savestate + } + }); + } } - throw new NotImplementedException(); + return true; } public bool PreLoadText(HawkFile hawkFile) { - throw new NotImplementedException(); + // For now, preload simply loads everything + var file = new FileInfo(Filename); + if (!file.Exists) + { + return false; + } + + Filename = file.FullName; + return Load(); } private void Write(string fn) @@ -74,12 +151,13 @@ namespace BizHawk.Client.Common using (BinaryStateSaver bs = new BinaryStateSaver(fs)) { bs.PutLump(BinaryStateLump.Movieheader, (tw) => tw.WriteLine(Header.ToString())); - bs.PutLump(BinaryStateLump.Input, (tw) => tw.WriteLine(RawInputLog())); - bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString())); bs.PutLump(BinaryStateLump.Subtitles, (tw) => tw.WriteLine(Subtitles.ToString())); bs.PutLump(BinaryStateLump.SyncSettings, (tw) => tw.WriteLine(_syncSettingsJson)); + bs.PutLump(BinaryStateLump.Input, (tw) => tw.WriteLine(RawInputLog())); + + if (StartsFromSavestate) { bs.PutLump(BinaryStateLump.CorestateText, (tw) => tw.WriteLine(SavestateBinaryBase64Blob)); @@ -88,5 +166,15 @@ namespace BizHawk.Client.Common Changes = false; } + + private void ClearBeforeLoad() + { + Header.Clear(); + _log.Clear(); + Subtitles.Clear(); + Comments.Clear(); + _syncSettingsJson = string.Empty; + _savestateBlob = string.Empty; + } } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 1b853c339b..3dfb738220 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -11,6 +11,7 @@ namespace BizHawk.Client.Common { public partial class Bk2Movie : IMovie { + // Movies 2.0 TODO: save and load loopOffset, put in header object private readonly PlatformFrameRates _frameRates = new PlatformFrameRates(); private bool _makeBackup = true; private int? _loopOffset;