From 3b25fdc8ca2db0842078eaac9d57492c54040fdd Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 29 Oct 2019 17:18:17 -0500 Subject: [PATCH] simplify some movie import code --- .../conversions/MovieConversionExtensions.cs | 2 +- .../movie/import/IMovieImport.cs | 12 ++--- .../movie/import/MovieImport.cs | 46 +++++++------------ BizHawk.sln.DotSettings | 2 + 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs index a1450bf56a..6fe710524f 100644 --- a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs +++ b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs @@ -338,7 +338,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions if (Global.Emulator is SMS && (Global.Emulator as SMS).IsSG1000) { movie.HeaderEntries.Add("IsSGMode", "1"); - } + } if (Global.Emulator is SMS && (Global.Emulator as SMS).IsGameGear) { diff --git a/BizHawk.Client.Common/movie/import/IMovieImport.cs b/BizHawk.Client.Common/movie/import/IMovieImport.cs index 91191b7342..c35caddca8 100644 --- a/BizHawk.Client.Common/movie/import/IMovieImport.cs +++ b/BizHawk.Client.Common/movie/import/IMovieImport.cs @@ -68,14 +68,8 @@ namespace BizHawk.Client.Common public class ImportResult { - public ImportResult() - { - Warnings = new List(); - Errors = new List(); - } - - public IList Warnings { get; private set; } - public IList Errors { get; } + public IList Warnings { get; } = new List(); + public IList Errors { get; } = new List(); public Bk2Movie Movie { get; set; } } @@ -88,6 +82,6 @@ namespace BizHawk.Client.Common Extension = extension; } - public string Extension { get; private set; } + public string Extension { get; } } } diff --git a/BizHawk.Client.Common/movie/import/MovieImport.cs b/BizHawk.Client.Common/movie/import/MovieImport.cs index 6f16c63120..0b0a6ae201 100644 --- a/BizHawk.Client.Common/movie/import/MovieImport.cs +++ b/BizHawk.Client.Common/movie/import/MovieImport.cs @@ -42,23 +42,16 @@ namespace BizHawk.Client.Common public static void ProcessMovieImport(string fn, Action conversionErrorCallback, Action messageCallback) { var d = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null); - string errorMsg; - string warningMsg; - var m = ImportFile(fn, out errorMsg, out warningMsg); + var m = ImportFile(fn, out var errorMsg, out var warningMsg); if (!string.IsNullOrWhiteSpace(errorMsg)) { conversionErrorCallback(errorMsg); } - if (!string.IsNullOrWhiteSpace(warningMsg)) - { - messageCallback(warningMsg); - } - else - { - messageCallback($"{Path.GetFileName(fn)} imported as {m.Filename}"); - } + messageCallback(!string.IsNullOrWhiteSpace(warningMsg) + ? warningMsg + : $"{Path.GetFileName(fn)} imported as {m.Filename}"); if (!Directory.Exists(d)) { @@ -118,25 +111,15 @@ namespace BizHawk.Client.Common private static IEnumerable ImportersForExtension(string ext) { - var info = typeof(MovieImport).Module; - var importers = from t in info.GetTypes() - where typeof(IMovieImport).IsAssignableFrom(t) - && TypeImportsExtension(t, ext) - select t; - - return importers; + return typeof(MovieImport).Module + .GetTypes() + .Where(t => typeof(IMovieImport).IsAssignableFrom(t)); } private static bool TypeImportsExtension(Type t, string ext) { var attrs = (ImportExtensionAttribute[])t.GetCustomAttributes(typeof(ImportExtensionAttribute), inherit: false); - - if (attrs.Any(a => a.Extension.ToUpper() == ext.ToUpper())) - { - return true; - } - - return false; + return attrs.Any(a => a.Extension.ToUpper() == ext.ToUpper()); } private static BkmMovie LegacyImportFile(string ext, string path, out string errorMsg, out string warningMsg) @@ -252,9 +235,12 @@ namespace BizHawk.Client.Common private static IController EmptyLmsvFrame(string line) { - var emptyController = new SimpleController { Definition = new ControllerDefinition { Name = "SNES Controller" } }; - emptyController["Reset"] = false; - emptyController["Power"] = false; + var emptyController = new SimpleController + { + Definition = new ControllerDefinition { Name = "SNES Controller" } + , ["Reset"] = false + , ["Power"] = false + }; string[] buttons = { "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" }; string[] sections = line.Split('|'); @@ -263,9 +249,9 @@ namespace BizHawk.Client.Common int player = section - 1; // We start with 1 string prefix = $"P{player} "; // "P1" - for (int button = 0; button < buttons.Length; button++) + foreach (var b in buttons) { - emptyController[prefix + buttons[button]] = false; + emptyController[prefix + b] = false; } } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 1473f6e06c..759dbd9b23 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -226,6 +226,7 @@ True True True + True True True True @@ -262,6 +263,7 @@ True True True + True True True True