Some movie refactoring - moving a function into the importer class, remove MovieExtension from the config file and instead add it as a movie property, add some todo comments in places regarding movie 2.0
This commit is contained in:
parent
b0c7ba5f77
commit
7e9b13f5c3
|
@ -89,7 +89,6 @@ namespace BizHawk.Client.Common
|
|||
public bool AutoLoadLastSaveSlot = false;
|
||||
public bool WIN32_CONSOLE = true;
|
||||
public bool SkipLagFrame = false;
|
||||
public string MovieExtension = "bkm";
|
||||
public bool SupressAskSave = false;
|
||||
public bool AVI_CaptureOSD = false;
|
||||
public bool Screenshot_CaptureOSD = false;
|
||||
|
|
|
@ -43,6 +43,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
int InputLogLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the file extension for this implementation
|
||||
/// </summary>
|
||||
string PreferredExtension { get; }
|
||||
|
||||
IMovieHeader Header { get; }
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BizHawk.Common;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -42,6 +42,10 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Properties
|
||||
|
||||
public string PreferredExtension { get { return "bkm"; } }
|
||||
|
||||
public static string Extension { get { return "bkm"; } }
|
||||
|
||||
public IMovieHeader Header { get; private set; }
|
||||
|
||||
public bool MakeBackup { get; set; }
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public static class MovieImport
|
||||
{
|
||||
// Movies 2.0 TODO: this is Movie.cs specific, can it be IMovie based? If not, needs to be refactored to a hardcoded 2.0 implementation, client needs to know what kind of type it imported to, or the mainform method needs to be moved here
|
||||
public const string COMMENT = "comment";
|
||||
public const string COREORIGIN = "CoreOrigin";
|
||||
public const string CRC16 = "CRC16";
|
||||
|
@ -31,14 +32,46 @@ namespace BizHawk.Client.Common
|
|||
public const string SYNCHACK = "SyncHack";
|
||||
public const string UNITCODE = "UnitCode";
|
||||
|
||||
public static void ProcessMovieImport(string fn, Action<string> conversionErrorCallback, Action<string> messageCallback)
|
||||
{
|
||||
var d = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
||||
string errorMsg;
|
||||
string warningMsg;
|
||||
var m = ImportFile(fn, out errorMsg, out warningMsg);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorMsg))
|
||||
{
|
||||
conversionErrorCallback(errorMsg);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(warningMsg))
|
||||
{
|
||||
messageCallback(warningMsg);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
messageCallback(Path.GetFileName(fn) + " imported as " + "Movies\\" +
|
||||
Path.GetFileName(fn) + "." + Global.MovieSession.Movie.PreferredExtension);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(d))
|
||||
{
|
||||
Directory.CreateDirectory(d);
|
||||
}
|
||||
|
||||
var outPath = Path.Combine(d, Path.GetFileName(fn) + "." + Global.MovieSession.Movie.PreferredExtension);
|
||||
m.SaveAs(outPath);
|
||||
}
|
||||
|
||||
// Attempt to import another type of movie file into a movie object.
|
||||
public static Movie ImportFile(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
Movie m = new Movie();
|
||||
errorMsg = String.Empty;
|
||||
warningMsg = String.Empty;
|
||||
errorMsg = string.Empty;
|
||||
warningMsg = string.Empty;
|
||||
|
||||
string ext = path != null ? Path.GetExtension(path).ToUpper() : String.Empty;
|
||||
string ext = path != null ? Path.GetExtension(path).ToUpper() : string.Empty;
|
||||
try
|
||||
{
|
||||
switch (ext)
|
||||
|
@ -293,7 +326,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportText(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileInfo file = new FileInfo(path);
|
||||
StreamReader sr = file.OpenText();
|
||||
string emulator = String.Empty;
|
||||
|
@ -489,7 +522,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportFCM(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 4-byte signature: 46 43 4D 1A "FCM\x1A"
|
||||
|
@ -741,7 +774,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportFMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 4-byte signature: 46 4D 56 1A "FMV\x1A"
|
||||
|
@ -881,7 +914,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportGMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 16-byte signature and format version: "Gens Movie TEST9"
|
||||
|
@ -1005,7 +1038,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportLSMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
HawkFile hf = new HawkFile(path);
|
||||
// .LSMV movies are .zip files containing data files.
|
||||
if (!hf.IsArchive)
|
||||
|
@ -1237,7 +1270,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportMCM(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 8-byte "MDFNMOVI" signature
|
||||
|
@ -1358,7 +1391,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportMMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 0000: 4-byte signature: "MMV\0"
|
||||
|
@ -1472,7 +1505,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportNMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 4-byte signature: 4E 53 53 1A "NSS\x1A"
|
||||
|
@ -1699,7 +1732,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportSMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 4-byte signature: 53 4D 56 1A "SMV\x1A"
|
||||
|
@ -1970,7 +2003,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportVBM(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 4-byte signature: 56 42 4D 1A "VBM\x1A"
|
||||
|
@ -2240,7 +2273,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportVMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 12-byte signature: "VirtuaNES MV"
|
||||
|
@ -2464,7 +2497,7 @@ namespace BizHawk.Client.Common
|
|||
private static Movie ImportZMV(string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = warningMsg = String.Empty;
|
||||
Movie m = new Movie(path + "." + Global.Config.MovieExtension);
|
||||
Movie m = new Movie(path + "." + Movie.Extension);
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader r = new BinaryReader(fs);
|
||||
// 000 3-byte signature: 5A 4D 56 "ZMV"
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public static bool IsValidMovieExtension(string ext)
|
||||
{
|
||||
if (ext.ToUpper() == "." + Global.Config.MovieExtension)
|
||||
// Movies 2.0 TODO
|
||||
if (ext.ToUpper() == "." + Global.MovieSession.Movie.PreferredExtension)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public string PreferredExtension { get { return "tasproj"; } }
|
||||
|
||||
public void ToggleButton(int frame, string buttonName)
|
||||
{
|
||||
InvalidateGreenzone(frame);
|
||||
|
|
|
@ -2209,6 +2209,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
else if (MovieImport.IsValidMovieExtension(Path.GetExtension(filePaths[0])))
|
||||
{
|
||||
// Movies 2.0 TODO: rethink this method
|
||||
|
||||
//tries to open a legacy movie format as if it were a BKM, by importing it
|
||||
if (CurrentlyOpenRom == null)
|
||||
{
|
||||
|
@ -2231,7 +2233,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
//fix movie extension to something palatable for these purposes.
|
||||
//for instance, something which doesnt clobber movies you already may have had.
|
||||
//i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this:
|
||||
movie.Filename += ".autoimported." + Global.Config.MovieExtension;
|
||||
movie.Filename += ".autoimported." + Movie.Extension;
|
||||
movie.Save();
|
||||
StartNewMovie(movie, false);
|
||||
}
|
||||
|
|
|
@ -3184,35 +3184,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private static void ShowConversionError(string errorMsg)
|
||||
{
|
||||
MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
private static void ProcessMovieImport(string fn) // Nothing Winform Specific here, move to Movie import
|
||||
{
|
||||
var d = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
||||
string errorMsg;
|
||||
string warningMsg;
|
||||
var m = MovieImport.ImportFile(fn, out errorMsg, out warningMsg);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(errorMsg))
|
||||
{
|
||||
MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(warningMsg))
|
||||
{
|
||||
GlobalWin.OSD.AddMessage(warningMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalWin.OSD.AddMessage(Path.GetFileName(fn) + " imported as " + "Movies\\" +
|
||||
Path.GetFileName(fn) + "." + Global.Config.MovieExtension);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(d))
|
||||
{
|
||||
Directory.CreateDirectory(d);
|
||||
}
|
||||
|
||||
var outPath = Path.Combine(d, Path.GetFileName(fn) + "." + Global.Config.MovieExtension);
|
||||
m.SaveAs(outPath);
|
||||
MovieImport.ProcessMovieImport(fn, ShowConversionError, GlobalWin.OSD.AddMessage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class PlayMovie : Form
|
||||
{
|
||||
// Movies 2.0 TODO: this is hopelessly Movie.cs specific, to make it generic, make a MovieLoader class that receives a path and returns an IMovie, that does the logic of determining bkm, bk2, or tasproj
|
||||
private List<IMovie> _movieList = new List<IMovie>();
|
||||
private bool _sortReverse;
|
||||
private string _sortedCol;
|
||||
|
@ -203,7 +204,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var tas = new List<int>();
|
||||
for (var i = 0; i < indices.Count; i++)
|
||||
{
|
||||
if (Path.GetExtension(_movieList[indices[i]].Filename).ToUpper() == "." + Global.Config.MovieExtension)
|
||||
if (Path.GetExtension(_movieList[indices[i]].Filename).ToUpper() == "." + Movie.Extension)
|
||||
{
|
||||
tas.Add(i);
|
||||
}
|
||||
|
@ -272,7 +273,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
dpTodo.Enqueue(subdir);
|
||||
|
||||
//add movies
|
||||
fpTodo.AddRange(Directory.GetFiles(dp, "*." + Global.Config.MovieExtension));
|
||||
fpTodo.AddRange(Directory.GetFiles(dp, "*." + Movie.Extension));
|
||||
|
||||
//add states if requested
|
||||
if (Global.Config.PlayMovie_ShowStateFiles)
|
||||
|
@ -315,7 +316,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
|
||||
filePaths
|
||||
.Where(path => Path.GetExtension(path) == "." + Global.Config.MovieExtension)
|
||||
.Where(path => Path.GetExtension(path) == "." + Movie.Extension)
|
||||
.ToList()
|
||||
.ForEach(path => AddMovieToList(path, force: true));
|
||||
|
||||
|
@ -623,7 +624,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*",
|
||||
Filter = "Movie Files (*." + Movie.Extension + ")|*." + Movie.Extension + "|Savestates|*.state|All Files|*.*",
|
||||
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null)
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (path[path.Length - 4] != '.') // If no file extension, add movie extension
|
||||
{
|
||||
path += "." + Global.Config.MovieExtension;
|
||||
path += "." + Global.MovieSession.Movie.PreferredExtension;
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -169,11 +169,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
var sfd = new SaveFileDialog
|
||||
{
|
||||
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null),
|
||||
DefaultExt = "." + Global.Config.MovieExtension,
|
||||
DefaultExt = "." + Global.MovieSession.Movie.PreferredExtension,
|
||||
FileName = RecordBox.Text,
|
||||
OverwritePrompt = false
|
||||
};
|
||||
var filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
|
||||
var filter = "Movie Files (*." + Global.MovieSession.Movie.PreferredExtension + ")|*." + Global.MovieSession.Movie.PreferredExtension + "|Savestates|*.state|All Files|*.*";
|
||||
sfd.Filter = filter;
|
||||
|
||||
var result = sfd.ShowHawkDialog();
|
||||
|
|
Loading…
Reference in New Issue