ConfigurationFileFormat.cs 7.0 KB

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