ConfigurationFileFormat.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /// Change System Region
  65. /// </summary>
  66. public Region SystemRegion { get; set; }
  67. /// <summary>
  68. /// Enables or disables Docked Mode
  69. /// </summary>
  70. public bool DockedMode { get; set; }
  71. /// <summary>
  72. /// Enables or disables Discord Rich Presence
  73. /// </summary>
  74. public bool EnableDiscordIntegration { get; set; }
  75. /// <summary>
  76. /// Enables or disables Vertical Sync
  77. /// </summary>
  78. public bool EnableVsync { get; set; }
  79. /// <summary>
  80. /// Enables or disables multi-core scheduling of threads
  81. /// </summary>
  82. public bool EnableMulticoreScheduling { get; set; }
  83. /// <summary>
  84. /// Enables integrity checks on Game content files
  85. /// </summary>
  86. public bool EnableFsIntegrityChecks { get; set; }
  87. /// <summary>
  88. /// Enables FS access log output to the console. Possible modes are 0-3
  89. /// </summary>
  90. public int FsGlobalAccessLogMode { get; set; }
  91. /// <summary>
  92. /// Enable or disable ignoring missing services
  93. /// </summary>
  94. public bool IgnoreMissingServices { get; set; }
  95. /// <summary>
  96. /// The primary controller's type
  97. /// </summary>
  98. public ControllerType ControllerType { get; set; }
  99. /// <summary>
  100. /// Used to toggle columns in the GUI
  101. /// </summary>
  102. public GuiColumns GuiColumns { get; set; }
  103. /// <summary>
  104. /// A list of directories containing games to be used to load games into the games list
  105. /// </summary>
  106. public List<string> GameDirs { get; set; }
  107. /// <summary>
  108. /// Enable or disable custom themes in the GUI
  109. /// </summary>
  110. public bool EnableCustomTheme { get; set; }
  111. /// <summary>
  112. /// Path to custom GUI theme
  113. /// </summary>
  114. public string CustomThemePath { get; set; }
  115. /// <summary>
  116. /// Enable or disable keyboard support (Independent from controllers binding)
  117. /// </summary>
  118. public bool EnableKeyboard { get; set; }
  119. /// <summary>
  120. /// Keyboard control bindings
  121. /// </summary>
  122. public NpadKeyboard KeyboardControls { get; set; }
  123. /// <summary>
  124. /// Controller control bindings
  125. /// </summary>
  126. public NpadController JoystickControls { get; set; }
  127. /// <summary>
  128. /// Loads a configuration file from disk
  129. /// </summary>
  130. /// <param name="path">The path to the JSON configuration file</param>
  131. public static ConfigurationFileFormat Load(string path)
  132. {
  133. var resolver = CompositeResolver.Create(
  134. new[] { new ConfigurationEnumFormatter<Key>() },
  135. new[] { StandardResolver.AllowPrivateSnakeCase }
  136. );
  137. using (Stream stream = File.OpenRead(path))
  138. {
  139. return JsonSerializer.Deserialize<ConfigurationFileFormat>(stream, resolver);
  140. }
  141. }
  142. /// <summary>
  143. /// Save a configuration file to disk
  144. /// </summary>
  145. /// <param name="path">The path to the JSON configuration file</param>
  146. public void SaveConfig(string path)
  147. {
  148. IJsonFormatterResolver resolver = CompositeResolver.Create(
  149. new[] { new ConfigurationEnumFormatter<Key>() },
  150. new[] { StandardResolver.AllowPrivateSnakeCase }
  151. );
  152. byte[] data = JsonSerializer.Serialize(this, resolver);
  153. File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
  154. }
  155. private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
  156. where T : struct
  157. {
  158. public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
  159. {
  160. formatterResolver.GetFormatterWithVerify<string>()
  161. .Serialize(ref writer, value.ToString(), formatterResolver);
  162. }
  163. public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
  164. {
  165. if (reader.ReadIsNull())
  166. {
  167. return default(T);
  168. }
  169. string enumName = formatterResolver.GetFormatterWithVerify<string>()
  170. .Deserialize(ref reader, formatterResolver);
  171. if (Enum.TryParse<T>(enumName, out T result))
  172. {
  173. return result;
  174. }
  175. return default(T);
  176. }
  177. }
  178. }
  179. }