more 2.0 work

This commit is contained in:
adelikat 2014-06-14 20:17:07 +00:00
parent c08e6bbf93
commit 1fcc105293
8 changed files with 31 additions and 23 deletions

View File

@ -225,7 +225,7 @@ namespace BizHawk.Client.Common
/// ///
/// </summary> /// </summary>
/// <param name="s">not closed when finished!</param> /// <param name="s">not closed when finished!</param>
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) _zip = new ZipOutputStream(s)
{ {
@ -234,7 +234,10 @@ namespace BizHawk.Client.Common
}; };
_zip.SetLevel(5); _zip.SetLevel(5);
PutLump(BinaryStateLump.Versiontag, WriteVersion); if (stateVersionTag)
{
PutLump(BinaryStateLump.Versiontag, WriteVersion);
}
} }
public void PutLump(BinaryStateLump lump, Action<Stream> callback) public void PutLump(BinaryStateLump lump, Action<Stream> callback)

View File

@ -16,11 +16,14 @@ namespace BizHawk.Client.Common
// TODO: open the file and determine the format, and instantiate the appropriate implementation // TODO: open the file and determine the format, and instantiate the appropriate implementation
// Currently we just use the file extension // Currently we just use the file extension
// TODO: change IMovies to take HawkFiles only and not path // TODO: change IMovies to take HawkFiles only and not path
// TOOD: tasproj
if (Path.GetExtension(path).EndsWith("bk2")) if (Path.GetExtension(path).EndsWith("bk2"))
{ {
return new Bk2Movie(path); return new Bk2Movie(path);
} }
else if (Path.GetExtension(path).EndsWith("tasproj"))
{
return new TasMovie(path);
}
else else
{ {
return new BkmMovie(path); return new BkmMovie(path);

View File

@ -148,10 +148,8 @@ namespace BizHawk.Client.Common
private void Write(string fn) 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 (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.Movieheader, (tw) => tw.WriteLine(Header.ToString()));
bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString())); bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString()));

View File

@ -14,8 +14,8 @@ namespace BizHawk.Client.Common
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates(); private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
private bool _makeBackup = true; private bool _makeBackup = true;
public Bk2Movie(string filename, bool startsFromSavestate = false) public Bk2Movie(string filename)
: this(startsFromSavestate) : this()
{ {
Subtitles = new SubtitleList(); Subtitles = new SubtitleList();
Comments = new List<string>(); Comments = new List<string>();
@ -24,18 +24,20 @@ namespace BizHawk.Client.Common
Filename = filename; Filename = filename;
} }
public Bk2Movie(bool startsFromSavestate = false) public Bk2Movie()
{ {
Filename = string.Empty; Filename = string.Empty;
StartsFromSavestate = startsFromSavestate;
IsCountingRerecords = true; IsCountingRerecords = true;
_mode = Moviemode.Inactive; _mode = Moviemode.Inactive;
_makeBackup = true; _makeBackup = true;
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0.0";
} }
public string Filename { get; set; } public string Filename { get; set; }
public string PreferredExtension { get { return "bk2"; } } public string PreferredExtension { get { return "bk2"; } }
public bool Changes { get; private set; } public bool Changes { get; private set; }
public bool IsCountingRerecords { get; set; } public bool IsCountingRerecords { get; set; }

View File

@ -10,21 +10,20 @@ namespace BizHawk.Client.Common
private bool _changes; private bool _changes;
private int? _loopOffset; private int? _loopOffset;
public BkmMovie(string filename, bool startsFromSavestate = false) public BkmMovie(string filename)
: this(startsFromSavestate) : this()
{ {
Rerecords = 0; Rerecords = 0;
Filename = filename; Filename = filename;
Loaded = !string.IsNullOrWhiteSpace(filename); Loaded = !string.IsNullOrWhiteSpace(filename);
} }
public BkmMovie(bool startsFromSavestate = false) public BkmMovie()
{ {
Header = new BkmHeader(); Header = new BkmHeader();
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v0.0.1"; Header[HeaderKeys.MOVIEVERSION] = "BizHawk v0.0.1";
Filename = string.Empty; Filename = string.Empty;
_preloadFramecount = 0; _preloadFramecount = 0;
StartsFromSavestate = startsFromSavestate;
IsCountingRerecords = true; IsCountingRerecords = true;
_mode = Moviemode.Inactive; _mode = Moviemode.Inactive;

View File

@ -52,7 +52,6 @@ namespace BizHawk.Client.Common
/// <summary> /// <summary>
/// Sync Settings from the Core /// 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
/// </summary> /// </summary>
string SyncSettingsJson { get; set; } string SyncSettingsJson { get; set; }

View File

@ -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) public void ToggleButton(int frame, string buttonName)
{ {
@ -71,17 +73,17 @@ namespace BizHawk.Client.Common
#region IMovie Implementation #region IMovie Implementation
public TasMovie(string filename, bool startsFromSavestate = false) public TasMovie(string filename)
: this(startsFromSavestate) : this()
{ {
Filename = filename; Filename = filename;
} }
public TasMovie(bool startsFromSavestate = false) public TasMovie()
{ {
_mg = MnemonicGeneratorFactory.Generate(); _mg = MnemonicGeneratorFactory.Generate();
Filename = string.Empty; Filename = string.Empty;
Header = new BkmHeader { StartsFromSavestate = startsFromSavestate }; Header = new BkmHeader();
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0"; Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0";
_records = new MovieRecordList(); _records = new MovieRecordList();
_mode = Moviemode.Inactive; _mode = Moviemode.Inactive;

View File

@ -257,9 +257,9 @@ namespace BizHawk.Client.EmuHawk
foreach(var subdir in Directory.GetDirectories(dp)) foreach(var subdir in Directory.GetDirectories(dp))
dpTodo.Enqueue(subdir); dpTodo.Enqueue(subdir);
// Movies 2.0 TODO: add tasproj, hardcoded is okay here
//add movies //add movies
fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension)); fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension));
fpTodo.AddRange(Directory.GetFiles(dp, "*." + TasMovie.Extension));
} }
//in parallel, scan each movie //in parallel, scan each movie
@ -601,7 +601,9 @@ namespace BizHawk.Client.EmuHawk
var ofd = new OpenFileDialog var ofd = new OpenFileDialog
{ {
// Movies 2.0 TODO - add tasproj in addition to default, hardcoded is fine in this case // 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) InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null)
}; };