From 5145ef3f97a8964ec6f0a39275de7d6950092434 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 19 Jun 2014 02:30:22 +0000 Subject: [PATCH] Movie imports now import to .bk2 --- BizHawk.Client.Common/movie/MovieImport.cs | 34 +++++++++++-------- .../movie/bk2/Bk2Movie.IO.cs | 6 +++- BizHawk.Client.EmuHawk/MainForm.Events.cs | 2 +- BizHawk.Client.EmuHawk/MainForm.cs | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.Common/movie/MovieImport.cs b/BizHawk.Client.Common/movie/MovieImport.cs index b21b99cd48..b541dba60e 100644 --- a/BizHawk.Client.Common/movie/MovieImport.cs +++ b/BizHawk.Client.Common/movie/MovieImport.cs @@ -7,6 +7,7 @@ using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.SNES; +using BizHawk.Client.Common.MovieConversionExtensions; namespace BizHawk.Client.Common { @@ -62,11 +63,12 @@ namespace BizHawk.Client.Common } var outPath = Path.Combine(d, Path.GetFileName(fn) + "." + Global.MovieSession.Movie.PreferredExtension); - m.SaveAs(outPath); + m.Filename = outPath; + m.Save(); } // Attempt to import another type of movie file into a movie object. - public static BkmMovie ImportFile(string path, out string errorMsg, out string warningMsg) + public static Bk2Movie ImportFile(string path, out string errorMsg, out string warningMsg) { BkmMovie m = new BkmMovie(); errorMsg = string.Empty; @@ -125,7 +127,9 @@ namespace BizHawk.Client.Common { errorMsg = except.ToString(); } - return m; + + // Hack + return m.ToBk2(); } // Return whether or not the type of file provided can currently be imported. @@ -323,7 +327,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportText(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileInfo file = new FileInfo(path); StreamReader sr = file.OpenText(); string emulator = string.Empty; @@ -520,7 +524,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportFCM(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 4-byte signature: 46 43 4D 1A "FCM\x1A" @@ -772,7 +776,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportFMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 4-byte signature: 46 4D 56 1A "FMV\x1A" @@ -912,7 +916,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportGMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 16-byte signature and format version: "Gens Movie TEST9" @@ -1036,7 +1040,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportLSMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); HawkFile hf = new HawkFile(path); // .LSMV movies are .zip files containing data files. if (!hf.IsArchive) @@ -1268,7 +1272,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportMCM(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 8-byte "MDFNMOVI" signature @@ -1389,7 +1393,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportMMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 0000: 4-byte signature: "MMV\0" @@ -1503,7 +1507,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportNMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 4-byte signature: 4E 53 53 1A "NSS\x1A" @@ -1730,7 +1734,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportSMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 4-byte signature: 53 4D 56 1A "SMV\x1A" @@ -2001,7 +2005,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportVBM(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 4-byte signature: 56 42 4D 1A "VBM\x1A" @@ -2271,7 +2275,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportVMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 12-byte signature: "VirtuaNES MV" @@ -2495,7 +2499,7 @@ namespace BizHawk.Client.Common private static BkmMovie ImportZMV(string path, out string errorMsg, out string warningMsg) { errorMsg = warningMsg = string.Empty; - BkmMovie m = new BkmMovie(path + "." + MovieService.DefaultExtension); + BkmMovie m = new BkmMovie(path); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); // 000 3-byte signature: 5A 4D 56 "ZMV" diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index ab41a7157a..2f05d6f129 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -60,7 +60,11 @@ namespace BizHawk.Client.Common if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); - Header.Add(pair[0], pair[1]); + + if (pair.Length > 1) + { + Header.Add(pair[0], pair[1]); + } } } }); diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 1704b8c476..09e90f77b4 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -2241,7 +2241,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." + MovieService.DefaultExtension; + movie.Filename = Path.ChangeExtension(movie.Filename, ".autoimported." + MovieService.DefaultExtension); movie.Save(); StartNewMovie(movie, false); } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 5938dc9e16..30af6809e8 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -3224,7 +3224,7 @@ namespace BizHawk.Client.EmuHawk MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - private static void ProcessMovieImport(string fn) // Nothing Winform Specific here, move to Movie import + private static void ProcessMovieImport(string fn) { MovieImport.ProcessMovieImport(fn, ShowConversionError, GlobalWin.OSD.AddMessage); }