ConfigurationState.cs 45 KB

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