ConfigurationState.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. /// The selected audio backend
  180. /// </summary>
  181. public ReactiveObject<AudioBackend> AudioBackend { get; private set; }
  182. /// <summary>
  183. /// Enable or disable ignoring missing services
  184. /// </summary>
  185. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  186. public SystemSection()
  187. {
  188. Language = new ReactiveObject<Language>();
  189. Region = new ReactiveObject<Region>();
  190. TimeZone = new ReactiveObject<string>();
  191. SystemTimeOffset = new ReactiveObject<long>();
  192. EnableDockedMode = new ReactiveObject<bool>();
  193. EnableMulticoreScheduling = new ReactiveObject<bool>();
  194. EnablePtc = new ReactiveObject<bool>();
  195. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  196. FsGlobalAccessLogMode = new ReactiveObject<int>();
  197. AudioBackend = new ReactiveObject<AudioBackend>();
  198. IgnoreMissingServices = new ReactiveObject<bool>();
  199. }
  200. }
  201. /// <summary>
  202. /// Hid configuration section
  203. /// </summary>
  204. public class HidSection
  205. {
  206. /// <summary>
  207. /// Enable or disable keyboard support (Independent from controllers binding)
  208. /// </summary>
  209. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  210. /// <summary>
  211. /// Hotkey Keyboard Bindings
  212. /// </summary>
  213. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  214. /// <summary>
  215. /// Input device configuration.
  216. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  217. /// TODO: Implement a ReactiveList class.
  218. /// </summary>
  219. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  220. public HidSection()
  221. {
  222. EnableKeyboard = new ReactiveObject<bool>();
  223. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  224. InputConfig = new ReactiveObject<List<InputConfig>>();
  225. }
  226. }
  227. /// <summary>
  228. /// Graphics configuration section
  229. /// </summary>
  230. public class GraphicsSection
  231. {
  232. /// <summary>
  233. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  234. /// </summary>
  235. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  236. /// <summary>
  237. /// Dumps shaders in this local directory
  238. /// </summary>
  239. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  240. /// <summary>
  241. /// Enables or disables Vertical Sync
  242. /// </summary>
  243. public ReactiveObject<bool> EnableVsync { get; private set; }
  244. public GraphicsSection()
  245. {
  246. MaxAnisotropy = new ReactiveObject<float>();
  247. ShadersDumpPath = new ReactiveObject<string>();
  248. EnableVsync = new ReactiveObject<bool>();
  249. }
  250. }
  251. /// <summary>
  252. /// The default configuration instance
  253. /// </summary>
  254. public static ConfigurationState Instance { get; private set; }
  255. /// <summary>
  256. /// The Ui section
  257. /// </summary>
  258. public UiSection Ui { get; private set; }
  259. /// <summary>
  260. /// The Logger section
  261. /// </summary>
  262. public LoggerSection Logger { get; private set; }
  263. /// <summary>
  264. /// The System section
  265. /// </summary>
  266. public SystemSection System { get; private set; }
  267. /// <summary>
  268. /// The Graphics section
  269. /// </summary>
  270. public GraphicsSection Graphics { get; private set; }
  271. /// <summary>
  272. /// The Hid section
  273. /// </summary>
  274. public HidSection Hid { get; private set; }
  275. /// <summary>
  276. /// Enables or disables Discord Rich Presence
  277. /// </summary>
  278. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  279. private ConfigurationState()
  280. {
  281. Ui = new UiSection();
  282. Logger = new LoggerSection();
  283. System = new SystemSection();
  284. Graphics = new GraphicsSection();
  285. Hid = new HidSection();
  286. EnableDiscordIntegration = new ReactiveObject<bool>();
  287. }
  288. public ConfigurationFileFormat ToFileFormat()
  289. {
  290. List<ControllerConfig> controllerConfigList = new List<ControllerConfig>();
  291. List<KeyboardConfig> keyboardConfigList = new List<KeyboardConfig>();
  292. foreach (InputConfig inputConfig in Hid.InputConfig.Value)
  293. {
  294. if (inputConfig is ControllerConfig controllerConfig)
  295. {
  296. controllerConfigList.Add(controllerConfig);
  297. }
  298. else if (inputConfig is KeyboardConfig keyboardConfig)
  299. {
  300. keyboardConfigList.Add(keyboardConfig);
  301. }
  302. }
  303. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  304. {
  305. Version = ConfigurationFileFormat.CurrentVersion,
  306. MaxAnisotropy = Graphics.MaxAnisotropy,
  307. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  308. LoggingEnableDebug = Logger.EnableDebug,
  309. LoggingEnableStub = Logger.EnableStub,
  310. LoggingEnableInfo = Logger.EnableInfo,
  311. LoggingEnableWarn = Logger.EnableWarn,
  312. LoggingEnableError = Logger.EnableError,
  313. LoggingEnableGuest = Logger.EnableGuest,
  314. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  315. LoggingFilteredClasses = Logger.FilteredClasses,
  316. EnableFileLog = Logger.EnableFileLog,
  317. SystemLanguage = System.Language,
  318. SystemRegion = System.Region,
  319. SystemTimeZone = System.TimeZone,
  320. SystemTimeOffset = System.SystemTimeOffset,
  321. DockedMode = System.EnableDockedMode,
  322. EnableDiscordIntegration = EnableDiscordIntegration,
  323. EnableVsync = Graphics.EnableVsync,
  324. EnableMulticoreScheduling = System.EnableMulticoreScheduling,
  325. EnablePtc = System.EnablePtc,
  326. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  327. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  328. AudioBackend = System.AudioBackend,
  329. IgnoreMissingServices = System.IgnoreMissingServices,
  330. GuiColumns = new GuiColumns
  331. {
  332. FavColumn = Ui.GuiColumns.FavColumn,
  333. IconColumn = Ui.GuiColumns.IconColumn,
  334. AppColumn = Ui.GuiColumns.AppColumn,
  335. DevColumn = Ui.GuiColumns.DevColumn,
  336. VersionColumn = Ui.GuiColumns.VersionColumn,
  337. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  338. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  339. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  340. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  341. PathColumn = Ui.GuiColumns.PathColumn,
  342. },
  343. ColumnSort = new ColumnSort
  344. {
  345. SortColumnId = Ui.ColumnSort.SortColumnId,
  346. SortAscending = Ui.ColumnSort.SortAscending
  347. },
  348. GameDirs = Ui.GameDirs,
  349. EnableCustomTheme = Ui.EnableCustomTheme,
  350. CustomThemePath = Ui.CustomThemePath,
  351. EnableKeyboard = Hid.EnableKeyboard,
  352. Hotkeys = Hid.Hotkeys,
  353. KeyboardConfig = keyboardConfigList,
  354. ControllerConfig = controllerConfigList
  355. };
  356. return configurationFile;
  357. }
  358. public void LoadDefault()
  359. {
  360. Graphics.MaxAnisotropy.Value = -1;
  361. Graphics.ShadersDumpPath.Value = "";
  362. Logger.EnableDebug.Value = false;
  363. Logger.EnableStub.Value = true;
  364. Logger.EnableInfo.Value = true;
  365. Logger.EnableWarn.Value = true;
  366. Logger.EnableError.Value = true;
  367. Logger.EnableGuest.Value = true;
  368. Logger.EnableFsAccessLog.Value = false;
  369. Logger.FilteredClasses.Value = new LogClass[] { };
  370. Logger.EnableFileLog.Value = true;
  371. System.Language.Value = Language.AmericanEnglish;
  372. System.Region.Value = Region.USA;
  373. System.TimeZone.Value = "UTC";
  374. System.SystemTimeOffset.Value = 0;
  375. System.EnableDockedMode.Value = false;
  376. EnableDiscordIntegration.Value = true;
  377. Graphics.EnableVsync.Value = true;
  378. System.EnableMulticoreScheduling.Value = true;
  379. System.EnablePtc.Value = false;
  380. System.EnableFsIntegrityChecks.Value = true;
  381. System.FsGlobalAccessLogMode.Value = 0;
  382. System.AudioBackend.Value = AudioBackend.OpenAl;
  383. System.IgnoreMissingServices.Value = false;
  384. Ui.GuiColumns.FavColumn.Value = true;
  385. Ui.GuiColumns.IconColumn.Value = true;
  386. Ui.GuiColumns.AppColumn.Value = true;
  387. Ui.GuiColumns.DevColumn.Value = true;
  388. Ui.GuiColumns.VersionColumn.Value = true;
  389. Ui.GuiColumns.TimePlayedColumn.Value = true;
  390. Ui.GuiColumns.LastPlayedColumn.Value = true;
  391. Ui.GuiColumns.FileExtColumn.Value = true;
  392. Ui.GuiColumns.FileSizeColumn.Value = true;
  393. Ui.GuiColumns.PathColumn.Value = true;
  394. Ui.ColumnSort.SortColumnId.Value = 0;
  395. Ui.ColumnSort.SortAscending.Value = false;
  396. Ui.GameDirs.Value = new List<string>();
  397. Ui.EnableCustomTheme.Value = false;
  398. Ui.CustomThemePath.Value = "";
  399. Hid.EnableKeyboard.Value = false;
  400. Hid.Hotkeys.Value = new KeyboardHotkeys
  401. {
  402. ToggleVsync = Key.Tab
  403. };
  404. Hid.InputConfig.Value = new List<InputConfig>
  405. {
  406. new KeyboardConfig
  407. {
  408. Index = 0,
  409. ControllerType = ControllerType.JoyconPair,
  410. PlayerIndex = PlayerIndex.Player1,
  411. LeftJoycon = new NpadKeyboardLeft
  412. {
  413. StickUp = Key.W,
  414. StickDown = Key.S,
  415. StickLeft = Key.A,
  416. StickRight = Key.D,
  417. StickButton = Key.F,
  418. DPadUp = Key.Up,
  419. DPadDown = Key.Down,
  420. DPadLeft = Key.Left,
  421. DPadRight = Key.Right,
  422. ButtonMinus = Key.Minus,
  423. ButtonL = Key.E,
  424. ButtonZl = Key.Q,
  425. ButtonSl = Key.Home,
  426. ButtonSr = Key.End
  427. },
  428. RightJoycon = new NpadKeyboardRight
  429. {
  430. StickUp = Key.I,
  431. StickDown = Key.K,
  432. StickLeft = Key.J,
  433. StickRight = Key.L,
  434. StickButton = Key.H,
  435. ButtonA = Key.Z,
  436. ButtonB = Key.X,
  437. ButtonX = Key.C,
  438. ButtonY = Key.V,
  439. ButtonPlus = Key.Plus,
  440. ButtonR = Key.U,
  441. ButtonZr = Key.O,
  442. ButtonSl = Key.PageUp,
  443. ButtonSr = Key.PageDown
  444. }
  445. }
  446. };
  447. }
  448. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  449. {
  450. bool configurationFileUpdated = false;
  451. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  452. {
  453. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  454. LoadDefault();
  455. return;
  456. }
  457. if (configurationFileFormat.Version < 2)
  458. {
  459. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  460. configurationFileFormat.SystemRegion = Region.USA;
  461. configurationFileUpdated = true;
  462. }
  463. if (configurationFileFormat.Version < 3)
  464. {
  465. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  466. configurationFileFormat.SystemTimeZone = "UTC";
  467. configurationFileUpdated = true;
  468. }
  469. if (configurationFileFormat.Version < 4)
  470. {
  471. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  472. configurationFileFormat.MaxAnisotropy = -1;
  473. configurationFileUpdated = true;
  474. }
  475. if (configurationFileFormat.Version < 5)
  476. {
  477. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  478. configurationFileFormat.SystemTimeOffset = 0;
  479. configurationFileUpdated = true;
  480. }
  481. if (configurationFileFormat.Version < 6)
  482. {
  483. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6.");
  484. configurationFileFormat.ControllerConfig = new List<ControllerConfig>();
  485. configurationFileFormat.KeyboardConfig = new List<KeyboardConfig>
  486. {
  487. new KeyboardConfig
  488. {
  489. Index = 0,
  490. ControllerType = ControllerType.JoyconPair,
  491. PlayerIndex = PlayerIndex.Player1,
  492. LeftJoycon = new NpadKeyboardLeft
  493. {
  494. StickUp = Key.W,
  495. StickDown = Key.S,
  496. StickLeft = Key.A,
  497. StickRight = Key.D,
  498. StickButton = Key.F,
  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. RightJoycon = new NpadKeyboardRight
  510. {
  511. StickUp = Key.I,
  512. StickDown = Key.K,
  513. StickLeft = Key.J,
  514. StickRight = Key.L,
  515. StickButton = Key.H,
  516. ButtonA = Key.Z,
  517. ButtonB = Key.X,
  518. ButtonX = Key.C,
  519. ButtonY = Key.V,
  520. ButtonPlus = Key.Plus,
  521. ButtonR = Key.U,
  522. ButtonZr = Key.O,
  523. ButtonSl = Key.Unbound,
  524. ButtonSr = Key.Unbound
  525. }
  526. }
  527. };
  528. configurationFileUpdated = true;
  529. }
  530. // Only needed for version 6 configurations.
  531. if (configurationFileFormat.Version == 6)
  532. {
  533. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
  534. for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
  535. {
  536. if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
  537. {
  538. configurationFileFormat.KeyboardConfig[i].Index++;
  539. }
  540. }
  541. }
  542. if (configurationFileFormat.Version < 8)
  543. {
  544. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  545. configurationFileFormat.EnablePtc = false;
  546. configurationFileUpdated = true;
  547. }
  548. if (configurationFileFormat.Version < 9)
  549. {
  550. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  551. configurationFileFormat.ColumnSort = new ColumnSort
  552. {
  553. SortColumnId = 0,
  554. SortAscending = false
  555. };
  556. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  557. {
  558. ToggleVsync = Key.Tab
  559. };
  560. configurationFileUpdated = true;
  561. }
  562. if (configurationFileFormat.Version < 10)
  563. {
  564. Common.Logging.Logger.PrintWarning(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  565. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  566. configurationFileUpdated = true;
  567. }
  568. List<InputConfig> inputConfig = new List<InputConfig>();
  569. inputConfig.AddRange(configurationFileFormat.ControllerConfig);
  570. inputConfig.AddRange(configurationFileFormat.KeyboardConfig);
  571. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  572. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  573. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  574. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  575. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  576. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  577. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  578. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  579. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  580. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  581. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  582. System.Language.Value = configurationFileFormat.SystemLanguage;
  583. System.Region.Value = configurationFileFormat.SystemRegion;
  584. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  585. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  586. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  587. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  588. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  589. System.EnableMulticoreScheduling.Value = configurationFileFormat.EnableMulticoreScheduling;
  590. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  591. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  592. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  593. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  594. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  595. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  596. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  597. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  598. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  599. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  600. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  601. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  602. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  603. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  604. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  605. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  606. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  607. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  608. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  609. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  610. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  611. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  612. Hid.InputConfig.Value = inputConfig;
  613. if (configurationFileUpdated)
  614. {
  615. ToFileFormat().SaveConfig(configurationFilePath);
  616. Common.Logging.Logger.PrintWarning(LogClass.Application, "Configuration file has been updated!");
  617. }
  618. }
  619. public static void Initialize()
  620. {
  621. if (Instance != null)
  622. {
  623. throw new InvalidOperationException("Configuration is already initialized");
  624. }
  625. Instance = new ConfigurationState();
  626. }
  627. }
  628. }