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>
/// <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)
{
@ -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<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
// 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);

View File

@ -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()));

View File

@ -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<string>();
@ -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; }

View File

@ -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;

View File

@ -52,7 +52,6 @@ namespace BizHawk.Client.Common
/// <summary>
/// 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>
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)
{
@ -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;

View File

@ -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)
};