ConfigurationState.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Configuration;
  3. using Ryujinx.Common.Configuration.Hid;
  4. using Ryujinx.Common.Configuration.Hid.Keyboard;
  5. using Ryujinx.Common.Logging;
  6. using Ryujinx.Configuration.System;
  7. using Ryujinx.Configuration.Ui;
  8. using System;
  9. using System.Collections.Generic;
  10. namespace Ryujinx.Configuration
  11. {
  12. public class ConfigurationState
  13. {
  14. /// <summary>
  15. /// UI configuration section
  16. /// </summary>
  17. public class UiSection
  18. {
  19. public class Columns
  20. {
  21. public ReactiveObject<bool> FavColumn { get; private set; }
  22. public ReactiveObject<bool> IconColumn { get; private set; }
  23. public ReactiveObject<bool> AppColumn { get; private set; }
  24. public ReactiveObject<bool> DevColumn { get; private set; }
  25. public ReactiveObject<bool> VersionColumn { get; private set; }
  26. public ReactiveObject<bool> TimePlayedColumn { get; private set; }
  27. public ReactiveObject<bool> LastPlayedColumn { get; private set; }
  28. public ReactiveObject<bool> FileExtColumn { get; private set; }
  29. public ReactiveObject<bool> FileSizeColumn { get; private set; }
  30. public ReactiveObject<bool> PathColumn { get; private set; }
  31. public Columns()
  32. {
  33. FavColumn = new ReactiveObject<bool>();
  34. IconColumn = new ReactiveObject<bool>();
  35. AppColumn = new ReactiveObject<bool>();
  36. DevColumn = new ReactiveObject<bool>();
  37. VersionColumn = new ReactiveObject<bool>();
  38. TimePlayedColumn = new ReactiveObject<bool>();
  39. LastPlayedColumn = new ReactiveObject<bool>();
  40. FileExtColumn = new ReactiveObject<bool>();
  41. FileSizeColumn = new ReactiveObject<bool>();
  42. PathColumn = new ReactiveObject<bool>();
  43. }
  44. }
  45. public class ColumnSortSettings
  46. {
  47. public ReactiveObject<int> SortColumnId { get; private set; }
  48. public ReactiveObject<bool> SortAscending { get; private set; }
  49. public ColumnSortSettings()
  50. {
  51. SortColumnId = new ReactiveObject<int>();
  52. SortAscending = new ReactiveObject<bool>();
  53. }
  54. }
  55. /// <summary>
  56. /// Used to toggle columns in the GUI
  57. /// </summary>
  58. public Columns GuiColumns { get; private set; }
  59. /// <summary>
  60. /// Used to configure column sort settings in the GUI
  61. /// </summary>
  62. public ColumnSortSettings ColumnSort { get; private set; }
  63. /// <summary>
  64. /// A list of directories containing games to be used to load games into the games list
  65. /// </summary>
  66. public ReactiveObject<List<string>> GameDirs { get; private set; }
  67. /// <summary>
  68. /// Enable or disable custom themes in the GUI
  69. /// </summary>
  70. public ReactiveObject<bool> EnableCustomTheme { get; private set; }
  71. /// <summary>
  72. /// Path to custom GUI theme
  73. /// </summary>
  74. public ReactiveObject<string> CustomThemePath { get; private set; }
  75. /// <summary>
  76. /// Start games in fullscreen mode
  77. /// </summary>
  78. public ReactiveObject<bool> StartFullscreen { get; private set; }
  79. public UiSection()
  80. {
  81. GuiColumns = new Columns();
  82. ColumnSort = new ColumnSortSettings();
  83. GameDirs = new ReactiveObject<List<string>>();
  84. EnableCustomTheme = new ReactiveObject<bool>();
  85. CustomThemePath = new ReactiveObject<string>();
  86. StartFullscreen = new ReactiveObject<bool>();
  87. }
  88. }
  89. /// <summary>
  90. /// Logger configuration section
  91. /// </summary>
  92. public class LoggerSection
  93. {
  94. /// <summary>
  95. /// Enables printing debug log messages
  96. /// </summary>
  97. public ReactiveObject<bool> EnableDebug { get; private set; }
  98. /// <summary>
  99. /// Enables printing stub log messages
  100. /// </summary>
  101. public ReactiveObject<bool> EnableStub { get; private set; }
  102. /// <summary>
  103. /// Enables printing info log messages
  104. /// </summary>
  105. public ReactiveObject<bool> EnableInfo { get; private set; }
  106. /// <summary>
  107. /// Enables printing warning log messages
  108. /// </summary>
  109. public ReactiveObject<bool> EnableWarn { get; private set; }
  110. /// <summary>
  111. /// Enables printing error log messages
  112. /// </summary>
  113. public ReactiveObject<bool> EnableError { get; private set; }
  114. /// <summary>
  115. /// Enables printing guest log messages
  116. /// </summary>
  117. public ReactiveObject<bool> EnableGuest { get; private set; }
  118. /// <summary>
  119. /// Enables printing FS access log messages
  120. /// </summary>
  121. public ReactiveObject<bool> EnableFsAccessLog { get; private set; }
  122. /// <summary>
  123. /// Controls which log messages are written to the log targets
  124. /// </summary>
  125. public ReactiveObject<LogClass[]> FilteredClasses { get; private set; }
  126. /// <summary>
  127. /// Enables or disables logging to a file on disk
  128. /// </summary>
  129. public ReactiveObject<bool> EnableFileLog { get; private set; }
  130. /// <summary>
  131. /// Controls which OpenGL log messages are recorded in the log
  132. /// </summary>
  133. public ReactiveObject<GraphicsDebugLevel> GraphicsDebugLevel { get; private set; }
  134. public LoggerSection()
  135. {
  136. EnableDebug = new ReactiveObject<bool>();
  137. EnableStub = new ReactiveObject<bool>();
  138. EnableInfo = new ReactiveObject<bool>();
  139. EnableWarn = new ReactiveObject<bool>();
  140. EnableError = new ReactiveObject<bool>();
  141. EnableGuest = new ReactiveObject<bool>();
  142. EnableFsAccessLog = new ReactiveObject<bool>();
  143. FilteredClasses = new ReactiveObject<LogClass[]>();
  144. EnableFileLog = new ReactiveObject<bool>();
  145. EnableFileLog.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFileLog));
  146. GraphicsDebugLevel = new ReactiveObject<GraphicsDebugLevel>();
  147. }
  148. }
  149. /// <summary>
  150. /// System configuration section
  151. /// </summary>
  152. public class SystemSection
  153. {
  154. /// <summary>
  155. /// Change System Language
  156. /// </summary>
  157. public ReactiveObject<Language> Language { get; private set; }
  158. /// <summary>
  159. /// Change System Region
  160. /// </summary>
  161. public ReactiveObject<Region> Region { get; private set; }
  162. /// <summary>
  163. /// Change System TimeZone
  164. /// </summary>
  165. public ReactiveObject<string> TimeZone { get; private set; }
  166. /// <summary>
  167. /// System Time Offset in Seconds
  168. /// </summary>
  169. public ReactiveObject<long> SystemTimeOffset { get; private set; }
  170. /// <summary>
  171. /// Enables or disables Docked Mode
  172. /// </summary>
  173. public ReactiveObject<bool> EnableDockedMode { get; private set; }
  174. /// <summary>
  175. /// Enables or disables profiled translation cache persistency
  176. /// </summary>
  177. public ReactiveObject<bool> EnablePtc { get; private set; }
  178. /// <summary>
  179. /// Enables integrity checks on Game content files
  180. /// </summary>
  181. public ReactiveObject<bool> EnableFsIntegrityChecks { get; private set; }
  182. /// <summary>
  183. /// Enables FS access log output to the console. Possible modes are 0-3
  184. /// </summary>
  185. public ReactiveObject<int> FsGlobalAccessLogMode { get; private set; }
  186. /// <summary>
  187. /// The selected audio backend
  188. /// </summary>
  189. public ReactiveObject<AudioBackend> AudioBackend { get; private set; }
  190. /// <summary>
  191. /// The selected memory manager mode
  192. /// </summary>
  193. public ReactiveObject<MemoryManagerMode> MemoryManagerMode { get; private set; }
  194. /// <summary>
  195. /// Defines the amount of RAM available on the emulated system, and how it is distributed
  196. /// </summary>
  197. public ReactiveObject<bool> ExpandRam { get; private set; }
  198. /// <summary>
  199. /// Enable or disable ignoring missing services
  200. /// </summary>
  201. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  202. public SystemSection()
  203. {
  204. Language = new ReactiveObject<Language>();
  205. Region = new ReactiveObject<Region>();
  206. TimeZone = new ReactiveObject<string>();
  207. SystemTimeOffset = new ReactiveObject<long>();
  208. EnableDockedMode = new ReactiveObject<bool>();
  209. EnableDockedMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableDockedMode));
  210. EnablePtc = new ReactiveObject<bool>();
  211. EnablePtc.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnablePtc));
  212. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  213. EnableFsIntegrityChecks.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFsIntegrityChecks));
  214. FsGlobalAccessLogMode = new ReactiveObject<int>();
  215. FsGlobalAccessLogMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(FsGlobalAccessLogMode));
  216. AudioBackend = new ReactiveObject<AudioBackend>();
  217. AudioBackend.Event += static (sender, e) => LogValueChange(sender, e, nameof(AudioBackend));
  218. MemoryManagerMode = new ReactiveObject<MemoryManagerMode>();
  219. MemoryManagerMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(MemoryManagerMode));
  220. ExpandRam = new ReactiveObject<bool>();
  221. ExpandRam.Event += static (sender, e) => LogValueChange(sender, e, nameof(ExpandRam));
  222. IgnoreMissingServices = new ReactiveObject<bool>();
  223. IgnoreMissingServices.Event += static (sender, e) => LogValueChange(sender, e, nameof(IgnoreMissingServices));
  224. }
  225. }
  226. /// <summary>
  227. /// Hid configuration section
  228. /// </summary>
  229. public class HidSection
  230. {
  231. /// <summary>
  232. /// Enable or disable keyboard support (Independent from controllers binding)
  233. /// </summary>
  234. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  235. /// <summary>
  236. /// Enable or disable mouse support (Independent from controllers binding)
  237. /// </summary>
  238. public ReactiveObject<bool> EnableMouse { get; private set; }
  239. /// <summary>
  240. /// Hotkey Keyboard Bindings
  241. /// </summary>
  242. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  243. /// <summary>
  244. /// Input device configuration.
  245. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  246. /// TODO: Implement a ReactiveList class.
  247. /// </summary>
  248. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  249. public HidSection()
  250. {
  251. EnableKeyboard = new ReactiveObject<bool>();
  252. EnableMouse = new ReactiveObject<bool>();
  253. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  254. InputConfig = new ReactiveObject<List<InputConfig>>();
  255. }
  256. }
  257. /// <summary>
  258. /// Graphics configuration section
  259. /// </summary>
  260. public class GraphicsSection
  261. {
  262. /// <summary>
  263. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  264. /// </summary>
  265. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  266. /// <summary>
  267. /// Aspect Ratio applied to the renderer window.
  268. /// </summary>
  269. public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
  270. /// <summary>
  271. /// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
  272. /// </summary>
  273. public ReactiveObject<int> ResScale { get; private set; }
  274. /// <summary>
  275. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
  276. /// </summary>
  277. public ReactiveObject<float> ResScaleCustom { get; private set; }
  278. /// <summary>
  279. /// Dumps shaders in this local directory
  280. /// </summary>
  281. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  282. /// <summary>
  283. /// Enables or disables Vertical Sync
  284. /// </summary>
  285. public ReactiveObject<bool> EnableVsync { get; private set; }
  286. /// <summary>
  287. /// Enables or disables Shader cache
  288. /// </summary>
  289. public ReactiveObject<bool> EnableShaderCache { get; private set; }
  290. public GraphicsSection()
  291. {
  292. ResScale = new ReactiveObject<int>();
  293. ResScale.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScale));
  294. ResScaleCustom = new ReactiveObject<float>();
  295. ResScaleCustom.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScaleCustom));
  296. MaxAnisotropy = new ReactiveObject<float>();
  297. MaxAnisotropy.Event += static (sender, e) => LogValueChange(sender, e, nameof(MaxAnisotropy));
  298. AspectRatio = new ReactiveObject<AspectRatio>();
  299. AspectRatio.Event += static (sender, e) => LogValueChange(sender, e, nameof(AspectRatio));
  300. ShadersDumpPath = new ReactiveObject<string>();
  301. EnableVsync = new ReactiveObject<bool>();
  302. EnableVsync.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableVsync));
  303. EnableShaderCache = new ReactiveObject<bool>();
  304. EnableShaderCache.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableShaderCache));
  305. }
  306. }
  307. /// <summary>
  308. /// The default configuration instance
  309. /// </summary>
  310. public static ConfigurationState Instance { get; private set; }
  311. /// <summary>
  312. /// The Ui section
  313. /// </summary>
  314. public UiSection Ui { get; private set; }
  315. /// <summary>
  316. /// The Logger section
  317. /// </summary>
  318. public LoggerSection Logger { get; private set; }
  319. /// <summary>
  320. /// The System section
  321. /// </summary>
  322. public SystemSection System { get; private set; }
  323. /// <summary>
  324. /// The Graphics section
  325. /// </summary>
  326. public GraphicsSection Graphics { get; private set; }
  327. /// <summary>
  328. /// The Hid section
  329. /// </summary>
  330. public HidSection Hid { get; private set; }
  331. /// <summary>
  332. /// Enables or disables Discord Rich Presence
  333. /// </summary>
  334. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  335. /// <summary>
  336. /// Checks for updates when Ryujinx starts when enabled
  337. /// </summary>
  338. public ReactiveObject<bool> CheckUpdatesOnStart { get; private set; }
  339. /// <summary>
  340. /// Show "Confirm Exit" Dialog
  341. /// </summary>
  342. public ReactiveObject<bool> ShowConfirmExit { get; private set; }
  343. /// <summary>
  344. /// Hide Cursor on Idle
  345. /// </summary>
  346. public ReactiveObject<bool> HideCursorOnIdle { get; private set; }
  347. private ConfigurationState()
  348. {
  349. Ui = new UiSection();
  350. Logger = new LoggerSection();
  351. System = new SystemSection();
  352. Graphics = new GraphicsSection();
  353. Hid = new HidSection();
  354. EnableDiscordIntegration = new ReactiveObject<bool>();
  355. CheckUpdatesOnStart = new ReactiveObject<bool>();
  356. ShowConfirmExit = new ReactiveObject<bool>();
  357. HideCursorOnIdle = new ReactiveObject<bool>();
  358. }
  359. public ConfigurationFileFormat ToFileFormat()
  360. {
  361. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  362. {
  363. Version = ConfigurationFileFormat.CurrentVersion,
  364. EnableFileLog = Logger.EnableFileLog,
  365. ResScale = Graphics.ResScale,
  366. ResScaleCustom = Graphics.ResScaleCustom,
  367. MaxAnisotropy = Graphics.MaxAnisotropy,
  368. AspectRatio = Graphics.AspectRatio,
  369. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  370. LoggingEnableDebug = Logger.EnableDebug,
  371. LoggingEnableStub = Logger.EnableStub,
  372. LoggingEnableInfo = Logger.EnableInfo,
  373. LoggingEnableWarn = Logger.EnableWarn,
  374. LoggingEnableError = Logger.EnableError,
  375. LoggingEnableGuest = Logger.EnableGuest,
  376. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  377. LoggingFilteredClasses = Logger.FilteredClasses,
  378. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  379. SystemLanguage = System.Language,
  380. SystemRegion = System.Region,
  381. SystemTimeZone = System.TimeZone,
  382. SystemTimeOffset = System.SystemTimeOffset,
  383. DockedMode = System.EnableDockedMode,
  384. EnableDiscordIntegration = EnableDiscordIntegration,
  385. CheckUpdatesOnStart = CheckUpdatesOnStart,
  386. ShowConfirmExit = ShowConfirmExit,
  387. HideCursorOnIdle = HideCursorOnIdle,
  388. EnableVsync = Graphics.EnableVsync,
  389. EnableShaderCache = Graphics.EnableShaderCache,
  390. EnablePtc = System.EnablePtc,
  391. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  392. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  393. AudioBackend = System.AudioBackend,
  394. MemoryManagerMode = System.MemoryManagerMode,
  395. ExpandRam = System.ExpandRam,
  396. IgnoreMissingServices = System.IgnoreMissingServices,
  397. GuiColumns = new GuiColumns
  398. {
  399. FavColumn = Ui.GuiColumns.FavColumn,
  400. IconColumn = Ui.GuiColumns.IconColumn,
  401. AppColumn = Ui.GuiColumns.AppColumn,
  402. DevColumn = Ui.GuiColumns.DevColumn,
  403. VersionColumn = Ui.GuiColumns.VersionColumn,
  404. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  405. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  406. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  407. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  408. PathColumn = Ui.GuiColumns.PathColumn,
  409. },
  410. ColumnSort = new ColumnSort
  411. {
  412. SortColumnId = Ui.ColumnSort.SortColumnId,
  413. SortAscending = Ui.ColumnSort.SortAscending
  414. },
  415. GameDirs = Ui.GameDirs,
  416. EnableCustomTheme = Ui.EnableCustomTheme,
  417. CustomThemePath = Ui.CustomThemePath,
  418. StartFullscreen = Ui.StartFullscreen,
  419. EnableKeyboard = Hid.EnableKeyboard,
  420. EnableMouse = Hid.EnableMouse,
  421. Hotkeys = Hid.Hotkeys,
  422. KeyboardConfig = new List<object>(),
  423. ControllerConfig = new List<object>(),
  424. InputConfig = Hid.InputConfig,
  425. };
  426. return configurationFile;
  427. }
  428. public void LoadDefault()
  429. {
  430. Logger.EnableFileLog.Value = true;
  431. Graphics.ResScale.Value = 1;
  432. Graphics.ResScaleCustom.Value = 1.0f;
  433. Graphics.MaxAnisotropy.Value = -1.0f;
  434. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  435. Graphics.ShadersDumpPath.Value = "";
  436. Logger.EnableDebug.Value = false;
  437. Logger.EnableStub.Value = true;
  438. Logger.EnableInfo.Value = true;
  439. Logger.EnableWarn.Value = true;
  440. Logger.EnableError.Value = true;
  441. Logger.EnableGuest.Value = true;
  442. Logger.EnableFsAccessLog.Value = false;
  443. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  444. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  445. System.Language.Value = Language.AmericanEnglish;
  446. System.Region.Value = Region.USA;
  447. System.TimeZone.Value = "UTC";
  448. System.SystemTimeOffset.Value = 0;
  449. System.EnableDockedMode.Value = true;
  450. EnableDiscordIntegration.Value = true;
  451. CheckUpdatesOnStart.Value = true;
  452. ShowConfirmExit.Value = true;
  453. HideCursorOnIdle.Value = false;
  454. Graphics.EnableVsync.Value = true;
  455. Graphics.EnableShaderCache.Value = true;
  456. System.EnablePtc.Value = true;
  457. System.EnableFsIntegrityChecks.Value = true;
  458. System.FsGlobalAccessLogMode.Value = 0;
  459. System.AudioBackend.Value = AudioBackend.OpenAl;
  460. System.MemoryManagerMode.Value = MemoryManagerMode.HostMappedUnsafe;
  461. System.ExpandRam.Value = false;
  462. System.IgnoreMissingServices.Value = false;
  463. Ui.GuiColumns.FavColumn.Value = true;
  464. Ui.GuiColumns.IconColumn.Value = true;
  465. Ui.GuiColumns.AppColumn.Value = true;
  466. Ui.GuiColumns.DevColumn.Value = true;
  467. Ui.GuiColumns.VersionColumn.Value = true;
  468. Ui.GuiColumns.TimePlayedColumn.Value = true;
  469. Ui.GuiColumns.LastPlayedColumn.Value = true;
  470. Ui.GuiColumns.FileExtColumn.Value = true;
  471. Ui.GuiColumns.FileSizeColumn.Value = true;
  472. Ui.GuiColumns.PathColumn.Value = true;
  473. Ui.ColumnSort.SortColumnId.Value = 0;
  474. Ui.ColumnSort.SortAscending.Value = false;
  475. Ui.GameDirs.Value = new List<string>();
  476. Ui.EnableCustomTheme.Value = false;
  477. Ui.CustomThemePath.Value = "";
  478. Ui.StartFullscreen.Value = false;
  479. Hid.EnableKeyboard.Value = false;
  480. Hid.EnableMouse.Value = false;
  481. Hid.Hotkeys.Value = new KeyboardHotkeys
  482. {
  483. ToggleVsync = Key.Tab,
  484. Screenshot = Key.F8,
  485. ShowUi = Key.F4
  486. };
  487. Hid.InputConfig.Value = new List<InputConfig>
  488. {
  489. new StandardKeyboardInputConfig
  490. {
  491. Version = InputConfig.CurrentVersion,
  492. Backend = InputBackendType.WindowKeyboard,
  493. Id = "0",
  494. PlayerIndex = PlayerIndex.Player1,
  495. ControllerType = ControllerType.JoyconPair,
  496. LeftJoycon = new LeftJoyconCommonConfig<Key>
  497. {
  498. DpadUp = Key.Up,
  499. DpadDown = Key.Down,
  500. DpadLeft = Key.Left,
  501. DpadRight = Key.Right,
  502. ButtonMinus = Key.Minus,
  503. ButtonL = Key.E,
  504. ButtonZl = Key.Q,
  505. ButtonSl = Key.Unbound,
  506. ButtonSr = Key.Unbound
  507. },
  508. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  509. {
  510. StickUp = Key.W,
  511. StickDown = Key.S,
  512. StickLeft = Key.A,
  513. StickRight = Key.D,
  514. StickButton = Key.F,
  515. },
  516. RightJoycon = new RightJoyconCommonConfig<Key>
  517. {
  518. ButtonA = Key.Z,
  519. ButtonB = Key.X,
  520. ButtonX = Key.C,
  521. ButtonY = Key.V,
  522. ButtonPlus = Key.Plus,
  523. ButtonR = Key.U,
  524. ButtonZr = Key.O,
  525. ButtonSl = Key.Unbound,
  526. ButtonSr = Key.Unbound
  527. },
  528. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  529. {
  530. StickUp = Key.I,
  531. StickDown = Key.K,
  532. StickLeft = Key.J,
  533. StickRight = Key.L,
  534. StickButton = Key.H,
  535. }
  536. }
  537. };
  538. }
  539. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  540. {
  541. bool configurationFileUpdated = false;
  542. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  543. {
  544. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  545. LoadDefault();
  546. return;
  547. }
  548. if (configurationFileFormat.Version < 2)
  549. {
  550. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  551. configurationFileFormat.SystemRegion = Region.USA;
  552. configurationFileUpdated = true;
  553. }
  554. if (configurationFileFormat.Version < 3)
  555. {
  556. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  557. configurationFileFormat.SystemTimeZone = "UTC";
  558. configurationFileUpdated = true;
  559. }
  560. if (configurationFileFormat.Version < 4)
  561. {
  562. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  563. configurationFileFormat.MaxAnisotropy = -1;
  564. configurationFileUpdated = true;
  565. }
  566. if (configurationFileFormat.Version < 5)
  567. {
  568. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  569. configurationFileFormat.SystemTimeOffset = 0;
  570. configurationFileUpdated = true;
  571. }
  572. if (configurationFileFormat.Version < 8)
  573. {
  574. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  575. configurationFileFormat.EnablePtc = true;
  576. configurationFileUpdated = true;
  577. }
  578. if (configurationFileFormat.Version < 9)
  579. {
  580. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  581. configurationFileFormat.ColumnSort = new ColumnSort
  582. {
  583. SortColumnId = 0,
  584. SortAscending = false
  585. };
  586. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  587. {
  588. ToggleVsync = Key.Tab
  589. };
  590. configurationFileUpdated = true;
  591. }
  592. if (configurationFileFormat.Version < 10)
  593. {
  594. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  595. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  596. configurationFileUpdated = true;
  597. }
  598. if (configurationFileFormat.Version < 11)
  599. {
  600. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  601. configurationFileFormat.ResScale = 1;
  602. configurationFileFormat.ResScaleCustom = 1.0f;
  603. configurationFileUpdated = true;
  604. }
  605. if (configurationFileFormat.Version < 12)
  606. {
  607. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  608. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  609. configurationFileUpdated = true;
  610. }
  611. if (configurationFileFormat.Version < 14)
  612. {
  613. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  614. configurationFileFormat.CheckUpdatesOnStart = true;
  615. configurationFileUpdated = true;
  616. }
  617. if (configurationFileFormat.Version < 16)
  618. {
  619. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  620. configurationFileFormat.EnableShaderCache = true;
  621. configurationFileUpdated = true;
  622. }
  623. if (configurationFileFormat.Version < 17)
  624. {
  625. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  626. configurationFileFormat.StartFullscreen = false;
  627. configurationFileUpdated = true;
  628. }
  629. if (configurationFileFormat.Version < 18)
  630. {
  631. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  632. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  633. configurationFileUpdated = true;
  634. }
  635. if (configurationFileFormat.Version < 20)
  636. {
  637. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  638. configurationFileFormat.ShowConfirmExit = true;
  639. configurationFileUpdated = true;
  640. }
  641. if (configurationFileFormat.Version < 22)
  642. {
  643. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  644. configurationFileFormat.HideCursorOnIdle = false;
  645. configurationFileUpdated = true;
  646. }
  647. if (configurationFileFormat.Version < 24)
  648. {
  649. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24.");
  650. configurationFileFormat.InputConfig = new List<InputConfig>
  651. {
  652. new StandardKeyboardInputConfig
  653. {
  654. Version = InputConfig.CurrentVersion,
  655. Backend = InputBackendType.WindowKeyboard,
  656. Id = "0",
  657. PlayerIndex = PlayerIndex.Player1,
  658. ControllerType = ControllerType.JoyconPair,
  659. LeftJoycon = new LeftJoyconCommonConfig<Key>
  660. {
  661. DpadUp = Key.Up,
  662. DpadDown = Key.Down,
  663. DpadLeft = Key.Left,
  664. DpadRight = Key.Right,
  665. ButtonMinus = Key.Minus,
  666. ButtonL = Key.E,
  667. ButtonZl = Key.Q,
  668. ButtonSl = Key.Unbound,
  669. ButtonSr = Key.Unbound
  670. },
  671. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  672. {
  673. StickUp = Key.W,
  674. StickDown = Key.S,
  675. StickLeft = Key.A,
  676. StickRight = Key.D,
  677. StickButton = Key.F,
  678. },
  679. RightJoycon = new RightJoyconCommonConfig<Key>
  680. {
  681. ButtonA = Key.Z,
  682. ButtonB = Key.X,
  683. ButtonX = Key.C,
  684. ButtonY = Key.V,
  685. ButtonPlus = Key.Plus,
  686. ButtonR = Key.U,
  687. ButtonZr = Key.O,
  688. ButtonSl = Key.Unbound,
  689. ButtonSr = Key.Unbound
  690. },
  691. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  692. {
  693. StickUp = Key.I,
  694. StickDown = Key.K,
  695. StickLeft = Key.J,
  696. StickRight = Key.L,
  697. StickButton = Key.H,
  698. }
  699. }
  700. };
  701. configurationFileUpdated = true;
  702. }
  703. if (configurationFileFormat.Version < 25)
  704. {
  705. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 25.");
  706. configurationFileUpdated = true;
  707. }
  708. if (configurationFileFormat.Version < 26)
  709. {
  710. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 26.");
  711. configurationFileFormat.MemoryManagerMode = MemoryManagerMode.HostMappedUnsafe;
  712. configurationFileUpdated = true;
  713. }
  714. if (configurationFileFormat.Version < 27)
  715. {
  716. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 27.");
  717. configurationFileFormat.EnableMouse = false;
  718. configurationFileUpdated = true;
  719. }
  720. if (configurationFileFormat.Version < 28)
  721. {
  722. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 28.");
  723. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  724. {
  725. ToggleVsync = Key.Tab,
  726. Screenshot = Key.F8
  727. };
  728. configurationFileUpdated = true;
  729. }
  730. if (configurationFileFormat.Version < 29)
  731. {
  732. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 29.");
  733. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  734. {
  735. ToggleVsync = Key.Tab,
  736. Screenshot = Key.F8,
  737. ShowUi = Key.F4
  738. };
  739. configurationFileUpdated = true;
  740. }
  741. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  742. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  743. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  744. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  745. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  746. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  747. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  748. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  749. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  750. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  751. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  752. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  753. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  754. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  755. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  756. System.Language.Value = configurationFileFormat.SystemLanguage;
  757. System.Region.Value = configurationFileFormat.SystemRegion;
  758. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  759. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  760. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  761. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  762. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  763. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  764. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  765. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  766. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  767. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  768. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  769. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  770. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  771. System.MemoryManagerMode.Value = configurationFileFormat.MemoryManagerMode;
  772. System.ExpandRam.Value = configurationFileFormat.ExpandRam;
  773. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  774. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  775. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  776. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  777. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  778. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  779. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  780. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  781. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  782. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  783. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  784. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  785. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  786. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  787. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  788. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  789. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  790. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  791. Hid.EnableMouse.Value = configurationFileFormat.EnableMouse;
  792. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  793. Hid.InputConfig.Value = configurationFileFormat.InputConfig;
  794. if (Hid.InputConfig.Value == null)
  795. {
  796. Hid.InputConfig.Value = new List<InputConfig>();
  797. }
  798. if (configurationFileUpdated)
  799. {
  800. ToFileFormat().SaveConfig(configurationFilePath);
  801. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  802. }
  803. }
  804. private static void LogValueChange<T>(object sender, ReactiveEventArgs<T> eventArgs, string valueName)
  805. {
  806. Common.Logging.Logger.Info?.Print(LogClass.Configuration, $"{valueName} set to: {eventArgs.NewValue}");
  807. }
  808. public static void Initialize()
  809. {
  810. if (Instance != null)
  811. {
  812. throw new InvalidOperationException("Configuration is already initialized");
  813. }
  814. Instance = new ConfigurationState();
  815. }
  816. }
  817. }