Config.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. namespace Ryujinx
  7. {
  8. public static class Config
  9. {
  10. public static bool LoggingEnableInfo { get; private set; }
  11. public static bool LoggingEnableTrace { get; private set; }
  12. public static bool LoggingEnableDebug { get; private set; }
  13. public static bool LoggingEnableWarn { get; private set; }
  14. public static bool LoggingEnableError { get; private set; }
  15. public static bool LoggingEnableFatal { get; private set; }
  16. public static bool LoggingEnableLogFile { get; private set; }
  17. public static void Read()
  18. {
  19. IniParser Parser = new IniParser(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Ryujinx.conf"));
  20. LoggingEnableInfo = Convert.ToBoolean(Parser.Value("Logging_Enable_Info"));
  21. LoggingEnableTrace = Convert.ToBoolean(Parser.Value("Logging_Enable_Trace"));
  22. LoggingEnableDebug = Convert.ToBoolean(Parser.Value("Logging_Enable_Debug"));
  23. LoggingEnableWarn = Convert.ToBoolean(Parser.Value("Logging_Enable_Warn"));
  24. LoggingEnableError = Convert.ToBoolean(Parser.Value("Logging_Enable_Error"));
  25. LoggingEnableFatal = Convert.ToBoolean(Parser.Value("Logging_Enable_Fatal"));
  26. LoggingEnableLogFile = Convert.ToBoolean(Parser.Value("Logging_Enable_LogFile"));
  27. }
  28. }
  29. // https://stackoverflow.com/a/37772571
  30. public class IniParser
  31. {
  32. private Dictionary<string, string> Values;
  33. public IniParser(string Path)
  34. {
  35. Values = File.ReadLines(Path)
  36. .Where(Line => (!String.IsNullOrWhiteSpace(Line) && !Line.StartsWith("#")))
  37. .Select(Line => Line.Split(new char[] { '=' }, 2, 0))
  38. .ToDictionary(Parts => Parts[0].Trim(), Parts => Parts.Length > 1 ? Parts[1].Trim() : null);
  39. }
  40. public string Value(string Name, string Value = null)
  41. {
  42. if (Values != null && Values.ContainsKey(Name))
  43. {
  44. return Values[Name];
  45. }
  46. return Value;
  47. }
  48. }
  49. }