ConfigurationState.cs 33 KB

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