ConfigurationState.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. /// <summary>
  76. /// Start games in fullscreen mode
  77. /// </summary>
  78. public ReactiveObject<bool> StartFullscreen { get; private set; }
  79. public UiSection()
  80. {
  81. GuiColumns = new Columns();
  82. ColumnSort = new ColumnSortSettings();
  83. GameDirs = new ReactiveObject<List<string>>();
  84. EnableCustomTheme = new ReactiveObject<bool>();
  85. CustomThemePath = new ReactiveObject<string>();
  86. StartFullscreen = new ReactiveObject<bool>();
  87. }
  88. }
  89. /// <summary>
  90. /// Logger configuration section
  91. /// </summary>
  92. public class LoggerSection
  93. {
  94. /// <summary>
  95. /// Enables printing debug log messages
  96. /// </summary>
  97. public ReactiveObject<bool> EnableDebug { get; private set; }
  98. /// <summary>
  99. /// Enables printing stub log messages
  100. /// </summary>
  101. public ReactiveObject<bool> EnableStub { get; private set; }
  102. /// <summary>
  103. /// Enables printing info log messages
  104. /// </summary>
  105. public ReactiveObject<bool> EnableInfo { get; private set; }
  106. /// <summary>
  107. /// Enables printing warning log messages
  108. /// </summary>
  109. public ReactiveObject<bool> EnableWarn { get; private set; }
  110. /// <summary>
  111. /// Enables printing error log messages
  112. /// </summary>
  113. public ReactiveObject<bool> EnableError { get; private set; }
  114. /// <summary>
  115. /// Enables printing guest log messages
  116. /// </summary>
  117. public ReactiveObject<bool> EnableGuest { get; private set; }
  118. /// <summary>
  119. /// Enables printing FS access log messages
  120. /// </summary>
  121. public ReactiveObject<bool> EnableFsAccessLog { get; private set; }
  122. /// <summary>
  123. /// Controls which log messages are written to the log targets
  124. /// </summary>
  125. public ReactiveObject<LogClass[]> FilteredClasses { get; private set; }
  126. /// <summary>
  127. /// Enables or disables logging to a file on disk
  128. /// </summary>
  129. public ReactiveObject<bool> EnableFileLog { get; private set; }
  130. /// <summary>
  131. /// Controls which OpenGL log messages are recorded in the log
  132. /// </summary>
  133. public ReactiveObject<GraphicsDebugLevel> GraphicsDebugLevel { get; private set; }
  134. public LoggerSection()
  135. {
  136. EnableDebug = new ReactiveObject<bool>();
  137. EnableStub = new ReactiveObject<bool>();
  138. EnableInfo = new ReactiveObject<bool>();
  139. EnableWarn = new ReactiveObject<bool>();
  140. EnableError = new ReactiveObject<bool>();
  141. EnableGuest = new ReactiveObject<bool>();
  142. EnableFsAccessLog = new ReactiveObject<bool>();
  143. FilteredClasses = new ReactiveObject<LogClass[]>();
  144. EnableFileLog = new ReactiveObject<bool>();
  145. GraphicsDebugLevel = new ReactiveObject<GraphicsDebugLevel>();
  146. }
  147. }
  148. /// <summary>
  149. /// System configuration section
  150. /// </summary>
  151. public class SystemSection
  152. {
  153. /// <summary>
  154. /// Change System Language
  155. /// </summary>
  156. public ReactiveObject<Language> Language { get; private set; }
  157. /// <summary>
  158. /// Change System Region
  159. /// </summary>
  160. public ReactiveObject<Region> Region { get; private set; }
  161. /// <summary>
  162. /// Change System TimeZone
  163. /// </summary>
  164. public ReactiveObject<string> TimeZone { get; private set; }
  165. /// <summary>
  166. /// System Time Offset in Seconds
  167. /// </summary>
  168. public ReactiveObject<long> SystemTimeOffset { get; private set; }
  169. /// <summary>
  170. /// Enables or disables Docked Mode
  171. /// </summary>
  172. public ReactiveObject<bool> EnableDockedMode { get; private set; }
  173. /// <summary>
  174. /// Enables or disables profiled translation cache persistency
  175. /// </summary>
  176. public ReactiveObject<bool> EnablePtc { get; private set; }
  177. /// <summary>
  178. /// Enables integrity checks on Game content files
  179. /// </summary>
  180. public ReactiveObject<bool> EnableFsIntegrityChecks { get; private set; }
  181. /// <summary>
  182. /// Enables FS access log output to the console. Possible modes are 0-3
  183. /// </summary>
  184. public ReactiveObject<int> FsGlobalAccessLogMode { get; private set; }
  185. /// <summary>
  186. /// The selected audio backend
  187. /// </summary>
  188. public ReactiveObject<AudioBackend> AudioBackend { get; private set; }
  189. /// <summary>
  190. /// Enable or disable ignoring missing services
  191. /// </summary>
  192. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  193. public SystemSection()
  194. {
  195. Language = new ReactiveObject<Language>();
  196. Region = new ReactiveObject<Region>();
  197. TimeZone = new ReactiveObject<string>();
  198. SystemTimeOffset = new ReactiveObject<long>();
  199. EnableDockedMode = 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. /// Aspect Ratio applied to the renderer window.
  244. /// </summary>
  245. public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
  246. /// <summary>
  247. /// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
  248. /// </summary>
  249. public ReactiveObject<int> ResScale { get; private set; }
  250. /// <summary>
  251. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
  252. /// </summary>
  253. public ReactiveObject<float> ResScaleCustom { get; private set; }
  254. /// <summary>
  255. /// Dumps shaders in this local directory
  256. /// </summary>
  257. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  258. /// <summary>
  259. /// Enables or disables Vertical Sync
  260. /// </summary>
  261. public ReactiveObject<bool> EnableVsync { get; private set; }
  262. /// <summary>
  263. /// Enables or disables Shader cache
  264. /// </summary>
  265. public ReactiveObject<bool> EnableShaderCache { get; private set; }
  266. public GraphicsSection()
  267. {
  268. ResScale = new ReactiveObject<int>();
  269. ResScaleCustom = new ReactiveObject<float>();
  270. MaxAnisotropy = new ReactiveObject<float>();
  271. AspectRatio = new ReactiveObject<AspectRatio>();
  272. ShadersDumpPath = new ReactiveObject<string>();
  273. EnableVsync = new ReactiveObject<bool>();
  274. EnableShaderCache = new ReactiveObject<bool>();
  275. }
  276. }
  277. /// <summary>
  278. /// The default configuration instance
  279. /// </summary>
  280. public static ConfigurationState Instance { get; private set; }
  281. /// <summary>
  282. /// The Ui section
  283. /// </summary>
  284. public UiSection Ui { get; private set; }
  285. /// <summary>
  286. /// The Logger section
  287. /// </summary>
  288. public LoggerSection Logger { get; private set; }
  289. /// <summary>
  290. /// The System section
  291. /// </summary>
  292. public SystemSection System { get; private set; }
  293. /// <summary>
  294. /// The Graphics section
  295. /// </summary>
  296. public GraphicsSection Graphics { get; private set; }
  297. /// <summary>
  298. /// The Hid section
  299. /// </summary>
  300. public HidSection Hid { get; private set; }
  301. /// <summary>
  302. /// Enables or disables Discord Rich Presence
  303. /// </summary>
  304. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  305. /// <summary>
  306. /// Checks for updates when Ryujinx starts when enabled
  307. /// </summary>
  308. public ReactiveObject<bool> CheckUpdatesOnStart { get; private set; }
  309. /// <summary>
  310. /// Show "Confirm Exit" Dialog
  311. /// </summary>
  312. public ReactiveObject<bool> ShowConfirmExit { get; private set; }
  313. private ConfigurationState()
  314. {
  315. Ui = new UiSection();
  316. Logger = new LoggerSection();
  317. System = new SystemSection();
  318. Graphics = new GraphicsSection();
  319. Hid = new HidSection();
  320. EnableDiscordIntegration = new ReactiveObject<bool>();
  321. CheckUpdatesOnStart = new ReactiveObject<bool>();
  322. ShowConfirmExit = new ReactiveObject<bool>();
  323. }
  324. public ConfigurationFileFormat ToFileFormat()
  325. {
  326. List<ControllerConfig> controllerConfigList = new List<ControllerConfig>();
  327. List<KeyboardConfig> keyboardConfigList = new List<KeyboardConfig>();
  328. foreach (InputConfig inputConfig in Hid.InputConfig.Value)
  329. {
  330. if (inputConfig is ControllerConfig controllerConfig)
  331. {
  332. controllerConfigList.Add(controllerConfig);
  333. }
  334. else if (inputConfig is KeyboardConfig keyboardConfig)
  335. {
  336. keyboardConfigList.Add(keyboardConfig);
  337. }
  338. }
  339. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  340. {
  341. Version = ConfigurationFileFormat.CurrentVersion,
  342. ResScale = Graphics.ResScale,
  343. ResScaleCustom = Graphics.ResScaleCustom,
  344. MaxAnisotropy = Graphics.MaxAnisotropy,
  345. AspectRatio = Graphics.AspectRatio,
  346. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  347. LoggingEnableDebug = Logger.EnableDebug,
  348. LoggingEnableStub = Logger.EnableStub,
  349. LoggingEnableInfo = Logger.EnableInfo,
  350. LoggingEnableWarn = Logger.EnableWarn,
  351. LoggingEnableError = Logger.EnableError,
  352. LoggingEnableGuest = Logger.EnableGuest,
  353. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  354. LoggingFilteredClasses = Logger.FilteredClasses,
  355. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  356. EnableFileLog = Logger.EnableFileLog,
  357. SystemLanguage = System.Language,
  358. SystemRegion = System.Region,
  359. SystemTimeZone = System.TimeZone,
  360. SystemTimeOffset = System.SystemTimeOffset,
  361. DockedMode = System.EnableDockedMode,
  362. EnableDiscordIntegration = EnableDiscordIntegration,
  363. CheckUpdatesOnStart = CheckUpdatesOnStart,
  364. ShowConfirmExit = ShowConfirmExit,
  365. EnableVsync = Graphics.EnableVsync,
  366. EnableShaderCache = Graphics.EnableShaderCache,
  367. EnablePtc = System.EnablePtc,
  368. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  369. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  370. AudioBackend = System.AudioBackend,
  371. IgnoreMissingServices = System.IgnoreMissingServices,
  372. GuiColumns = new GuiColumns
  373. {
  374. FavColumn = Ui.GuiColumns.FavColumn,
  375. IconColumn = Ui.GuiColumns.IconColumn,
  376. AppColumn = Ui.GuiColumns.AppColumn,
  377. DevColumn = Ui.GuiColumns.DevColumn,
  378. VersionColumn = Ui.GuiColumns.VersionColumn,
  379. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  380. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  381. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  382. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  383. PathColumn = Ui.GuiColumns.PathColumn,
  384. },
  385. ColumnSort = new ColumnSort
  386. {
  387. SortColumnId = Ui.ColumnSort.SortColumnId,
  388. SortAscending = Ui.ColumnSort.SortAscending
  389. },
  390. GameDirs = Ui.GameDirs,
  391. EnableCustomTheme = Ui.EnableCustomTheme,
  392. CustomThemePath = Ui.CustomThemePath,
  393. StartFullscreen = Ui.StartFullscreen,
  394. EnableKeyboard = Hid.EnableKeyboard,
  395. Hotkeys = Hid.Hotkeys,
  396. KeyboardConfig = keyboardConfigList,
  397. ControllerConfig = controllerConfigList
  398. };
  399. return configurationFile;
  400. }
  401. public void LoadDefault()
  402. {
  403. Graphics.ResScale.Value = 1;
  404. Graphics.ResScaleCustom.Value = 1.0f;
  405. Graphics.MaxAnisotropy.Value = -1.0f;
  406. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  407. Graphics.ShadersDumpPath.Value = "";
  408. Logger.EnableDebug.Value = false;
  409. Logger.EnableStub.Value = true;
  410. Logger.EnableInfo.Value = true;
  411. Logger.EnableWarn.Value = true;
  412. Logger.EnableError.Value = true;
  413. Logger.EnableGuest.Value = true;
  414. Logger.EnableFsAccessLog.Value = false;
  415. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  416. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  417. Logger.EnableFileLog.Value = true;
  418. System.Language.Value = Language.AmericanEnglish;
  419. System.Region.Value = Region.USA;
  420. System.TimeZone.Value = "UTC";
  421. System.SystemTimeOffset.Value = 0;
  422. System.EnableDockedMode.Value = false;
  423. EnableDiscordIntegration.Value = true;
  424. CheckUpdatesOnStart.Value = true;
  425. ShowConfirmExit.Value = true;
  426. Graphics.EnableVsync.Value = true;
  427. Graphics.EnableShaderCache.Value = true;
  428. System.EnablePtc.Value = true;
  429. System.EnableFsIntegrityChecks.Value = true;
  430. System.FsGlobalAccessLogMode.Value = 0;
  431. System.AudioBackend.Value = AudioBackend.OpenAl;
  432. System.IgnoreMissingServices.Value = false;
  433. Ui.GuiColumns.FavColumn.Value = true;
  434. Ui.GuiColumns.IconColumn.Value = true;
  435. Ui.GuiColumns.AppColumn.Value = true;
  436. Ui.GuiColumns.DevColumn.Value = true;
  437. Ui.GuiColumns.VersionColumn.Value = true;
  438. Ui.GuiColumns.TimePlayedColumn.Value = true;
  439. Ui.GuiColumns.LastPlayedColumn.Value = true;
  440. Ui.GuiColumns.FileExtColumn.Value = true;
  441. Ui.GuiColumns.FileSizeColumn.Value = true;
  442. Ui.GuiColumns.PathColumn.Value = true;
  443. Ui.ColumnSort.SortColumnId.Value = 0;
  444. Ui.ColumnSort.SortAscending.Value = false;
  445. Ui.GameDirs.Value = new List<string>();
  446. Ui.EnableCustomTheme.Value = false;
  447. Ui.CustomThemePath.Value = "";
  448. Ui.StartFullscreen.Value = false;
  449. Hid.EnableKeyboard.Value = false;
  450. Hid.Hotkeys.Value = new KeyboardHotkeys
  451. {
  452. ToggleVsync = Key.Tab
  453. };
  454. Hid.InputConfig.Value = new List<InputConfig>
  455. {
  456. new KeyboardConfig
  457. {
  458. Index = 0,
  459. ControllerType = ControllerType.JoyconPair,
  460. PlayerIndex = PlayerIndex.Player1,
  461. LeftJoycon = new NpadKeyboardLeft
  462. {
  463. StickUp = Key.W,
  464. StickDown = Key.S,
  465. StickLeft = Key.A,
  466. StickRight = Key.D,
  467. StickButton = Key.F,
  468. DPadUp = Key.Up,
  469. DPadDown = Key.Down,
  470. DPadLeft = Key.Left,
  471. DPadRight = Key.Right,
  472. ButtonMinus = Key.Minus,
  473. ButtonL = Key.E,
  474. ButtonZl = Key.Q,
  475. ButtonSl = Key.Home,
  476. ButtonSr = Key.End
  477. },
  478. RightJoycon = new NpadKeyboardRight
  479. {
  480. StickUp = Key.I,
  481. StickDown = Key.K,
  482. StickLeft = Key.J,
  483. StickRight = Key.L,
  484. StickButton = Key.H,
  485. ButtonA = Key.Z,
  486. ButtonB = Key.X,
  487. ButtonX = Key.C,
  488. ButtonY = Key.V,
  489. ButtonPlus = Key.Plus,
  490. ButtonR = Key.U,
  491. ButtonZr = Key.O,
  492. ButtonSl = Key.PageUp,
  493. ButtonSr = Key.PageDown
  494. },
  495. EnableMotion = false,
  496. MirrorInput = false,
  497. Slot = 0,
  498. AltSlot = 0,
  499. Sensitivity = 100,
  500. GyroDeadzone = 1,
  501. DsuServerHost = "127.0.0.1",
  502. DsuServerPort = 26760
  503. }
  504. };
  505. }
  506. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  507. {
  508. bool configurationFileUpdated = false;
  509. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  510. {
  511. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  512. LoadDefault();
  513. return;
  514. }
  515. if (configurationFileFormat.Version < 2)
  516. {
  517. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  518. configurationFileFormat.SystemRegion = Region.USA;
  519. configurationFileUpdated = true;
  520. }
  521. if (configurationFileFormat.Version < 3)
  522. {
  523. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  524. configurationFileFormat.SystemTimeZone = "UTC";
  525. configurationFileUpdated = true;
  526. }
  527. if (configurationFileFormat.Version < 4)
  528. {
  529. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  530. configurationFileFormat.MaxAnisotropy = -1;
  531. configurationFileUpdated = true;
  532. }
  533. if (configurationFileFormat.Version < 5)
  534. {
  535. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  536. configurationFileFormat.SystemTimeOffset = 0;
  537. configurationFileUpdated = true;
  538. }
  539. if (configurationFileFormat.Version < 6)
  540. {
  541. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6.");
  542. configurationFileFormat.ControllerConfig = new List<ControllerConfig>();
  543. configurationFileFormat.KeyboardConfig = new List<KeyboardConfig>
  544. {
  545. new KeyboardConfig
  546. {
  547. Index = 0,
  548. ControllerType = ControllerType.JoyconPair,
  549. PlayerIndex = PlayerIndex.Player1,
  550. LeftJoycon = new NpadKeyboardLeft
  551. {
  552. StickUp = Key.W,
  553. StickDown = Key.S,
  554. StickLeft = Key.A,
  555. StickRight = Key.D,
  556. StickButton = Key.F,
  557. DPadUp = Key.Up,
  558. DPadDown = Key.Down,
  559. DPadLeft = Key.Left,
  560. DPadRight = Key.Right,
  561. ButtonMinus = Key.Minus,
  562. ButtonL = Key.E,
  563. ButtonZl = Key.Q,
  564. ButtonSl = Key.Unbound,
  565. ButtonSr = Key.Unbound
  566. },
  567. RightJoycon = new NpadKeyboardRight
  568. {
  569. StickUp = Key.I,
  570. StickDown = Key.K,
  571. StickLeft = Key.J,
  572. StickRight = Key.L,
  573. StickButton = Key.H,
  574. ButtonA = Key.Z,
  575. ButtonB = Key.X,
  576. ButtonX = Key.C,
  577. ButtonY = Key.V,
  578. ButtonPlus = Key.Plus,
  579. ButtonR = Key.U,
  580. ButtonZr = Key.O,
  581. ButtonSl = Key.Unbound,
  582. ButtonSr = Key.Unbound
  583. },
  584. EnableMotion = false,
  585. MirrorInput = false,
  586. Slot = 0,
  587. AltSlot = 0,
  588. Sensitivity = 100,
  589. GyroDeadzone = 1,
  590. DsuServerHost = "127.0.0.1",
  591. DsuServerPort = 26760
  592. }
  593. };
  594. configurationFileUpdated = true;
  595. }
  596. // Only needed for version 6 configurations.
  597. if (configurationFileFormat.Version == 6)
  598. {
  599. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
  600. for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
  601. {
  602. if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
  603. {
  604. configurationFileFormat.KeyboardConfig[i].Index++;
  605. }
  606. }
  607. }
  608. if (configurationFileFormat.Version < 8)
  609. {
  610. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  611. configurationFileFormat.EnablePtc = true;
  612. configurationFileUpdated = true;
  613. }
  614. if (configurationFileFormat.Version < 9)
  615. {
  616. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  617. configurationFileFormat.ColumnSort = new ColumnSort
  618. {
  619. SortColumnId = 0,
  620. SortAscending = false
  621. };
  622. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  623. {
  624. ToggleVsync = Key.Tab
  625. };
  626. configurationFileUpdated = true;
  627. }
  628. if (configurationFileFormat.Version < 10)
  629. {
  630. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  631. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  632. configurationFileUpdated = true;
  633. }
  634. if (configurationFileFormat.Version < 11)
  635. {
  636. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  637. configurationFileFormat.ResScale = 1;
  638. configurationFileFormat.ResScaleCustom = 1.0f;
  639. configurationFileUpdated = true;
  640. }
  641. if (configurationFileFormat.Version < 12)
  642. {
  643. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  644. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  645. configurationFileUpdated = true;
  646. }
  647. if (configurationFileFormat.Version < 14)
  648. {
  649. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  650. configurationFileFormat.CheckUpdatesOnStart = true;
  651. configurationFileUpdated = true;
  652. }
  653. if (configurationFileFormat.Version < 16)
  654. {
  655. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  656. configurationFileFormat.EnableShaderCache = true;
  657. configurationFileUpdated = true;
  658. }
  659. if (configurationFileFormat.Version < 17)
  660. {
  661. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  662. configurationFileFormat.StartFullscreen = false;
  663. configurationFileUpdated = true;
  664. }
  665. if (configurationFileFormat.Version < 18)
  666. {
  667. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  668. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  669. configurationFileUpdated = true;
  670. }
  671. if (configurationFileFormat.Version < 20)
  672. {
  673. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  674. configurationFileFormat.ShowConfirmExit = true;
  675. configurationFileUpdated = true;
  676. }
  677. List<InputConfig> inputConfig = new List<InputConfig>();
  678. inputConfig.AddRange(configurationFileFormat.ControllerConfig);
  679. inputConfig.AddRange(configurationFileFormat.KeyboardConfig);
  680. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  681. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  682. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  683. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  684. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  685. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  686. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  687. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  688. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  689. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  690. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  691. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  692. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  693. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  694. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  695. System.Language.Value = configurationFileFormat.SystemLanguage;
  696. System.Region.Value = configurationFileFormat.SystemRegion;
  697. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  698. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  699. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  700. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  701. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  702. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  703. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  704. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  705. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  706. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  707. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  708. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  709. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  710. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  711. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  712. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  713. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  714. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  715. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  716. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  717. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  718. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  719. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  720. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  721. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  722. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  723. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  724. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  725. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  726. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  727. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  728. Hid.InputConfig.Value = inputConfig;
  729. if (configurationFileUpdated)
  730. {
  731. ToFileFormat().SaveConfig(configurationFilePath);
  732. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  733. }
  734. }
  735. public static void Initialize()
  736. {
  737. if (Instance != null)
  738. {
  739. throw new InvalidOperationException("Configuration is already initialized");
  740. }
  741. Instance = new ConfigurationState();
  742. }
  743. }
  744. }