ConfigurationState.cs 36 KB

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