Archived
1
0
Fork 0
forked from Mirror/Ryujinx

Misc language usage simplifications (#26)

un-nest some logic
add some xmldoc
simplify ini parse
This commit is contained in:
Kurt 2018-02-20 02:54:00 -08:00 committed by gdkchan
parent dff28df84e
commit 068f9bff2e
9 changed files with 31 additions and 37 deletions

View file

@ -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<string, string> Values;
private readonly Dictionary<string, string> 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)
/// <summary>
/// Gets the setting value for the requested setting <see cref="Name"/>.
/// </summary>
/// <param name="Name">Setting Name</param>
/// <param name="defaultValue">Default value of the setting</param>
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;
}
}
}

View file

@ -11,9 +11,7 @@ namespace ChocolArm64.Translation
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;

View file

@ -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),

View file

@ -1,5 +1,8 @@
namespace Ryujinx
{
/// <summary>
/// Common RGB color hex codes for JoyCon coloring.
/// </summary>
public enum JoyConColor //Thanks to CTCaer
{
Body_Grey = 0x828282,

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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()

View file

@ -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();
}
}
}