Move MovieService.Get to IMovieSession, and require an IMovieSession in Bk2Movie and TasMovie ctors, refactor accordingly
This commit is contained in:
parent
863d022bc5
commit
55bb627550
|
@ -18,7 +18,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
||||||
public static ITasMovie ToTasMovie(this IMovie old)
|
public static ITasMovie ToTasMovie(this IMovie old)
|
||||||
{
|
{
|
||||||
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
||||||
var tas = (ITasMovie)MovieService.Get(newFilename);
|
var tas = (ITasMovie)old.Session.Get(newFilename);
|
||||||
tas.CopyLog(old.GetLogEntries());
|
tas.CopyLog(old.GetLogEntries());
|
||||||
|
|
||||||
old.Truncate(0); // Trying to minimize ram usage
|
old.Truncate(0); // Trying to minimize ram usage
|
||||||
|
@ -53,7 +53,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
||||||
|
|
||||||
public static IMovie ToBk2(this IMovie old)
|
public static IMovie ToBk2(this IMovie old)
|
||||||
{
|
{
|
||||||
var bk2 = MovieService.Get(old.Filename.Replace(old.PreferredExtension, Bk2Movie.Extension));
|
var bk2 = old.Session.Get(old.Filename.Replace(old.PreferredExtension, Bk2Movie.Extension));
|
||||||
bk2.CopyLog(old.GetLogEntries());
|
bk2.CopyLog(old.GetLogEntries());
|
||||||
|
|
||||||
bk2.HeaderEntries.Clear();
|
bk2.HeaderEntries.Clear();
|
||||||
|
@ -87,7 +87,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
||||||
{
|
{
|
||||||
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
||||||
|
|
||||||
var tas = (ITasMovie)MovieService.Get(newFilename);
|
var tas = (ITasMovie)old.Session.Get(newFilename);
|
||||||
tas.BinarySavestate = savestate;
|
tas.BinarySavestate = savestate;
|
||||||
tas.LagLog.Clear();
|
tas.LagLog.Clear();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
||||||
{
|
{
|
||||||
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
string newFilename = ConvertFileNameToTasMovie(old.Filename);
|
||||||
|
|
||||||
var tas = (ITasMovie) MovieService.Get(newFilename);
|
var tas = (ITasMovie)old.Session.Get(newFilename);
|
||||||
tas.SaveRam = saveRam;
|
tas.SaveRam = saveRam;
|
||||||
tas.TasStateManager.Clear();
|
tas.TasStateManager.Clear();
|
||||||
tas.LagLog.Clear();
|
tas.LagLog.Clear();
|
||||||
|
|
|
@ -1,22 +1,10 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public static class MovieService
|
public static class MovieService
|
||||||
{
|
{
|
||||||
public static IMovie Get(string path)
|
|
||||||
{
|
|
||||||
// TODO: change IMovies to take HawkFiles only and not path
|
|
||||||
if (Path.GetExtension(path)?.EndsWith("tasproj") ?? false)
|
|
||||||
{
|
|
||||||
return new TasMovie(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Bk2Movie(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string StandardMovieExtension => Bk2Movie.Extension;
|
public static string StandardMovieExtension => Bk2Movie.Extension;
|
||||||
public static string TasMovieExtension => TasMovie.Extension;
|
public static string TasMovieExtension => TasMovie.Extension;
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void RunQueuedMovie(bool recordMode, IEmulator emulator, IDictionary<string, string> preferredCores)
|
public void RunQueuedMovie(bool recordMode, IEmulator emulator, IDictionary<string, string> preferredCores)
|
||||||
{
|
{
|
||||||
_queuedMovie.Attach(this, emulator);
|
_queuedMovie.Attach(emulator);
|
||||||
foreach (var previousPref in _preferredCores)
|
foreach (var previousPref in _preferredCores)
|
||||||
{
|
{
|
||||||
preferredCores[previousPref.Key] = previousPref.Value;
|
preferredCores[previousPref.Key] = previousPref.Value;
|
||||||
|
@ -339,6 +339,18 @@ namespace BizHawk.Client.Common
|
||||||
Movie.SwitchToPlay();
|
Movie.SwitchToPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IMovie Get(string path)
|
||||||
|
{
|
||||||
|
// TODO: change IMovies to take HawkFiles only and not path
|
||||||
|
if (Path.GetExtension(path)?.EndsWith("tasproj") ?? false)
|
||||||
|
{
|
||||||
|
return new TasMovie(this, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Bk2Movie(this, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ClearFrame()
|
private void ClearFrame()
|
||||||
{
|
{
|
||||||
if (Movie.IsPlayingOrFinished())
|
if (Movie.IsPlayingOrFinished())
|
||||||
|
|
|
@ -160,7 +160,7 @@ namespace BizHawk.Client.Common
|
||||||
SetCycleValues(); // We are pretending these only need to be set on save
|
SetCycleValues(); // We are pretending these only need to be set on save
|
||||||
CreateDirectoryIfNotExists(fn);
|
CreateDirectoryIfNotExists(fn);
|
||||||
|
|
||||||
using var bs = new ZipStateSaver(fn, Global.MovieSession.Settings.MovieCompressionLevel);
|
using var bs = new ZipStateSaver(fn, Session.Settings.MovieCompressionLevel);
|
||||||
AddLumps(bs);
|
AddLumps(bs);
|
||||||
|
|
||||||
if (!isBackup)
|
if (!isBackup)
|
||||||
|
|
|
@ -9,18 +9,19 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
private Bk2Controller _adapter;
|
private Bk2Controller _adapter;
|
||||||
|
|
||||||
internal Bk2Movie(string filename)
|
internal Bk2Movie(IMovieSession session, string filename)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(filename))
|
if (string.IsNullOrWhiteSpace(filename))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException($"{nameof(filename)} can not be null.");
|
throw new ArgumentNullException($"{nameof(filename)} can not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Session = session;
|
||||||
Filename = filename;
|
Filename = filename;
|
||||||
Header[HeaderKeys.MovieVersion] = "BizHawk v2.0.0";
|
Header[HeaderKeys.MovieVersion] = "BizHawk v2.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Attach(IMovieSession session, IEmulator emulator)
|
public virtual void Attach(IEmulator emulator)
|
||||||
{
|
{
|
||||||
// TODO: this check would ideally happen
|
// TODO: this check would ideally happen
|
||||||
// but is disabled for now because restarting a movie doesn't new one up
|
// but is disabled for now because restarting a movie doesn't new one up
|
||||||
|
@ -32,11 +33,10 @@ namespace BizHawk.Client.Common
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Emulator = emulator;
|
Emulator = emulator;
|
||||||
Session = session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEmulator Emulator { get; private set; }
|
public IEmulator Emulator { get; private set; }
|
||||||
public IMovieSession Session { get; private set; }
|
public IMovieSession Session { get; }
|
||||||
|
|
||||||
protected bool MakeBackup { get; set; } = true;
|
protected bool MakeBackup { get; set; } = true;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public interface IMovieImport
|
public interface IMovieImport
|
||||||
{
|
{
|
||||||
ImportResult Import(string path, Config config);
|
ImportResult Import(IMovieSession session, string path, Config config);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal abstract class MovieImporter : IMovieImport
|
internal abstract class MovieImporter : IMovieImport
|
||||||
|
@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
|
||||||
protected const string Md5 = "MD5";
|
protected const string Md5 = "MD5";
|
||||||
protected const string MovieOrigin = "MovieOrigin";
|
protected const string MovieOrigin = "MovieOrigin";
|
||||||
|
|
||||||
public ImportResult Import(string path, Config config)
|
public ImportResult Import(IMovieSession session, string path, Config config)
|
||||||
{
|
{
|
||||||
SourceFile = new FileInfo(path);
|
SourceFile = new FileInfo(path);
|
||||||
Config = config;
|
Config = config;
|
||||||
|
@ -28,7 +28,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
var newFileName = $"{SourceFile.FullName}.{Bk2Movie.Extension}";
|
var newFileName = $"{SourceFile.FullName}.{Bk2Movie.Extension}";
|
||||||
Result.Movie = MovieService.Get(newFileName);
|
Result.Movie = session.Get(newFileName);
|
||||||
|
|
||||||
RunImport();
|
RunImport();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attempt to import another type of movie file into a movie object.
|
// Attempt to import another type of movie file into a movie object.
|
||||||
public static ImportResult ImportFile(string path, Config config)
|
public static ImportResult ImportFile(IMovieSession session, string path, Config config)
|
||||||
{
|
{
|
||||||
string ext = Path.GetExtension(path) ?? "";
|
string ext = Path.GetExtension(path) ?? "";
|
||||||
var importerType = ImporterForExtension(ext);
|
var importerType = ImporterForExtension(ext);
|
||||||
|
@ -47,7 +47,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
return importer == null
|
return importer == null
|
||||||
? ImportResult.Error($"No importer found for file type {ext}")
|
? ImportResult.Error($"No importer found for file type {ext}")
|
||||||
: importer.Import(path, config);
|
: importer.Import(session, path, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Type ImporterForExtension(string ext)
|
private static Type ImporterForExtension(string ext)
|
||||||
|
|
|
@ -234,13 +234,18 @@ namespace BizHawk.Client.Common
|
||||||
/// Thrown if attempting to attach a core when one is already attached
|
/// Thrown if attempting to attach a core when one is already attached
|
||||||
/// or if the given core does not meet all required dependencies
|
/// or if the given core does not meet all required dependencies
|
||||||
/// </exception>
|
/// </exception>
|
||||||
void Attach(IMovieSession session, IEmulator emulator);
|
void Attach(IEmulator emulator);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The currently attached core or null if not yet attached
|
/// The currently attached core or null if not yet attached
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IEmulator Emulator { get; }
|
IEmulator Emulator { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current movie session
|
||||||
|
/// </summary>
|
||||||
|
IMovieSession Session { get; }
|
||||||
|
|
||||||
IStringLog GetLogEntries();
|
IStringLog GetLogEntries();
|
||||||
void CopyLog(IEnumerable<string> log);
|
void CopyLog(IEnumerable<string> log);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,10 @@ namespace BizHawk.Client.Common
|
||||||
void StopMovie(bool saveChanges = true);
|
void StopMovie(bool saveChanges = true);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If a movie is active, it will be converted to a <see cref="TasMovie" />
|
/// If a movie is active, it will be converted to a <see cref="ITasMovie" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void ConvertToTasProj();
|
void ConvertToTasProj();
|
||||||
|
|
||||||
|
IMovie Get(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
|
||||||
private IInputPollable _inputPollable;
|
private IInputPollable _inputPollable;
|
||||||
|
|
||||||
/// <exception cref="InvalidOperationException">loaded core does not implement <see cref="IStatable"/></exception>
|
/// <exception cref="InvalidOperationException">loaded core does not implement <see cref="IStatable"/></exception>
|
||||||
internal TasMovie(string path) : base(path)
|
internal TasMovie(IMovieSession session, string path) : base(session, path)
|
||||||
{
|
{
|
||||||
Branches = new TasBranchCollection(this);
|
Branches = new TasBranchCollection(this);
|
||||||
ChangeLog = new TasMovieChangeLog(this);
|
ChangeLog = new TasMovieChangeLog(this);
|
||||||
|
@ -24,7 +24,7 @@ namespace BizHawk.Client.Common
|
||||||
Markers.Add(0, "Power on");
|
Markers.Add(0, "Power on");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Attach(IMovieSession session, IEmulator emulator)
|
public override void Attach(IEmulator emulator)
|
||||||
{
|
{
|
||||||
if (!emulator.HasSavestates())
|
if (!emulator.HasSavestates())
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.Common
|
||||||
_inputPollable = emulator.AsInputPollable();
|
_inputPollable = emulator.AsInputPollable();
|
||||||
TasStateManager.Attach(emulator);
|
TasStateManager.Attach(emulator);
|
||||||
|
|
||||||
base.Attach(session, emulator);
|
base.Attach(emulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool StartsFromSavestate
|
public override bool StartsFromSavestate
|
||||||
|
|
|
@ -102,7 +102,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartNewMovie(MovieService.Get(filename), false);
|
StartNewMovie(MovieSession.Get(filename), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadRom(string filename, string archive = null)
|
private void LoadRom(string filename, string archive = null)
|
||||||
|
|
|
@ -496,7 +496,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// If user picked a game, then do the commandline logic
|
// If user picked a game, then do the commandline logic
|
||||||
if (!Game.IsNullInstance())
|
if (!Game.IsNullInstance())
|
||||||
{
|
{
|
||||||
var movie = MovieService.Get(_argParser.cmdMovie);
|
var movie = MovieSession.Get(_argParser.cmdMovie);
|
||||||
MovieSession.ReadOnly = true;
|
MovieSession.ReadOnly = true;
|
||||||
|
|
||||||
// if user is dumping and didn't supply dump length, make it as long as the loaded movie
|
// if user is dumping and didn't supply dump length, make it as long as the loaded movie
|
||||||
|
@ -531,7 +531,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (File.Exists(Config.RecentMovies.MostRecent))
|
if (File.Exists(Config.RecentMovies.MostRecent))
|
||||||
{
|
{
|
||||||
StartNewMovie(MovieService.Get(Config.RecentMovies.MostRecent), false);
|
StartNewMovie(MovieSession.Get(Config.RecentMovies.MostRecent), false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2065,7 +2065,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
var movie = MovieService.Get(path);
|
var movie = MovieSession.Get(path);
|
||||||
MovieSession.ReadOnly = true;
|
MovieSession.ReadOnly = true;
|
||||||
StartNewMovie(movie, false);
|
StartNewMovie(movie, false);
|
||||||
}
|
}
|
||||||
|
@ -4015,7 +4015,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void ProcessMovieImport(string fn, bool start)
|
private void ProcessMovieImport(string fn, bool start)
|
||||||
{
|
{
|
||||||
var result = MovieImport.ImportFile(fn, Config);
|
var result = MovieImport.ImportFile(MovieSession, fn, Config);
|
||||||
|
|
||||||
if (result.Errors.Any())
|
if (result.Errors.Any())
|
||||||
{
|
{
|
||||||
|
|
|
@ -128,7 +128,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private IMovie PreLoadMovieFile(HawkFile hf, bool force)
|
private IMovie PreLoadMovieFile(HawkFile hf, bool force)
|
||||||
{
|
{
|
||||||
var movie = MovieService.Get(hf.CanonicalFullPath);
|
var movie = _movieSession.Get(hf.CanonicalFullPath);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var movieToRecord = MovieService.Get(path);
|
var movieToRecord = _movieSession.Get(path);
|
||||||
|
|
||||||
var fileInfo = new FileInfo(path);
|
var fileInfo = new FileInfo(path);
|
||||||
if (!fileInfo.Exists)
|
if (!fileInfo.Exists)
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (result1.IsOk())
|
if (result1.IsOk())
|
||||||
{
|
{
|
||||||
_initializing = true; // Starting a new movie causes a core reboot
|
_initializing = true; // Starting a new movie causes a core reboot
|
||||||
MainForm.StartNewMovie(MovieService.Get(ofd.FileName), false);
|
MainForm.StartNewMovie(MovieSession.Get(ofd.FileName), false);
|
||||||
ConvertCurrentMovieToTasproj();
|
ConvertCurrentMovieToTasproj();
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
StartNewMovieWrapper(CurrentTasMovie);
|
StartNewMovieWrapper(CurrentTasMovie);
|
||||||
|
|
|
@ -622,7 +622,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newMovie = (ITasMovie)MovieService.Get(file.FullName);
|
var newMovie = (ITasMovie)MovieSession.Get(file.FullName);
|
||||||
newMovie.BindMarkersToInput = Settings.BindMarkersToInput;
|
newMovie.BindMarkersToInput = Settings.BindMarkersToInput;
|
||||||
newMovie.TasStateManager.InvalidateCallback = GreenzoneInvalidated;
|
newMovie.TasStateManager.InvalidateCallback = GreenzoneInvalidated;
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename
|
var filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename
|
||||||
var tasMovie = (ITasMovie)MovieService.Get(filename);
|
var tasMovie = (ITasMovie)MovieSession.Get(filename);
|
||||||
tasMovie.BindMarkersToInput = Settings.BindMarkersToInput;
|
tasMovie.BindMarkersToInput = Settings.BindMarkersToInput;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue