properly use TasMovie.Session - fixes #1771

This commit is contained in:
adelikat 2020-01-12 10:55:15 -06:00
parent 7062ba5b6a
commit eaca35d3d0
6 changed files with 16 additions and 30 deletions

View File

@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
namespace BizHawk.Client.Common
{
@ -12,13 +9,13 @@ namespace BizHawk.Client.Common
private ZipArchive _archive;
private readonly CompressionLevel _level;
public FrameworkZipWriter(string path, int compressionlevel)
public FrameworkZipWriter(string path, int compressionLevel)
{
_archive = new ZipArchive(new FileStream(path, FileMode.Create, FileAccess.Write),
ZipArchiveMode.Create, false);
if (compressionlevel == 0)
if (compressionLevel == 0)
_level = CompressionLevel.NoCompression;
else if (compressionlevel < 5)
else if (compressionLevel < 5)
_level = CompressionLevel.Fastest;
else
_level = CompressionLevel.Optimal;
@ -26,10 +23,8 @@ namespace BizHawk.Client.Common
public void WriteItem(string name, Action<Stream> callback)
{
using (var stream = _archive.CreateEntry(name, _level).Open())
{
callback(stream);
}
using var stream = _archive.CreateEntry(name, _level).Open();
callback(stream);
}
public void Dispose()

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.Common
protected override void Write(string fn, bool backup = false)
{
var file = new FileInfo(fn);
if (!file.Directory.Exists)
if (file.Directory != null && !file.Directory.Exists)
{
Directory.CreateDirectory(file.Directory.ToString());
}
@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
if (TasStateManager.Settings.SaveStateHistory && !backup)
{
bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => TasStateManager.Save(bw));
bs.PutLump(BinaryStateLump.StateHistory, bw => TasStateManager.Save(bw));
}
}

View File

@ -56,7 +56,7 @@ namespace BizHawk.Client.Common
ChangeLog = new TasMovieChangeLog(this);
TasStateManager = new TasStateManager(this);
Session = new TasSession(this);
Session = new TasSession();
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
Markers = new TasMovieMarkerList(this);
Markers.CollectionChanged += Markers_CollectionChanged;

View File

@ -1,25 +1,14 @@
using System;
using System.Text;
namespace BizHawk.Client.Common
namespace BizHawk.Client.Common
{
public class TasSession
{
private readonly TasMovie _movie;
public int CurrentFrame { get; private set; }
public int CurrentBranch { get; private set; }
public int CurrentFrame { get; set; }
public int CurrentBranch { get; set; } = -1;
public TasSession(TasMovie movie)
public void UpdateValues(int frame, int currentBranch)
{
_movie = movie;
CurrentFrame = 0;
CurrentBranch = -1;
}
public void UpdateValues()
{
CurrentFrame = Global.Emulator.Frame;
CurrentBranch = _movie.CurrentBranch;
CurrentFrame = frame;
CurrentBranch = currentBranch;
}
}
}

View File

@ -145,6 +145,7 @@ namespace BizHawk.Client.EmuHawk
Movie.AddBranch(branch);
BranchView.RowCount = Movie.Branches.Count;
Movie.CurrentBranch = Movie.Branches.Count - 1;
Movie.Session.UpdateValues(Global.Emulator.Frame, Movie.CurrentBranch); // TODO: pass in emulator dependency
BranchView.ScrollToIndex(Movie.CurrentBranch);
Select(Movie.CurrentBranch, true);
BranchView.Refresh();

View File

@ -51,6 +51,7 @@ namespace BizHawk.Client.EmuHawk
refreshNeeded = AutoAdjustInput();
}
CurrentTasMovie.Session.UpdateValues(Emulator.Frame, CurrentTasMovie.CurrentBranch);
MaybeFollowCursor();
if (TasView.IsPartiallyVisible(Emulator.Frame) || TasView.IsPartiallyVisible(_lastRefresh))