Config.cs 2.1 KB

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