ConfigurationState.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Configuration.Hid;
  3. using Ryujinx.Common.Logging;
  4. using Ryujinx.Configuration.Hid;
  5. using Ryujinx.Configuration.System;
  6. using Ryujinx.Configuration.Ui;
  7. using System;
  8. using System.Collections.Generic;
  9. namespace Ryujinx.Configuration
  10. {
  11. public class ConfigurationState
  12. {
  13. /// <summary>
  14. /// UI configuration section
  15. /// </summary>
  16. public class UiSection
  17. {
  18. public class Columns
  19. {
  20. public ReactiveObject<bool> FavColumn { get; private set; }
  21. public ReactiveObject<bool> IconColumn { get; private set; }
  22. public ReactiveObject<bool> AppColumn { get; private set; }
  23. public ReactiveObject<bool> DevColumn { get; private set; }
  24. public ReactiveObject<bool> VersionColumn { get; private set; }
  25. public ReactiveObject<bool> TimePlayedColumn { get; private set; }
  26. public ReactiveObject<bool> LastPlayedColumn { get; private set; }
  27. public ReactiveObject<bool> FileExtColumn { get; private set; }
  28. public ReactiveObject<bool> FileSizeColumn { get; private set; }
  29. public ReactiveObject<bool> PathColumn { get; private set; }
  30. public Columns()
  31. {
  32. FavColumn = new ReactiveObject<bool>();
  33. IconColumn = new ReactiveObject<bool>();
  34. AppColumn = new ReactiveObject<bool>();
  35. DevColumn = new ReactiveObject<bool>();
  36. VersionColumn = new ReactiveObject<bool>();
  37. TimePlayedColumn = new ReactiveObject<bool>();
  38. LastPlayedColumn = new ReactiveObject<bool>();
  39. FileExtColumn = new ReactiveObject<bool>();
  40. FileSizeColumn = new ReactiveObject<bool>();
  41. PathColumn = new ReactiveObject<bool>();
  42. }
  43. }
  44. public class ColumnSortSettings
  45. {
  46. public ReactiveObject<int> SortColumnId { get; private set; }
  47. public ReactiveObject<bool> SortAscending { get; private set; }
  48. public ColumnSortSettings()
  49. {
  50. SortColumnId = new ReactiveObject<int>();
  51. SortAscending = new ReactiveObject<bool>();
  52. }
  53. }
  54. /// <summary>
  55. /// Used to toggle columns in the GUI
  56. /// </summary>
  57. public Columns GuiColumns { get; private set; }
  58. /// <summary>
  59. /// Used to configure column sort settings in the GUI
  60. /// </summary>
  61. public ColumnSortSettings ColumnSort { get; private set; }
  62. /// <summary>
  63. /// A list of directories containing games to be used to load games into the games list
  64. /// </summary>
  65. public ReactiveObject<List<string>> GameDirs { get; private set; }
  66. /// <summary>
  67. /// Enable or disable custom themes in the GUI
  68. /// </summary>
  69. public ReactiveObject<bool> EnableCustomTheme { get; private set; }
  70. /// <summary>
  71. /// Path to custom GUI theme
  72. /// </summary>
  73. public ReactiveObject<string> CustomThemePath { get; private set; }
  74. public UiSection()
  75. {
  76. GuiColumns = new Columns();
  77. ColumnSort = new ColumnSortSettings();
  78. GameDirs = new ReactiveObject<List<string>>();
  79. EnableCustomTheme = new ReactiveObject<bool>();
  80. CustomThemePath = new ReactiveObject<string>();
  81. }
  82. }
  83. /// <summary>
  84. /// Logger configuration section
  85. /// </summary>
  86. public class LoggerSection
  87. {
  88. /// <summary>
  89. /// Enables printing debug log messages
  90. /// </summary>
  91. public ReactiveObject<bool> EnableDebug { get; private set; }
  92. /// <summary>
  93. /// Enables printing stub log messages
  94. /// </summary>
  95. public ReactiveObject<bool> EnableStub { get; private set; }
  96. /// <summary>
  97. /// Enables printing info log messages
  98. /// </summary>
  99. public ReactiveObject<bool> EnableInfo { get; private set; }
  100. /// <summary>
  101. /// Enables printing warning log messages
  102. /// </summary>
  103. public ReactiveObject<bool> EnableWarn { get; private set; }
  104. /// <summary>
  105. /// Enables printing error log messages
  106. /// </summary>
  107. public ReactiveObject<bool> EnableError { get; private set; }
  108. /// <summary>
  109. /// Enables printing guest log messages
  110. /// </summary>
  111. public ReactiveObject<bool> EnableGuest { get; private set; }
  112. /// <summary>
  113. /// Enables printing FS access log messages
  114. /// </summary>
  115. public ReactiveObject<bool> EnableFsAccessLog { get; private set; }
  116. /// <summary>
  117. /// Controls which log messages are written to the log targets
  118. /// </summary>
  119. public ReactiveObject<LogClass[]> FilteredClasses { get; private set; }
  120. /// <summary>
  121. /// Enables or disables logging to a file on disk
  122. /// </summary>
  123. public ReactiveObject<bool> EnableFileLog { get; private set; }
  124. public LoggerSection()
  125. {
  126. EnableDebug = new ReactiveObject<bool>();
  127. EnableStub = new ReactiveObject<bool>();
  128. EnableInfo = new ReactiveObject<bool>();
  129. EnableWarn = new ReactiveObject<bool>();
  130. EnableError = new ReactiveObject<bool>();
  131. EnableGuest = new ReactiveObject<bool>();
  132. EnableFsAccessLog = new ReactiveObject<bool>();
  133. FilteredClasses = new ReactiveObject<LogClass[]>();
  134. EnableFileLog = new ReactiveObject<bool>();
  135. }
  136. }
  137. /// <summary>
  138. /// System configuration section
  139. /// </summary>
  140. public class SystemSection
  141. {
  142. /// <summary>
  143. /// Change System Language
  144. /// </summary>
  145. public ReactiveObject<Language> Language { get; private set; }
  146. /// <summary>
  147. /// Change System Region
  148. /// </summary>
  149. public ReactiveObject<Region> Region { get; private set; }
  150. /// <summary>
  151. /// Change System TimeZone
  152. /// </summary>
  153. public ReactiveObject<string> TimeZone { get; private set; }
  154. /// <summary>
  155. /// System Time Offset in Seconds
  156. /// </summary>
  157. public ReactiveObject<long> SystemTimeOffset { get; private set; }
  158. /// <summary>
  159. /// Enables or disables Docked Mode
  160. /// </summary>
  161. public ReactiveObject<bool> EnableDockedMode { get; private set; }
  162. /// <summary>
  163. /// Enables or disables multi-core scheduling of threads
  164. /// </summary>
  165. public ReactiveObject<bool> EnableMulticoreScheduling { get; private set; }
  166. /// <summary>
  167. /// Enables or disables profiled translation cache persistency
  168. /// </summary>
  169. public ReactiveObject<bool> EnablePtc { get; private set; }
  170. /// <summary>
  171. /// Enables integrity checks on Game content files
  172. /// </summary>
  173. public ReactiveObject<bool> EnableFsIntegrityChecks { get; private set; }
  174. /// <summary>
  175. /// Enables FS access log output to the console. Possible modes are 0-3
  176. /// </summary>
  177. public ReactiveObject<int> FsGlobalAccessLogMode { get; private set; }
  178. /// <summary>
  179. /// Enable or disable ignoring missing services
  180. /// </summary>
  181. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  182. public SystemSection()
  183. {
  184. Language = new ReactiveObject<Language>();
  185. Region = new ReactiveObject<Region>();
  186. TimeZone = new ReactiveObject<string>();
  187. SystemTimeOffset = new ReactiveObject<long>();
  188. EnableDockedMode = new ReactiveObject<bool>();
  189. EnableMulticoreScheduling = new ReactiveObject<bool>();
  190. EnablePtc = new ReactiveObject<bool>();
  191. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  192. FsGlobalAccessLogMode = new ReactiveObject<int>();
  193. IgnoreMissingServices = new ReactiveObject<bool>();
  194. }
  195. }
  196. /// <summary>
  197. /// Hid configuration section
  198. /// </summary>
  199. public class HidSection
  200. {
  201. /// <summary>
  202. /// Enable or disable keyboard support (Independent from controllers binding)
  203. /// </summary>
  204. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  205. /// <summary>
  206. /// Hotkey Keyboard Bindings
  207. /// </summary>
  208. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  209. /// <summary>
  210. /// Input device configuration.
  211. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  212. /// TODO: Implement a ReactiveList class.
  213. /// </summary>
  214. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  215. public HidSection()
  216. {
  217. EnableKeyboard = new ReactiveObject<bool>();
  218. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  219. InputConfig = new ReactiveObject<List<InputConfig>>();
  220. }
  221. }
  222. /// <summary>
  223. /// Graphics configuration section
  224. /// </summary>
  225. public class GraphicsSection
  226. {
  227. /// <summary>
  228. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  229. /// </summary>
  230. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  231. /// <summary>
  232. /// Dumps shaders in this local directory
  233. /// </summary>
  234. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  235. /// <summary>
  236. /// Enables or disables Vertical Sync
  237. /// </summary>
  238. public ReactiveObject<bool> EnableVsync { get; private set; }
  239. public GraphicsSection()
  240. {
  241. MaxAnisotropy = new ReactiveObject<float>();
  242. ShadersDumpPath = new ReactiveObject<string>();
  243. EnableVsync = new ReactiveObject<bool>();
  244. }
  245. }
  246. /// <summary>
  247. /// The default configuration instance
  248. /// </summary>
  249. public static ConfigurationState Instance { get; private set; }
  250. /// <summary>
  251. /// The Ui section
  252. /// </summary>
  253. public UiSection Ui { get; private set; }
  254. /// <summary>
  255. /// The Logger section
  256. /// </summary>
  257. public LoggerSection Logger { get; private set; }
  258. /// <summary>
  259. /// The System section
  260. /// </summary>
  261. public SystemSection System { get; private set; }
  262. /// <summary>
  263. /// The Graphics section
  264. /// </summary>
  265. public GraphicsSection Graphics { get; private set; }
  266. /// <summary>
  267. /// The Hid section
  268. /// </summary>
  269. public HidSection Hid { get; private set; }
  270. /// <summary>
  271. /// Enables or disables Discord Rich Presence
  272. /// </summary>
  273. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  274. private ConfigurationState()
  275. {
  276. Ui = new UiSection();
  277. Logger = new LoggerSection();
  278. System = new SystemSection();
  279. Graphics = new GraphicsSection();
  280. Hid = new HidSection();
  281. EnableDiscordIntegration = new ReactiveObject<bool>();
  282. }
  283. public ConfigurationFileFormat ToFileFormat()
  284. {
  285. List<ControllerConfig> controllerConfigList = new List<ControllerConfig>();
  286. List<KeyboardConfig> keyboardConfigList = new List<KeyboardConfig>();
  287. foreach (InputConfig inputConfig in Hid.InputConfig.Value)
  288. {
  289. if (inputConfig is ControllerConfig controllerConfig)
  290. {
  291. controllerConfigList.Add(controllerConfig);
  292. }
  293. else if (inputConfig is KeyboardConfig keyboardConfig)
  294. {
  295. keyboardConfigList.Add(keyboardConfig);
  296. }
  297. }
  298. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  299. {
  300. Version = ConfigurationFileFormat.CurrentVersion,
  301. MaxAnisotropy = Graphics.MaxAnisotropy,
  302. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  303. LoggingEnableDebug = Logger.EnableDebug,
  304. LoggingEnableStub = Logger.EnableStub,
  305. LoggingEnableInfo = Logger.EnableInfo,
  306. LoggingEnableWarn = Logger.EnableWarn,
  307. LoggingEnableError = Logger.EnableError,
  308. LoggingEnableGuest = Logger.EnableGuest,
  309. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  310. LoggingFilteredClasses = Logger.FilteredClasses,
  311. EnableFileLog = Logger.EnableFileLog,
  312. SystemLanguage = System.Language,
  313. SystemRegion = System.Region,
  314. SystemTimeZone = System.TimeZone,
  315. SystemTimeOffset = System.SystemTimeOffset,
  316. DockedMode = System.EnableDockedMode,
  317. EnableDiscordIntegration = EnableDiscordIntegration,
  318. EnableVsync = Graphics.EnableVsync,
  319. EnableMulticoreScheduling = System.EnableMulticoreScheduling,
  320. EnablePtc = System.EnablePtc,
  321. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  322. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  323. IgnoreMissingServices = System.IgnoreMissingServices,
  324. GuiColumns = new GuiColumns
  325. {
  326. FavColumn = Ui.GuiColumns.FavColumn,
  327. IconColumn = Ui.GuiColumns.IconColumn,
  328. AppColumn = Ui.GuiColumns.AppColumn,
  329. DevColumn = Ui.GuiColumns.DevColumn,
  330. VersionColumn = Ui.GuiColumns.VersionColumn,
  331. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  332. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  333. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  334. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  335. PathColumn = Ui.GuiColumns.PathColumn,
  336. },
  337. ColumnSort = new ColumnSort
  338. {
  339. SortColumnId = Ui.ColumnSort.SortColumnId,
  340. SortAscending = Ui.ColumnSort.SortAscending
  341. },
  342. GameDirs = Ui.GameDirs,
  343. EnableCustomTheme = Ui.EnableCustomTheme,
  344. CustomThemePath = Ui.CustomThemePath,
  345. EnableKeyboard = Hid.EnableKeyboard,
  346. Hotkeys = Hid.Hotkeys,
  347. KeyboardConfig = keyboardConfigList,
  348. ControllerConfig = controllerConfigList
  349. };
  350. return configurationFile;
  351. }
  352. public void LoadDefault()
  353. {
  354. Graphics.MaxAnisotropy.Value = -1;
  355. Graphics.ShadersDumpPath.Value = "";
  356. Logger.EnableDebug.Value = false;
  357. Logger.EnableStub.Value = true;
  358. Logger.EnableInfo.Value = true;
  359. Logger.EnableWarn.Value = true;
  360. Logger.EnableError.Value = true;
  361. Logger.EnableGuest.Value = true;
  362. Logger.EnableFsAccessLog.Value = false;
  363. Logger.FilteredClasses.Value = new LogClass[] { };
  364. Logger.EnableFileLog.Value = true;
  365. System.Language.Value = Language.AmericanEnglish;
  366. System.Region.Value = Region.USA;
  367. System.TimeZone.Value = "UTC";
  368. System.SystemTimeOffset.Value = 0;
  369. System.EnableDockedMode.Value = false;
  370. EnableDiscordIntegration.Value = true;
  371. Graphics.EnableVsync.Value = true;
  372. System.EnableMulticoreScheduling.Value = true;
  373. System.EnablePtc.Value = false;
  374. System.EnableFsIntegrityChecks.Value = true;
  375. System.FsGlobalAccessLogMode.Value = 0;
  376. System.IgnoreMissingServices.Value = false;
  377. Ui.GuiColumns.FavColumn.Value = true;
  378. Ui.GuiColumns.IconColumn.Value = true;
  379. Ui.GuiColumns.AppColumn.Value = true;
  380. Ui.GuiColumns.DevColumn.Value = true;
  381. Ui.GuiColumns.VersionColumn.Value = true;
  382. Ui.GuiColumns.TimePlayedColumn.Value = true;
  383. Ui.GuiColumns.LastPlayedColumn.Value = true;
  384. Ui.GuiColumns.FileExtColumn.Value = true;
  385. Ui.GuiColumns.FileSizeColumn.Value = true;
  386. Ui.GuiColumns.PathColumn.Value = true;
  387. Ui.ColumnSort.SortColumnId.Value = 0;
  388. Ui.ColumnSort.SortAscending.Value = false;
  389. Ui.GameDirs.Value = new List<string>();
  390. Ui.EnableCustomTheme.Value = false;
  391. Ui.CustomThemePath.Value = "";
  392. Hid.EnableKeyboard.Value = false;
  393. Hid.Hotkeys.Value = new KeyboardHotkeys
  394. {
  395. ToggleVsync = Key.Tab
  396. };
  397. Hid.InputConfig.Value = new List<InputConfig>
  398. {
  399. new KeyboardConfig
  400. {
  401. Index = 0,
  402. ControllerType = ControllerType.JoyconPair,
  403. PlayerIndex = PlayerIndex.Player1,
  404. LeftJoycon = new NpadKeyboardLeft
  405. {
  406. StickUp = Key.W,
  407. StickDown = Key.S,
  408. StickLeft = Key.A,
  409. StickRight = Key.D,
  410. StickButton = Key.F,
  411. DPadUp = Key.Up,
  412. DPadDown = Key.Down,
  413. DPadLeft = Key.Left,
  414. DPadRight = Key.Right,
  415. ButtonMinus = Key.Minus,
  416. ButtonL = Key.E,
  417. ButtonZl = Key.Q,
  418. ButtonSl = Key.Home,
  419. ButtonSr = Key.End
  420. },
  421. RightJoycon = new NpadKeyboardRight
  422. {
  423. StickUp = Key.I,
  424. StickDown = Key.K,
  425. StickLeft = Key.J,
  426. StickRight = Key.L,
  427. StickButton = Key.H,
  428. ButtonA = Key.Z,
  429. ButtonB = Key.X,
  430. ButtonX = Key.C,
  431. ButtonY = Key.V,
  432. ButtonPlus = Key.Plus,
  433. ButtonR = Key.U,
  434. ButtonZr = Key.O,
  435. ButtonSl = Key.PageUp,
  436. ButtonSr = Key.PageDown
  437. }
  438. }
  439. };
  440. }
  441. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  442. {
  443. bool configurationFileUpdated = false;
  444. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  445. {
  446. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  447. LoadDefault();
  448. return;
  449. }
  450. if (configurationFileFormat.Version < 2)
  451. {
  452. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  453. configurationFileFormat.SystemRegion = Region.USA;
  454. configurationFileUpdated = true;
  455. }
  456. if (configurationFileFormat.Version < 3)
  457. {
  458. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  459. configurationFileFormat.SystemTimeZone = "UTC";
  460. configurationFileUpdated = true;
  461. }
  462. if (configurationFileFormat.Version < 4)
  463. {
  464. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  465. configurationFileFormat.MaxAnisotropy = -1;
  466. configurationFileUpdated = true;
  467. }
  468. if (configurationFileFormat.Version < 5)
  469. {
  470. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  471. configurationFileFormat.SystemTimeOffset = 0;
  472. configurationFileUpdated = true;
  473. }
  474. if (configurationFileFormat.Version < 6)
  475. {
  476. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6.");
  477. configurationFileFormat.ControllerConfig = new List<ControllerConfig>();
  478. configurationFileFormat.KeyboardConfig = new List<KeyboardConfig>{
  479. new KeyboardConfig
  480. {
  481. Index = 0,
  482. ControllerType = ControllerType.JoyconPair,
  483. PlayerIndex = PlayerIndex.Player1,
  484. LeftJoycon = new NpadKeyboardLeft
  485. {
  486. StickUp = Key.W,
  487. StickDown = Key.S,
  488. StickLeft = Key.A,
  489. StickRight = Key.D,
  490. StickButton = Key.F,
  491. DPadUp = Key.Up,
  492. DPadDown = Key.Down,
  493. DPadLeft = Key.Left,
  494. DPadRight = Key.Right,
  495. ButtonMinus = Key.Minus,
  496. ButtonL = Key.E,
  497. ButtonZl = Key.Q,
  498. ButtonSl = Key.Unbound,
  499. ButtonSr = Key.Unbound
  500. },
  501. RightJoycon = new NpadKeyboardRight
  502. {
  503. StickUp = Key.I,
  504. StickDown = Key.K,
  505. StickLeft = Key.J,
  506. StickRight = Key.L,
  507. StickButton = Key.H,
  508. ButtonA = Key.Z,
  509. ButtonB = Key.X,
  510. ButtonX = Key.C,
  511. ButtonY = Key.V,
  512. ButtonPlus = Key.Plus,
  513. ButtonR = Key.U,
  514. ButtonZr = Key.O,
  515. ButtonSl = Key.Unbound,
  516. ButtonSr = Key.Unbound
  517. }
  518. }
  519. };
  520. configurationFileUpdated = true;
  521. }
  522. // Only needed for version 6 configurations.
  523. if (configurationFileFormat.Version == 6)
  524. {
  525. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
  526. for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
  527. {
  528. if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
  529. {
  530. configurationFileFormat.KeyboardConfig[i].Index++;
  531. }
  532. }
  533. }
  534. if (configurationFileFormat.Version < 8)
  535. {
  536. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  537. configurationFileFormat.EnablePtc = false;
  538. configurationFileUpdated = true;
  539. }
  540. if (configurationFileFormat.Version < 9)
  541. {
  542. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  543. configurationFileFormat.ColumnSort = new ColumnSort
  544. {
  545. SortColumnId = 0,
  546. SortAscending = false
  547. };
  548. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  549. {
  550. ToggleVsync = Key.Tab
  551. };
  552. configurationFileUpdated = true;
  553. }
  554. List<InputConfig> inputConfig = new List<InputConfig>();
  555. foreach (ControllerConfig controllerConfig in configurationFileFormat.ControllerConfig)
  556. {
  557. inputConfig.Add(controllerConfig);
  558. }
  559. foreach (KeyboardConfig keyboardConfig in configurationFileFormat.KeyboardConfig)
  560. {
  561. inputConfig.Add(keyboardConfig);
  562. }
  563. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  564. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  565. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  566. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  567. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  568. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  569. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  570. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  571. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  572. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  573. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  574. System.Language.Value = configurationFileFormat.SystemLanguage;
  575. System.Region.Value = configurationFileFormat.SystemRegion;
  576. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  577. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  578. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  579. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  580. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  581. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  582. System.EnableMulticoreScheduling.Value = configurationFileFormat.EnableMulticoreScheduling;
  583. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  584. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  585. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  586. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  587. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  588. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  589. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  590. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  591. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  592. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  593. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  594. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  595. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  596. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  597. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  598. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  599. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  600. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  601. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  602. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  603. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  604. Hid.InputConfig.Value = inputConfig;
  605. if (configurationFileUpdated)
  606. {
  607. ToFileFormat().SaveConfig(configurationFilePath);
  608. Common.Logging.Logger.PrintWarning(LogClass.Application, "Configuration file has been updated!");
  609. }
  610. }
  611. public static void Initialize()
  612. {
  613. if (Instance != null)
  614. {
  615. throw new InvalidOperationException("Configuration is already initialized");
  616. }
  617. Instance = new ConfigurationState();
  618. }
  619. }
  620. }