From 1fcc10529355eab0ecce5844dc2557bd28858a8d Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 14 Jun 2014 20:17:07 +0000 Subject: [PATCH] more 2.0 work --- BizHawk.Client.Common/BinarySaveStates.cs | 7 +++++-- BizHawk.Client.Common/movie/MovieService.cs | 5 ++++- BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs | 4 +--- BizHawk.Client.Common/movie/bk2/Bk2Movie.cs | 12 +++++++----- BizHawk.Client.Common/movie/bkm/BkmMovie.cs | 7 +++---- BizHawk.Client.Common/movie/interfaces/IMovie.cs | 1 - BizHawk.Client.Common/movie/tasproj/TasMovie.cs | 12 +++++++----- BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 6 ++++-- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index 7b8e13cb6c..aca8078a59 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -225,7 +225,7 @@ namespace BizHawk.Client.Common /// /// /// not closed when finished! - public BinaryStateSaver(Stream s) + public BinaryStateSaver(Stream s, bool stateVersionTag = true) // stateVersionTag is a hack for reusing this for movie code { _zip = new ZipOutputStream(s) { @@ -234,7 +234,10 @@ namespace BizHawk.Client.Common }; _zip.SetLevel(5); - PutLump(BinaryStateLump.Versiontag, WriteVersion); + if (stateVersionTag) + { + PutLump(BinaryStateLump.Versiontag, WriteVersion); + } } public void PutLump(BinaryStateLump lump, Action callback) diff --git a/BizHawk.Client.Common/movie/MovieService.cs b/BizHawk.Client.Common/movie/MovieService.cs index be32616be6..25207b3577 100644 --- a/BizHawk.Client.Common/movie/MovieService.cs +++ b/BizHawk.Client.Common/movie/MovieService.cs @@ -16,11 +16,14 @@ namespace BizHawk.Client.Common // TODO: open the file and determine the format, and instantiate the appropriate implementation // Currently we just use the file extension // TODO: change IMovies to take HawkFiles only and not path - // TOOD: tasproj if (Path.GetExtension(path).EndsWith("bk2")) { return new Bk2Movie(path); } + else if (Path.GetExtension(path).EndsWith("tasproj")) + { + return new TasMovie(path); + } else { return new BkmMovie(path); diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index 69d6dd2445..2097bd9be9 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -148,10 +148,8 @@ namespace BizHawk.Client.Common private void Write(string fn) { - // Movies 2.0 TODO: Save and Load Movie version - // there's a lot of common code here with SavestateManager. refactor? using (FileStream fs = new FileStream(Filename, FileMode.Create, FileAccess.Write)) - using (BinaryStateSaver bs = new BinaryStateSaver(fs)) + using (BinaryStateSaver bs = new BinaryStateSaver(fs, false)) { bs.PutLump(BinaryStateLump.Movieheader, (tw) => tw.WriteLine(Header.ToString())); bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString())); diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 62681007e4..30f925fe10 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -14,8 +14,8 @@ namespace BizHawk.Client.Common private readonly PlatformFrameRates _frameRates = new PlatformFrameRates(); private bool _makeBackup = true; - public Bk2Movie(string filename, bool startsFromSavestate = false) - : this(startsFromSavestate) + public Bk2Movie(string filename) + : this() { Subtitles = new SubtitleList(); Comments = new List(); @@ -24,18 +24,20 @@ namespace BizHawk.Client.Common Filename = filename; } - public Bk2Movie(bool startsFromSavestate = false) + public Bk2Movie() { Filename = string.Empty; - StartsFromSavestate = startsFromSavestate; - IsCountingRerecords = true; _mode = Moviemode.Inactive; _makeBackup = true; + + Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0.0"; } public string Filename { get; set; } + public string PreferredExtension { get { return "bk2"; } } + public bool Changes { get; private set; } public bool IsCountingRerecords { get; set; } diff --git a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs index bc92dc6f71..5e7db8ec62 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs @@ -10,21 +10,20 @@ namespace BizHawk.Client.Common private bool _changes; private int? _loopOffset; - public BkmMovie(string filename, bool startsFromSavestate = false) - : this(startsFromSavestate) + public BkmMovie(string filename) + : this() { Rerecords = 0; Filename = filename; Loaded = !string.IsNullOrWhiteSpace(filename); } - public BkmMovie(bool startsFromSavestate = false) + public BkmMovie() { Header = new BkmHeader(); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v0.0.1"; Filename = string.Empty; _preloadFramecount = 0; - StartsFromSavestate = startsFromSavestate; IsCountingRerecords = true; _mode = Moviemode.Inactive; diff --git a/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/BizHawk.Client.Common/movie/interfaces/IMovie.cs index b1bc5cbe0b..4ef3ce31b8 100644 --- a/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -52,7 +52,6 @@ namespace BizHawk.Client.Common /// /// Sync Settings from the Core - /// Movies 2.0 TODO: instead of enforcing a Json transfer, there should be methods that get and receive SyncSettings objects and let the implementation decide the format /// string SyncSettingsJson { get; set; } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 2893877620..7dc1db6f06 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -33,7 +33,9 @@ namespace BizHawk.Client.Common } } - public string PreferredExtension { get { return "tasproj"; } } + public string PreferredExtension { get { return Extension; } } + + public const string Extension = "tasproj"; public void ToggleButton(int frame, string buttonName) { @@ -71,17 +73,17 @@ namespace BizHawk.Client.Common #region IMovie Implementation - public TasMovie(string filename, bool startsFromSavestate = false) - : this(startsFromSavestate) + public TasMovie(string filename) + : this() { Filename = filename; } - public TasMovie(bool startsFromSavestate = false) + public TasMovie() { _mg = MnemonicGeneratorFactory.Generate(); Filename = string.Empty; - Header = new BkmHeader { StartsFromSavestate = startsFromSavestate }; + Header = new BkmHeader(); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0"; _records = new MovieRecordList(); _mode = Moviemode.Inactive; diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 56bc4bcfbf..b3c2a25eee 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -257,9 +257,9 @@ namespace BizHawk.Client.EmuHawk foreach(var subdir in Directory.GetDirectories(dp)) dpTodo.Enqueue(subdir); - // Movies 2.0 TODO: add tasproj, hardcoded is okay here //add movies fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension)); + fpTodo.AddRange(Directory.GetFiles(dp, "*." + TasMovie.Extension)); } //in parallel, scan each movie @@ -601,7 +601,9 @@ namespace BizHawk.Client.EmuHawk var ofd = new OpenFileDialog { // Movies 2.0 TODO - add tasproj in addition to default, hardcoded is fine in this case - Filter = "Movie Files (*." + MovieService.DefaultExtension + ")|*." + MovieService.DefaultExtension + "|All Files|*.*", + Filter = "Movie Files (*." + MovieService.DefaultExtension + ")|*." + MovieService.DefaultExtension + + "|TAS project Files (*." + TasMovie.Extension + ")|*." + TasMovie.Extension + + "|All Files|*.*", InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null) };