ConfigurationFileFormat.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using JsonPrettyPrinterPlus;
  2. using Ryujinx.Common.Logging;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. using Utf8Json;
  8. using Utf8Json.Resolvers;
  9. using Ryujinx.Configuration.System;
  10. using Ryujinx.Configuration.Hid;
  11. using Ryujinx.Common.Configuration.Hid;
  12. using Ryujinx.UI.Input;
  13. using Ryujinx.Configuration.Ui;
  14. namespace Ryujinx.Configuration
  15. {
  16. public class ConfigurationFileFormat
  17. {
  18. public int Version { get; set; }
  19. /// <summary>
  20. /// Dumps shaders in this local directory
  21. /// </summary>
  22. public string GraphicsShadersDumpPath { get; set; }
  23. /// <summary>
  24. /// Enables printing debug log messages
  25. /// </summary>
  26. public bool LoggingEnableDebug { get; set; }
  27. /// <summary>
  28. /// Enables printing stub log messages
  29. /// </summary>
  30. public bool LoggingEnableStub { get; set; }
  31. /// <summary>
  32. /// Enables printing info log messages
  33. /// </summary>
  34. public bool LoggingEnableInfo { get; set; }
  35. /// <summary>
  36. /// Enables printing warning log messages
  37. /// </summary>
  38. public bool LoggingEnableWarn { get; set; }
  39. /// <summary>
  40. /// Enables printing error log messages
  41. /// </summary>
  42. public bool LoggingEnableError { get; set; }
  43. /// <summary>
  44. /// Enables printing guest log messages
  45. /// </summary>
  46. public bool LoggingEnableGuest { get; set; }
  47. /// <summary>
  48. /// Enables printing FS access log messages
  49. /// </summary>
  50. public bool LoggingEnableFsAccessLog { get; set; }
  51. /// <summary>
  52. /// Controls which log messages are written to the log targets
  53. /// </summary>
  54. public LogClass[] LoggingFilteredClasses { get; set; }
  55. /// <summary>
  56. /// Enables or disables logging to a file on disk
  57. /// </summary>
  58. public bool EnableFileLog { get; set; }
  59. /// <summary>
  60. /// Change System Language
  61. /// </summary>
  62. public Language SystemLanguage { get; set; }
  63. /// <summary>
  64. /// Enables or disables Docked Mode
  65. /// </summary>
  66. public bool DockedMode { get; set; }
  67. /// <summary>
  68. /// Enables or disables Discord Rich Presence
  69. /// </summary>
  70. public bool EnableDiscordIntegration { get; set; }
  71. /// <summary>
  72. /// Enables or disables Vertical Sync
  73. /// </summary>
  74. public bool EnableVsync { get; set; }
  75. /// <summary>
  76. /// Enables or disables multi-core scheduling of threads
  77. /// </summary>
  78. public bool EnableMulticoreScheduling { get; set; }
  79. /// <summary>
  80. /// Enables integrity checks on Game content files
  81. /// </summary>
  82. public bool EnableFsIntegrityChecks { get; set; }
  83. /// <summary>
  84. /// Enables FS access log output to the console. Possible modes are 0-3
  85. /// </summary>
  86. public int FsGlobalAccessLogMode { get; set; }
  87. /// <summary>
  88. /// Enable or disable ignoring missing services
  89. /// </summary>
  90. public bool IgnoreMissingServices { get; set; }
  91. /// <summary>
  92. /// The primary controller's type
  93. /// </summary>
  94. public ControllerType ControllerType { get; set; }
  95. /// <summary>
  96. /// Used to toggle columns in the GUI
  97. /// </summary>
  98. public GuiColumns GuiColumns { get; set; }
  99. /// <summary>
  100. /// A list of directories containing games to be used to load games into the games list
  101. /// </summary>
  102. public List<string> GameDirs { get; set; }
  103. /// <summary>
  104. /// Enable or disable custom themes in the GUI
  105. /// </summary>
  106. public bool EnableCustomTheme { get; set; }
  107. /// <summary>
  108. /// Path to custom GUI theme
  109. /// </summary>
  110. public string CustomThemePath { get; set; }
  111. /// <summary>
  112. /// Enable or disable keyboard support (Independent from controllers binding)
  113. /// </summary>
  114. public bool EnableKeyboard { get; set; }
  115. /// <summary>
  116. /// Keyboard control bindings
  117. /// </summary>
  118. public NpadKeyboard KeyboardControls { get; set; }
  119. /// <summary>
  120. /// Controller control bindings
  121. /// </summary>
  122. public NpadController JoystickControls { get; set; }
  123. /// <summary>
  124. /// Loads a configuration file from disk
  125. /// </summary>
  126. /// <param name="path">The path to the JSON configuration file</param>
  127. public static ConfigurationFileFormat Load(string path)
  128. {
  129. var resolver = CompositeResolver.Create(
  130. new[] { new ConfigurationEnumFormatter<Key>() },
  131. new[] { StandardResolver.AllowPrivateSnakeCase }
  132. );
  133. using (Stream stream = File.OpenRead(path))
  134. {
  135. return JsonSerializer.Deserialize<ConfigurationFileFormat>(stream, resolver);
  136. }
  137. }
  138. /// <summary>
  139. /// Save a configuration file to disk
  140. /// </summary>
  141. /// <param name="path">The path to the JSON configuration file</param>
  142. public void SaveConfig(string path)
  143. {
  144. IJsonFormatterResolver resolver = CompositeResolver.Create(
  145. new[] { new ConfigurationEnumFormatter<Key>() },
  146. new[] { StandardResolver.AllowPrivateSnakeCase }
  147. );
  148. byte[] data = JsonSerializer.Serialize(this, resolver);
  149. File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
  150. }
  151. private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
  152. where T : struct
  153. {
  154. public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
  155. {
  156. formatterResolver.GetFormatterWithVerify<string>()
  157. .Serialize(ref writer, value.ToString(), formatterResolver);
  158. }
  159. public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
  160. {
  161. if (reader.ReadIsNull())
  162. {
  163. return default(T);
  164. }
  165. string enumName = formatterResolver.GetFormatterWithVerify<string>()
  166. .Deserialize(ref reader, formatterResolver);
  167. if (Enum.TryParse<T>(enumName, out T result))
  168. {
  169. return result;
  170. }
  171. return default(T);
  172. }
  173. }
  174. }
  175. }