From 068f9bff2e7beafe365f4767d5ec1685a47d38af Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 20 Feb 2018 02:54:00 -0800 Subject: [PATCH] Misc language usage simplifications (#26) un-nest some logic add some xmldoc simplify ini parse --- Ryujinx/Config.cs | 23 +++++++++++++---------- Ryujinx/Cpu/Translation/AILOpCodeStore.cs | 4 +--- Ryujinx/Hid/HidController.cs | 6 +++++- Ryujinx/Hid/JoyCon.cs | 3 +++ Ryujinx/Logging.cs | 2 +- Ryujinx/OsHle/Handles/HSharedMem.cs | 10 ++-------- Ryujinx/OsHle/Horizon.cs | 7 +------ Ryujinx/Switch.cs | 5 +---- Ryujinx/VirtualFs.cs | 8 ++++---- 9 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Ryujinx/Config.cs b/Ryujinx/Config.cs index e211441fbc..b536142111 100644 --- a/Ryujinx/Config.cs +++ b/Ryujinx/Config.cs @@ -20,7 +20,9 @@ namespace Ryujinx public static void Read() { - IniParser Parser = new IniParser(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Ryujinx.conf")); + var iniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + var iniPath = Path.Combine(iniFolder, "Ryujinx.conf"); + IniParser Parser = new IniParser(iniPath); LoggingEnableInfo = Convert.ToBoolean(Parser.Value("Logging_Enable_Info")); LoggingEnableTrace = Convert.ToBoolean(Parser.Value("Logging_Enable_Trace")); @@ -70,23 +72,24 @@ namespace Ryujinx // https://stackoverflow.com/a/37772571 public class IniParser { - private Dictionary Values; + private readonly Dictionary Values; public IniParser(string Path) { Values = File.ReadLines(Path) - .Where(Line => (!String.IsNullOrWhiteSpace(Line) && !Line.StartsWith("#"))) - .Select(Line => Line.Split(new char[] { '=' }, 2, 0)) + .Where(Line => !string.IsNullOrWhiteSpace(Line) && !Line.StartsWith('#')) + .Select(Line => Line.Split('=', 2)) .ToDictionary(Parts => Parts[0].Trim(), Parts => Parts.Length > 1 ? Parts[1].Trim() : null); } - public string Value(string Name, string Value = null) + /// + /// Gets the setting value for the requested setting . + /// + /// Setting Name + /// Default value of the setting + public string Value(string Name, string defaultValue = null) { - if (Values != null && Values.ContainsKey(Name)) - { - return Values[Name]; - } - return Value; + return Values.TryGetValue(Name, out var value) ? value : defaultValue; } } } diff --git a/Ryujinx/Cpu/Translation/AILOpCodeStore.cs b/Ryujinx/Cpu/Translation/AILOpCodeStore.cs index 34b26fe289..c4ea53abaf 100644 --- a/Ryujinx/Cpu/Translation/AILOpCodeStore.cs +++ b/Ryujinx/Cpu/Translation/AILOpCodeStore.cs @@ -10,10 +10,8 @@ namespace ChocolArm64.Translation public AIoType IoType { get; private set; } public ARegisterSize RegisterSize { get; private set; } - - public AILOpCodeStore(int Index, AIoType IoType) : this(Index, IoType, ARegisterSize.Int64) { } - public AILOpCodeStore(int Index, AIoType IoType, ARegisterSize RegisterSize) + public AILOpCodeStore(int Index, AIoType IoType, ARegisterSize RegisterSize = ARegisterSize.Int64) { this.IoType = IoType; this.Index = Index; diff --git a/Ryujinx/Hid/HidController.cs b/Ryujinx/Hid/HidController.cs index 433d7b9bad..7dd1984120 100644 --- a/Ryujinx/Hid/HidController.cs +++ b/Ryujinx/Hid/HidController.cs @@ -1,7 +1,9 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace Ryujinx { + [Flags] public enum HidControllerKeys { KEY_A = (1 << 0), @@ -79,12 +81,14 @@ namespace Ryujinx Main } + [Flags] public enum HidControllerConnectionState { Controller_State_Connected = (1 << 0), Controller_State_Wired = (1 << 1) } + [Flags] public enum HidControllerType { ControllerType_ProController = (1 << 0), diff --git a/Ryujinx/Hid/JoyCon.cs b/Ryujinx/Hid/JoyCon.cs index 9dde2b70a8..8c9518e58e 100644 --- a/Ryujinx/Hid/JoyCon.cs +++ b/Ryujinx/Hid/JoyCon.cs @@ -1,5 +1,8 @@ namespace Ryujinx { + /// + /// Common RGB color hex codes for JoyCon coloring. + /// public enum JoyConColor //Thanks to CTCaer { Body_Grey = 0x828282, diff --git a/Ryujinx/Logging.cs b/Ryujinx/Logging.cs index 308f068f84..2ae858b4ee 100644 --- a/Ryujinx/Logging.cs +++ b/Ryujinx/Logging.cs @@ -7,7 +7,7 @@ namespace Ryujinx public static class Logging { private static Stopwatch ExecutionTime = new Stopwatch(); - private static string LogFileName = "Ryujinx.log"; + private const string LogFileName = "Ryujinx.log"; public static bool EnableInfo = Config.LoggingEnableInfo; public static bool EnableTrace = Config.LoggingEnableTrace; diff --git a/Ryujinx/OsHle/Handles/HSharedMem.cs b/Ryujinx/OsHle/Handles/HSharedMem.cs index a493276a2b..4f943ebcd0 100644 --- a/Ryujinx/OsHle/Handles/HSharedMem.cs +++ b/Ryujinx/OsHle/Handles/HSharedMem.cs @@ -23,10 +23,7 @@ namespace Ryujinx.OsHle.Handles { Positions.Add(Position); - if (MemoryMapped != null) - { - MemoryMapped(this, EventArgs.Empty); - } + MemoryMapped?.Invoke(this, EventArgs.Empty); } } @@ -36,10 +33,7 @@ namespace Ryujinx.OsHle.Handles { Positions.Remove(Position); - if (MemoryUnmapped != null) - { - MemoryUnmapped(this, EventArgs.Empty); - } + MemoryUnmapped?.Invoke(this, EventArgs.Empty); } } diff --git a/Ryujinx/OsHle/Horizon.cs b/Ryujinx/OsHle/Horizon.cs index e72c62dc0a..b9af69c2ff 100644 --- a/Ryujinx/OsHle/Horizon.cs +++ b/Ryujinx/OsHle/Horizon.cs @@ -165,12 +165,7 @@ namespace Ryujinx.OsHle internal bool TryGetProcess(int ProcessId, out Process Process) { - if (!Processes.TryGetValue(ProcessId, out Process)) - { - return false; - } - - return true; + return Processes.TryGetValue(ProcessId, out Process); } internal void CloseHandle(int Handle) diff --git a/Ryujinx/Switch.cs b/Ryujinx/Switch.cs index b5874051ec..4022061bc6 100644 --- a/Ryujinx/Switch.cs +++ b/Ryujinx/Switch.cs @@ -30,10 +30,7 @@ namespace Ryujinx internal virtual void OnFinish(EventArgs e) { - if (Finish != null) - { - Finish(this, e); - } + Finish?.Invoke(this, e); } public void Dispose() diff --git a/Ryujinx/VirtualFs.cs b/Ryujinx/VirtualFs.cs index e5579bcf15..98298053f4 100644 --- a/Ryujinx/VirtualFs.cs +++ b/Ryujinx/VirtualFs.cs @@ -37,7 +37,7 @@ namespace Ryujinx public string GetGameSavesPath() => MakeDirAndGetFullPath(SavesPath); - private string MakeDirAndGetFullPath(string Dir) + private static string MakeDirAndGetFullPath(string Dir) { string FullPath = Path.Combine(GetBasePath(), Dir); @@ -49,7 +49,7 @@ namespace Ryujinx return FullPath; } - public string GetBasePath() + public static string GetBasePath() { return Path.Combine(Directory.GetCurrentDirectory(), BasePath); } @@ -61,9 +61,9 @@ namespace Ryujinx protected virtual void Dispose(bool disposing) { - if (disposing && RomFs != null) + if (disposing) { - RomFs.Dispose(); + RomFs?.Dispose(); } } }