From cf4dd6770cbe4b981add8822bfd3620833256a12 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 15 Nov 2019 17:29:38 -0600 Subject: [PATCH] ApiHawk - cleanups --- .../BizHawkExternalToolAttribute.cs | 45 +++----------- .../BizHawkExternalToolUsageAttribute.cs | 47 ++++---------- .../Classes/Api/GameInfoApi.cs | 3 - .../Classes/Api/JoypadApi.cs | 53 ++++++---------- BizHawk.Client.ApiHawk/Classes/Api/MemApi.cs | 18 +++--- .../Classes/Api/MemApiBase.cs | 12 ++-- .../Classes/Api/MemorySaveStateApi.cs | 8 +-- .../Classes/Api/UserDataApi.cs | 11 +--- .../Classes/BasicApiProvider.cs | 19 ++---- ...izHawkSystemIdToCoreSystemEnumConverter.cs | 2 +- BizHawk.Client.ApiHawk/Classes/ClientApi.cs | 32 ++++------ .../EventArgs/BeforeQuickLoadEventArgs.cs | 46 ++------------ .../EventArgs/BeforeQuickSaveEventArgs.cs | 46 ++------------ .../Events/EventArgs/StateLoadedEventArgs.cs | 24 +------- .../Events/EventArgs/StateSavedEventArgs.cs | 24 +------- .../Classes/ExternalToolManager.cs | 61 +++++++++---------- BizHawk.Client.ApiHawk/Classes/Joypad.cs | 33 ++-------- .../Classes/JoypadStringToEnumConverter.cs | 2 +- BizHawk.sln.DotSettings | 4 ++ 19 files changed, 133 insertions(+), 357 deletions(-) diff --git a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs index 590eba9f91..134a3ab3f0 100644 --- a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs +++ b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs @@ -3,20 +3,12 @@ namespace BizHawk.Client.ApiHawk { /// - /// This class hold logic interraction for the ExternalToolAttribute + /// This class holds logic interaction for the ExternalToolAttribute /// This attribute helps BizHawk to handle ExternalTools /// [AttributeUsage(AttributeTargets.Assembly)] public sealed class BizHawkExternalToolAttribute : Attribute { - #region Fields - - private string _Name; - private string _Description; - private string _IconResourceName; - - #endregion - #region cTor(s) /// @@ -27,9 +19,9 @@ namespace BizHawk.Client.ApiHawk /// Icon embedded resource name public BizHawkExternalToolAttribute(string name, string description, string iconResourceName) { - _Name = name; - _Description = description; - _IconResourceName = iconResourceName; + Name = name; + Description = description; + IconResourceName = iconResourceName; } /// @@ -56,36 +48,19 @@ namespace BizHawk.Client.ApiHawk /// /// Gets tool's friendly name /// - public string Name - { - get - { - return _Name; - } - } + public string Name { get; } /// - /// Gets tool's descriptino + /// Gets tool's description /// - public string Description - { - get - { - return _Description; - } - } + public string Description { get; } + /// /// Get the name of the embedded resource icon /// - /// Don't forget to set compile => Embedded reource to the icon file in your project - public string IconResourceName - { - get - { - return _IconResourceName; - } - } + /// Don't forget to set compile => Embedded resource to the icon file in your project + public string IconResourceName { get; } #endregion } diff --git a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs index 5e7dc81d3c..0c15e79c1a 100644 --- a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs +++ b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs @@ -3,20 +3,12 @@ namespace BizHawk.Client.ApiHawk { /// - /// This class hold logic interraction for the BizHawkExternalToolUsageAttribute + /// This class holds logic interaction for the BizHawkExternalToolUsageAttribute /// This attribute helps ApiHawk to know how a tool can be enabled or not /// [AttributeUsage(AttributeTargets.Assembly)] public sealed class BizHawkExternalToolUsageAttribute : Attribute { - #region Fields - - private BizHawkExternalToolUsage _ToolUsage; - private CoreSystem _System; - private string _GameHash; - - #endregion - #region cTor(s) /// @@ -36,9 +28,9 @@ namespace BizHawk.Client.ApiHawk throw new InvalidOperationException("A game hash must be set"); } - _ToolUsage = usage; - _System = system; - _GameHash = gameHash; + ToolUsage = usage; + System = system; + GameHash = gameHash; } /// @@ -63,37 +55,20 @@ namespace BizHawk.Client.ApiHawk #region Properties /// - /// Gets the specific system used by the exetrnal tool + /// Gets the specific system used by the external tool /// - public CoreSystem System - { - get - { - return _System; - } - } + public CoreSystem System { get; } + /// - /// Gets the specific game (hash) used by the exetrnal tool + /// Gets the specific game (hash) used by the external tool /// - public string GameHash - { - get - { - return _GameHash; - } - } - + public string GameHash { get; } + /// /// Gets the tool usage /// - public BizHawkExternalToolUsage ToolUsage - { - get - { - return _ToolUsage; - } - } + public BizHawkExternalToolUsage ToolUsage { get; } #endregion } diff --git a/BizHawk.Client.ApiHawk/Classes/Api/GameInfoApi.cs b/BizHawk.Client.ApiHawk/Classes/Api/GameInfoApi.cs index ca74d09da6..e005b28a1d 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/GameInfoApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/GameInfoApi.cs @@ -10,9 +10,6 @@ namespace BizHawk.Client.ApiHawk [OptionalService] private IBoardInfo BoardInfo { get; set; } - public GameInfoApi() - { } - public string GetRomName() { if (Global.Game != null) diff --git a/BizHawk.Client.ApiHawk/Classes/Api/JoypadApi.cs b/BizHawk.Client.ApiHawk/Classes/Api/JoypadApi.cs index a1074d5507..dc08dc95fa 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/JoypadApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/JoypadApi.cs @@ -7,34 +7,31 @@ namespace BizHawk.Client.ApiHawk { public sealed class JoypadApi : IJoypad { - public JoypadApi() - { } - public Dictionary Get(int? controller = null) { var buttons = new Dictionary(); - var adaptor = Global.AutofireStickyXORAdapter; - foreach (var button in adaptor.Source.Definition.BoolButtons) + var adapter = Global.AutofireStickyXORAdapter; + foreach (var button in adapter.Source.Definition.BoolButtons) { if (!controller.HasValue) { - buttons[button] = adaptor.IsPressed(button); + buttons[button] = adapter.IsPressed(button); } else if (button.Length >= 3 && button.Substring(0, 2) == $"P{controller}") { - buttons[button.Substring(3)] = adaptor.IsPressed($"P{controller} {button.Substring(3)}"); + buttons[button.Substring(3)] = adapter.IsPressed($"P{controller} {button.Substring(3)}"); } } - foreach (var button in adaptor.Source.Definition.FloatControls) + foreach (var button in adapter.Source.Definition.FloatControls) { if (controller == null) { - buttons[button] = adaptor.GetFloat(button); + buttons[button] = adapter.GetFloat(button); } else if (button.Length >= 3 && button.Substring(0, 2) == $"P{controller}") { - buttons[button.Substring(3)] = adaptor.GetFloat($"P{controller} {button.Substring(3)}"); + buttons[button.Substring(3)] = adapter.GetFloat($"P{controller} {button.Substring(3)}"); } } @@ -49,14 +46,15 @@ namespace BizHawk.Client.ApiHawk public Dictionary GetImmediate() { var buttons = new Dictionary(); - var adaptor = Global.ActiveController; - foreach (var button in adaptor.Definition.BoolButtons) + var adapter = Global.ActiveController; + foreach (var button in adapter.Definition.BoolButtons) { - buttons[button] = adaptor.IsPressed(button); + buttons[button] = adapter.IsPressed(button); } - foreach (var button in adaptor.Definition.FloatControls) + + foreach (var button in adapter.Definition.FloatControls) { - buttons[button] = adaptor.GetFloat(button); + buttons[button] = adapter.GetFloat(button); } return buttons; @@ -116,7 +114,7 @@ namespace BizHawk.Client.ApiHawk theValue = null; } - var toPress = button.ToString(); + var toPress = button; if (controller.HasValue) { toPress = $"P{controller} {button}"; @@ -178,21 +176,13 @@ namespace BizHawk.Client.ApiHawk if (!string.IsNullOrWhiteSpace(theValueStr)) { - float f; - if (float.TryParse(theValueStr, out f)) + if (float.TryParse(theValueStr, out var f)) { theValue = f; } } - if (controller == null) - { - Global.StickyXORAdapter.SetFloat(name.ToString(), theValue); - } - else - { - Global.StickyXORAdapter.SetFloat($"P{controller} {name}", theValue); - } + Global.StickyXORAdapter.SetFloat(controller == null ? name : $"P{controller} {name}", theValue); } } catch @@ -204,14 +194,9 @@ namespace BizHawk.Client.ApiHawk { try { - if (controller == null) - { - Global.StickyXORAdapter.SetFloat(control, value); - } - else - { - Global.StickyXORAdapter.SetFloat($"P{controller} {control}", value); - } + Global.StickyXORAdapter.SetFloat(controller == null + ? control + : $"P{controller} {control}", value); } catch { diff --git a/BizHawk.Client.ApiHawk/Classes/Api/MemApi.cs b/BizHawk.Client.ApiHawk/Classes/Api/MemApi.cs index f54b282550..8176787b75 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/MemApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/MemApi.cs @@ -10,7 +10,7 @@ namespace BizHawk.Client.ApiHawk public sealed class MemApi : MemApiBase, IMem { private MemoryDomain _currentMemoryDomain; - private bool _isBigEndian = false; + private bool _isBigEndian; public MemApi() : base() { @@ -122,10 +122,8 @@ namespace BizHawk.Client.ApiHawk data[i] = d.PeekByte(addr + i); } - using (var hasher = System.Security.Cryptography.SHA256.Create()) - { - return hasher.ComputeHash(data).BytesToHexString(); - } + using var hasher = System.Security.Cryptography.SHA256.Create(); + return hasher.ComputeHash(data).BytesToHexString(); } #endregion @@ -134,14 +132,16 @@ namespace BizHawk.Client.ApiHawk private int ReadSigned(long addr, int size, string domain = null) { - if (_isBigEndian) return ReadSignedBig(addr, size, domain); - else return ReadSignedLittle(addr, size, domain); + return _isBigEndian + ? ReadSignedBig(addr, size, domain) + : ReadSignedLittle(addr, size, domain); } private uint ReadUnsigned(long addr, int size, string domain = null) { - if (_isBigEndian) return ReadUnsignedBig(addr, size, domain); - else return ReadUnsignedLittle(addr, size, domain); + return _isBigEndian + ? ReadUnsignedBig(addr, size, domain) + : ReadUnsignedLittle(addr, size, domain); } private void WriteSigned(long addr, int value, int size, string domain = null) diff --git a/BizHawk.Client.ApiHawk/Classes/Api/MemApiBase.cs b/BizHawk.Client.ApiHawk/Classes/Api/MemApiBase.cs index dd6a6377a9..523b6384f3 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/MemApiBase.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/MemApiBase.cs @@ -179,11 +179,11 @@ namespace BizHawk.Client.ApiHawk var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)]; if (d.CanPoke()) { - for (var i = 0; i < memoryblock.Count; i++) + foreach (var m in memoryblock) { if (addr < d.Size) { - d.PokeByte(addr++, memoryblock[i]); + d.PokeByte(addr++, m); } else { @@ -197,12 +197,12 @@ namespace BizHawk.Client.ApiHawk } } - protected float ReadFloat(long addr, bool bigendian, string domain = null) + protected float ReadFloat(long addr, bool bigEndian, string domain = null) { var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)]; if (addr < d.Size) { - var val = d.PeekUint(addr, bigendian); + var val = d.PeekUint(addr, bigEndian); var bytes = BitConverter.GetBytes(val); return BitConverter.ToSingle(bytes, 0); } @@ -212,7 +212,7 @@ namespace BizHawk.Client.ApiHawk return 0; } - protected void WriteFloat(long addr, double value, bool bigendian, string domain = null) + protected void WriteFloat(long addr, double value, bool bigEndian, string domain = null) { var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)]; if (d.CanPoke()) @@ -222,7 +222,7 @@ namespace BizHawk.Client.ApiHawk var dv = (float)value; var bytes = BitConverter.GetBytes(dv); var v = BitConverter.ToUInt32(bytes, 0); - d.PokeUint(addr, v, bigendian); + d.PokeUint(addr, v, bigEndian); } else { diff --git a/BizHawk.Client.ApiHawk/Classes/Api/MemorySaveStateApi.cs b/BizHawk.Client.ApiHawk/Classes/Api/MemorySaveStateApi.cs index b22eaa7540..39635ef4b9 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/MemorySaveStateApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/MemorySaveStateApi.cs @@ -34,11 +34,9 @@ namespace BizHawk.Client.ApiHawk { var state = _memorySavestates[guid]; - using (var ms = new MemoryStream(state)) - using (var br = new BinaryReader(ms)) - { - StatableCore.LoadStateBinary(br); - } + using var ms = new MemoryStream(state); + using var br = new BinaryReader(ms); + StatableCore.LoadStateBinary(br); } catch { diff --git a/BizHawk.Client.ApiHawk/Classes/Api/UserDataApi.cs b/BizHawk.Client.ApiHawk/Classes/Api/UserDataApi.cs index 735fe397b9..a41b073c22 100644 --- a/BizHawk.Client.ApiHawk/Classes/Api/UserDataApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/Api/UserDataApi.cs @@ -1,6 +1,4 @@ using System; -using System.ComponentModel; - using BizHawk.Client.Common; namespace BizHawk.Client.ApiHawk @@ -26,12 +24,9 @@ namespace BizHawk.Client.ApiHawk public object Get(string key) { - if (Global.UserBag.ContainsKey(key)) - { - return Global.UserBag[key]; - } - - return null; + return Global.UserBag.ContainsKey(key) + ? Global.UserBag[key] + : null; } public void Clear() diff --git a/BizHawk.Client.ApiHawk/Classes/BasicApiProvider.cs b/BizHawk.Client.ApiHawk/Classes/BasicApiProvider.cs index 75da59a6d4..01166a6496 100644 --- a/BizHawk.Client.ApiHawk/Classes/BasicApiProvider.cs +++ b/BizHawk.Client.ApiHawk/Classes/BasicApiProvider.cs @@ -14,7 +14,7 @@ namespace BizHawk.Client.ApiHawk /// public class BasicApiProvider : IExternalApiProvider { - private readonly Dictionary _Apis = new Dictionary(); + private readonly Dictionary _apis = new Dictionary(); public BasicApiProvider(IApiContainer container) { @@ -25,7 +25,7 @@ namespace BizHawk.Client.ApiHawk // this also fully allows apis that are not IExternalApi var libs = container.Libraries; - _Apis = libs; + _apis = libs; } /// @@ -40,7 +40,7 @@ namespace BizHawk.Client.ApiHawk throw new ArgumentNullException(nameof(api)); } - _Apis[typeof(T)] = api; + _apis[typeof(T)] = api; } public T GetApi() @@ -51,8 +51,7 @@ namespace BizHawk.Client.ApiHawk public object GetApi(Type t) { - IExternalApi Api; - KeyValuePair[] k = _Apis.Where(kvp => t.IsAssignableFrom(kvp.Key)).ToArray(); + KeyValuePair[] k = _apis.Where(kvp => t.IsAssignableFrom(kvp.Key)).ToArray(); if (k.Length > 0) { return k[0].Value; @@ -69,15 +68,9 @@ namespace BizHawk.Client.ApiHawk public bool HasApi(Type t) { - return _Apis.ContainsKey(t); + return _apis.ContainsKey(t); } - public IEnumerable AvailableApis - { - get - { - return _Apis.Select(d => d.Key); - } - } + public IEnumerable AvailableApis => _apis.Select(d => d.Key); } } diff --git a/BizHawk.Client.ApiHawk/Classes/BizHawkSystemIdToCoreSystemEnumConverter.cs b/BizHawk.Client.ApiHawk/Classes/BizHawkSystemIdToCoreSystemEnumConverter.cs index 0957068e5b..22fb84308d 100644 --- a/BizHawk.Client.ApiHawk/Classes/BizHawkSystemIdToCoreSystemEnumConverter.cs +++ b/BizHawk.Client.ApiHawk/Classes/BizHawkSystemIdToCoreSystemEnumConverter.cs @@ -236,7 +236,7 @@ namespace BizHawk.Client.ApiHawk return "AmstradCPC"; default: - throw new IndexOutOfRangeException($"{value.ToString()} is missing in convert list"); + throw new IndexOutOfRangeException($"{value} is missing in convert list"); } } diff --git a/BizHawk.Client.ApiHawk/Classes/ClientApi.cs b/BizHawk.Client.ApiHawk/Classes/ClientApi.cs index 9222ee4689..fa3c19d927 100644 --- a/BizHawk.Client.ApiHawk/Classes/ClientApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/ClientApi.cs @@ -16,7 +16,7 @@ namespace BizHawk.Client.ApiHawk { /// /// This class contains some methods that - /// interract with BizHawk client + /// interact with BizHawk client /// public static class ClientApi { @@ -46,11 +46,11 @@ namespace BizHawk.Client.ApiHawk /// public static event BeforeQuickSaveEventHandler BeforeQuickSave; /// - /// Occurs when a ROM is succesfully loaded + /// Occurs when a ROM is successfully loaded /// public static event EventHandler RomLoaded; /// - /// Occurs when a savestate is sucessfully loaded + /// Occurs when a savestate is successfully loaded /// public static event StateLoadedEventHandler StateLoaded; /// @@ -63,7 +63,7 @@ namespace BizHawk.Client.ApiHawk #region cTor(s) /// - /// Static stuff initilization + /// Static stuff initialization /// static ClientApi() { @@ -210,10 +210,7 @@ namespace BizHawk.Client.ApiHawk /// User friendly name for saved state public static void OnStateLoaded(object sender, string stateName) { - if (StateLoaded != null) - { - StateLoaded(sender, new StateLoadedEventArgs(stateName)); - } + StateLoaded?.Invoke(sender, new StateLoadedEventArgs(stateName)); } /// @@ -223,10 +220,7 @@ namespace BizHawk.Client.ApiHawk /// User friendly name for saved state public static void OnStateSaved(object sender, string stateName) { - if (StateSaved != null) - { - StateSaved(sender, new StateSavedEventArgs(stateName)); - } + StateSaved?.Invoke(sender, new StateSavedEventArgs(stateName)); } /// @@ -249,7 +243,7 @@ namespace BizHawk.Client.ApiHawk /// /// Save a state with specified name /// - /// Savetate friendly name + /// Savestate friendly name public static void SaveState(string name) { InvokeMainFormMethod("SaveState", new object[] { Path.Combine(PathManager.GetSaveStatePath(Global.Game), $"{name}.State"), name, false }); @@ -417,10 +411,10 @@ namespace BizHawk.Client.ApiHawk /// private static void GetAllInputs() { - AutoFireStickyXorAdapter joypadAdaptor = Global.AutofireStickyXORAdapter; + AutoFireStickyXorAdapter joypadAdapter = Global.AutofireStickyXORAdapter; - IEnumerable pressedButtons = from button in joypadAdaptor.Definition.BoolButtons - where joypadAdaptor.IsPressed(button) + IEnumerable pressedButtons = from button in joypadAdapter.Definition.BoolButtons + where joypadAdapter.IsPressed(button) select button; foreach (Joypad j in allJoypads) @@ -448,8 +442,8 @@ namespace BizHawk.Client.ApiHawk { for (int i = 1; i <= RunningSystem.MaxControllers; i++) { - allJoypads[i - 1].AnalogX = joypadAdaptor.GetFloat($"P{i} X Axis"); - allJoypads[i - 1].AnalogY = joypadAdaptor.GetFloat($"P{i} Y Axis"); + allJoypads[i - 1].AnalogX = joypadAdapter.GetFloat($"P{i} X Axis"); + allJoypads[i - 1].AnalogY = joypadAdapter.GetFloat($"P{i} Y Axis"); } } } @@ -652,7 +646,7 @@ namespace BizHawk.Client.ApiHawk object osd = f.GetValue(null); t = f.GetType(); MethodInfo m = t.GetMethod("AddMessage"); - m.Invoke(osd, new Object[] { $"Window size set to {size}x" }); + m.Invoke(osd, new object[] { $"Window size set to {size}x" }); } else { diff --git a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickLoadEventArgs.cs b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickLoadEventArgs.cs index 85fe83d1f8..9eb331e570 100644 --- a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickLoadEventArgs.cs +++ b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickLoadEventArgs.cs @@ -7,62 +7,26 @@ namespace BizHawk.Client.ApiHawk.Classes.Events /// public sealed class BeforeQuickLoadEventArgs : EventArgs { - #region Fields - - private bool _Handled = false; - private string _QuickSaveSlotName; - - #endregion - - #region cTor(s) - internal BeforeQuickLoadEventArgs(string name) { - _QuickSaveSlotName = name; + Name = name; } - #endregion - - #region Properties - /// /// Gets or sets value that defined if saved has been handled or not /// - public bool Handled - { - get - { - return _Handled; - } - set - { - _Handled = value; - } - } + public bool Handled { get; set; } + /// /// Gets quicksave name /// - public string Name - { - get - { - return _QuickSaveSlotName; - } - } + public string Name { get; } /// /// Gets slot used for quicksave /// - public int Slot - { - get - { - return int.Parse(_QuickSaveSlotName.Substring(_QuickSaveSlotName.Length - 1)); - } - } - - #endregion + public int Slot => int.Parse(Name.Substring(Name.Length - 1)); } } diff --git a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickSaveEventArgs.cs b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickSaveEventArgs.cs index b186f82aba..b2a9299e69 100644 --- a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickSaveEventArgs.cs +++ b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/BeforeQuickSaveEventArgs.cs @@ -7,63 +7,25 @@ namespace BizHawk.Client.ApiHawk.Classes.Events /// public sealed class BeforeQuickSaveEventArgs : EventArgs { - #region Fields - - private bool _Handled = false; - private string _QuickSaveSlotName; - - #endregion - - #region cTor(s) - internal BeforeQuickSaveEventArgs(string name) { - _QuickSaveSlotName = name; + Name = name; } - #endregion - - #region Properties - /// /// Gets or sets value that defined if saved has been handled or not /// - public bool Handled - { - get - { - return _Handled; - } - set - { - _Handled = value; - } - } - + public bool Handled { get; set; } /// /// Gets quicksave name /// - public string Name - { - get - { - return _QuickSaveSlotName; - } - } + public string Name { get; } /// /// Gets slot used for quicksave /// - public int Slot - { - get - { - return int.Parse(_QuickSaveSlotName.Substring(_QuickSaveSlotName.Length - 1)); - } - } - - #endregion + public int Slot => int.Parse(Name.Substring(Name.Length - 1)); } } diff --git a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateLoadedEventArgs.cs b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateLoadedEventArgs.cs index 0dfc5b3729..b3a1afdf2f 100644 --- a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateLoadedEventArgs.cs +++ b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateLoadedEventArgs.cs @@ -7,38 +7,18 @@ namespace BizHawk.Client.ApiHawk.Classes.Events /// public sealed class StateLoadedEventArgs: EventArgs { - #region Fields - - string _Name; - - #endregion - - #region cTor(s) - /// /// Initialize a new instance of /// /// User friendly name of loaded state internal StateLoadedEventArgs(string stateName) { - _Name = stateName; + Name = stateName; } - #endregion - - #region Properties - /// /// Gets user friendly name of the loaded savestate /// - public string Name - { - get - { - return _Name; - } - } - - #endregion + public string Name { get; } } } diff --git a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateSavedEventArgs.cs b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateSavedEventArgs.cs index a2d00690eb..9cd197e8ab 100644 --- a/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateSavedEventArgs.cs +++ b/BizHawk.Client.ApiHawk/Classes/Events/EventArgs/StateSavedEventArgs.cs @@ -7,38 +7,18 @@ namespace BizHawk.Client.ApiHawk.Classes.Events /// public sealed class StateSavedEventArgs : EventArgs { - #region Fields - - string _Name; - - #endregion - - #region cTor(s) - /// /// Initialize a new instance of /// /// User friendly name of loaded state internal StateSavedEventArgs(string stateName) { - _Name = stateName; + Name = stateName; } - #endregion - - #region Properties - /// /// Gets user friendly name of the loaded savestate /// - public string Name - { - get - { - return _Name; - } - } - - #endregion + public string Name { get; } } } diff --git a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs index b9371e7358..8565448739 100644 --- a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs +++ b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs @@ -18,15 +18,15 @@ namespace BizHawk.Client.ApiHawk { #region Fields - private static FileSystemWatcher directoryMonitor; - private static List menuItems = new List(); + private static readonly FileSystemWatcher DirectoryMonitor; + private static readonly List MenuItems = new List(); #endregion #region cTor(s) /// - /// Initilization + /// Initialization /// static ExternalToolManager() { @@ -34,12 +34,15 @@ namespace BizHawk.Client.ApiHawk { Directory.CreateDirectory(Global.Config.PathEntries["Global", "External Tools"].Path); } - directoryMonitor = new FileSystemWatcher(Global.Config.PathEntries["Global", "External Tools"].Path, "*.dll"); - directoryMonitor.IncludeSubdirectories = false; - directoryMonitor.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName; - directoryMonitor.Filter = "*.dll"; - directoryMonitor.Created += new FileSystemEventHandler(DirectoryMonitor_Created); - directoryMonitor.EnableRaisingEvents = true; + + DirectoryMonitor = new FileSystemWatcher(Global.Config.PathEntries["Global", "External Tools"].Path, "*.dll") + { + IncludeSubdirectories = false + , NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName + , Filter = "*.dll" + }; + DirectoryMonitor.Created += DirectoryMonitor_Created; + DirectoryMonitor.EnableRaisingEvents = true; ClientApi.RomLoaded += delegate { BuildToolStrip(); }; @@ -51,18 +54,18 @@ namespace BizHawk.Client.ApiHawk #region Methods /// - /// Build the toolstrip menu + /// Build the ToolStrip menu /// private static void BuildToolStrip() { - menuItems.Clear(); - if (Directory.Exists(directoryMonitor.Path)) + MenuItems.Clear(); + if (Directory.Exists(DirectoryMonitor.Path)) { - DirectoryInfo dInfo = new DirectoryInfo(directoryMonitor.Path); + DirectoryInfo dInfo = new DirectoryInfo(DirectoryMonitor.Path); foreach (FileInfo fi in dInfo.GetFiles("*.dll")) { - menuItems.Add(GenerateToolTipFromFileName(fi.FullName)); + MenuItems.Add(GenerateToolTipFromFileName(fi.FullName)); } } } @@ -78,20 +81,17 @@ namespace BizHawk.Client.ApiHawk /// For the moment, you could only load a dll that have a form (which implements ) private static ToolStripMenuItem GenerateToolTipFromFileName(string fileName) { - Type customFormType; - Assembly externalToolFile; ToolStripMenuItem item = null; try { BizHawk.Common.Win32Hacks.RemoveMOTW(fileName); - externalToolFile = Assembly.LoadFrom(fileName); + var externalToolFile = Assembly.LoadFrom(fileName); object[] attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolAttribute), false); if (attributes != null && attributes.Count() == 1) { BizHawkExternalToolAttribute attribute = (BizHawkExternalToolAttribute)attributes[0]; - item = new ToolStripMenuItem(attribute.Name); - item.ToolTipText = attribute.Description; + item = new ToolStripMenuItem(attribute.Name) { ToolTipText = attribute.Description }; if (attribute.IconResourceName != "") { Stream s = externalToolFile.GetManifestResourceStream($"{externalToolFile.GetName().Name}.{attribute.IconResourceName}"); @@ -101,7 +101,7 @@ namespace BizHawk.Client.ApiHawk } } - customFormType = externalToolFile.GetTypes().FirstOrDefault(t => t != null && t.FullName == "BizHawk.Client.EmuHawk.CustomMainForm"); + var customFormType = externalToolFile.GetTypes().FirstOrDefault(t => t != null && t.FullName == "BizHawk.Client.EmuHawk.CustomMainForm"); if (customFormType == null) { item.ToolTipText = "Does not have a CustomMainForm"; @@ -110,7 +110,7 @@ namespace BizHawk.Client.ApiHawk item.Tag = fileName; attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolUsageAttribute), false); - if (attributes != null && attributes.Count() == 1) + if (attributes != null && attributes.Length == 1) { BizHawkExternalToolUsageAttribute attribute2 = (BizHawkExternalToolUsageAttribute)attributes[0]; if(Global.Emulator.SystemId == "NULL" && attribute2.ToolUsage != BizHawkExternalToolUsage.Global) @@ -132,9 +132,10 @@ namespace BizHawk.Client.ApiHawk } else { - item = new ToolStripMenuItem(externalToolFile.GetName().Name); - item.ToolTipText = "BizHawkExternalTool attribute hasn't been found"; - item.Enabled = false; + item = new ToolStripMenuItem(externalToolFile.GetName().Name) + { + ToolTipText = "BizHawkExternalTool attribute hasn't been found", Enabled = false + }; } } catch (BadImageFormatException) @@ -144,7 +145,7 @@ namespace BizHawk.Client.ApiHawk item.Enabled = false; } -#if DEBUG //I added special debug stuff to get additionnal informations. Don(t think it can be usefull for released versions +#if DEBUG //I added special debug stuff to get additional information. Don't think it can be useful for released versions catch (ReflectionTypeLoadException ex) { foreach (Exception e in ex.LoaderExceptions) @@ -174,7 +175,7 @@ namespace BizHawk.Client.ApiHawk /// Event arguments private static void DirectoryMonitor_Created(object sender, FileSystemEventArgs e) { - menuItems.Add(GenerateToolTipFromFileName(e.FullPath)); + MenuItems.Add(GenerateToolTipFromFileName(e.FullPath)); } #endregion @@ -185,13 +186,7 @@ namespace BizHawk.Client.ApiHawk /// Gets a prebuild /// This list auto-updated by the itself /// - public static IEnumerable ToolStripMenu - { - get - { - return menuItems; - } - } + public static IEnumerable ToolStripMenu => MenuItems; #endregion } diff --git a/BizHawk.Client.ApiHawk/Classes/Joypad.cs b/BizHawk.Client.ApiHawk/Classes/Joypad.cs index 6848a106bd..927c855803 100644 --- a/BizHawk.Client.ApiHawk/Classes/Joypad.cs +++ b/BizHawk.Client.ApiHawk/Classes/Joypad.cs @@ -80,14 +80,8 @@ namespace BizHawk.Client.ApiHawk /// The value you get will aways be rounded to 0 decimal public float AnalogX { - get - { - return (float)Math.Round(_AnalogX, 0); - } - set - { - _AnalogX = value; - } + get => (float)Math.Round(_AnalogX, 0); + set => _AnalogX = value; } /// @@ -96,14 +90,8 @@ namespace BizHawk.Client.ApiHawk /// The value you get will aways be rounded to 0 decimal public float AnalogY { - get - { - return (float)Math.Round(_AnalogY, 0); - } - set - { - _AnalogY = value; - } + get => (float)Math.Round(_AnalogY, 0); + set => _AnalogY = value; } /// @@ -113,10 +101,7 @@ namespace BizHawk.Client.ApiHawk /// It overrides all existing inputs public JoypadButton Inputs { - get - { - return _PressedButtons; - } + get => _PressedButtons; set { value &= _System.AvailableButtons; @@ -127,13 +112,7 @@ namespace BizHawk.Client.ApiHawk /// /// Gets for current /// - public SystemInfo System - { - get - { - return _System; - } - } + public SystemInfo System => _System; #endregion } diff --git a/BizHawk.Client.ApiHawk/Classes/JoypadStringToEnumConverter.cs b/BizHawk.Client.ApiHawk/Classes/JoypadStringToEnumConverter.cs index 638e93b329..213b9ef787 100644 --- a/BizHawk.Client.ApiHawk/Classes/JoypadStringToEnumConverter.cs +++ b/BizHawk.Client.ApiHawk/Classes/JoypadStringToEnumConverter.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.ApiHawk return JoypadButton.A; case "B": - return JoypadButton.B; + return JoypadButton.B; case "B1": return JoypadButton.B1; diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index ffab5d0978..22b064bb2c 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -220,11 +220,13 @@ True True True + True True True True True True + True True True True @@ -234,6 +236,7 @@ True True True + True True True True @@ -267,6 +270,7 @@ True True True + True True True True