ConfigurationState.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. /// <summary>
  314. /// Hide Cursor on Idle
  315. /// </summary>
  316. public ReactiveObject<bool> HideCursorOnIdle { get; private set; }
  317. private ConfigurationState()
  318. {
  319. Ui = new UiSection();
  320. Logger = new LoggerSection();
  321. System = new SystemSection();
  322. Graphics = new GraphicsSection();
  323. Hid = new HidSection();
  324. EnableDiscordIntegration = new ReactiveObject<bool>();
  325. CheckUpdatesOnStart = new ReactiveObject<bool>();
  326. ShowConfirmExit = new ReactiveObject<bool>();
  327. HideCursorOnIdle = new ReactiveObject<bool>();
  328. }
  329. public ConfigurationFileFormat ToFileFormat()
  330. {
  331. List<ControllerConfig> controllerConfigList = new List<ControllerConfig>();
  332. List<KeyboardConfig> keyboardConfigList = new List<KeyboardConfig>();
  333. foreach (InputConfig inputConfig in Hid.InputConfig.Value)
  334. {
  335. if (inputConfig is ControllerConfig controllerConfig)
  336. {
  337. controllerConfigList.Add(controllerConfig);
  338. }
  339. else if (inputConfig is KeyboardConfig keyboardConfig)
  340. {
  341. keyboardConfigList.Add(keyboardConfig);
  342. }
  343. }
  344. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  345. {
  346. Version = ConfigurationFileFormat.CurrentVersion,
  347. ResScale = Graphics.ResScale,
  348. ResScaleCustom = Graphics.ResScaleCustom,
  349. MaxAnisotropy = Graphics.MaxAnisotropy,
  350. AspectRatio = Graphics.AspectRatio,
  351. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  352. LoggingEnableDebug = Logger.EnableDebug,
  353. LoggingEnableStub = Logger.EnableStub,
  354. LoggingEnableInfo = Logger.EnableInfo,
  355. LoggingEnableWarn = Logger.EnableWarn,
  356. LoggingEnableError = Logger.EnableError,
  357. LoggingEnableGuest = Logger.EnableGuest,
  358. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  359. LoggingFilteredClasses = Logger.FilteredClasses,
  360. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  361. EnableFileLog = Logger.EnableFileLog,
  362. SystemLanguage = System.Language,
  363. SystemRegion = System.Region,
  364. SystemTimeZone = System.TimeZone,
  365. SystemTimeOffset = System.SystemTimeOffset,
  366. DockedMode = System.EnableDockedMode,
  367. EnableDiscordIntegration = EnableDiscordIntegration,
  368. CheckUpdatesOnStart = CheckUpdatesOnStart,
  369. ShowConfirmExit = ShowConfirmExit,
  370. HideCursorOnIdle = HideCursorOnIdle,
  371. EnableVsync = Graphics.EnableVsync,
  372. EnableShaderCache = Graphics.EnableShaderCache,
  373. EnablePtc = System.EnablePtc,
  374. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  375. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  376. AudioBackend = System.AudioBackend,
  377. IgnoreMissingServices = System.IgnoreMissingServices,
  378. GuiColumns = new GuiColumns
  379. {
  380. FavColumn = Ui.GuiColumns.FavColumn,
  381. IconColumn = Ui.GuiColumns.IconColumn,
  382. AppColumn = Ui.GuiColumns.AppColumn,
  383. DevColumn = Ui.GuiColumns.DevColumn,
  384. VersionColumn = Ui.GuiColumns.VersionColumn,
  385. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  386. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  387. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  388. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  389. PathColumn = Ui.GuiColumns.PathColumn,
  390. },
  391. ColumnSort = new ColumnSort
  392. {
  393. SortColumnId = Ui.ColumnSort.SortColumnId,
  394. SortAscending = Ui.ColumnSort.SortAscending
  395. },
  396. GameDirs = Ui.GameDirs,
  397. EnableCustomTheme = Ui.EnableCustomTheme,
  398. CustomThemePath = Ui.CustomThemePath,
  399. StartFullscreen = Ui.StartFullscreen,
  400. EnableKeyboard = Hid.EnableKeyboard,
  401. Hotkeys = Hid.Hotkeys,
  402. KeyboardConfig = keyboardConfigList,
  403. ControllerConfig = controllerConfigList
  404. };
  405. return configurationFile;
  406. }
  407. public void LoadDefault()
  408. {
  409. Graphics.ResScale.Value = 1;
  410. Graphics.ResScaleCustom.Value = 1.0f;
  411. Graphics.MaxAnisotropy.Value = -1.0f;
  412. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  413. Graphics.ShadersDumpPath.Value = "";
  414. Logger.EnableDebug.Value = false;
  415. Logger.EnableStub.Value = true;
  416. Logger.EnableInfo.Value = true;
  417. Logger.EnableWarn.Value = true;
  418. Logger.EnableError.Value = true;
  419. Logger.EnableGuest.Value = true;
  420. Logger.EnableFsAccessLog.Value = false;
  421. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  422. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  423. Logger.EnableFileLog.Value = true;
  424. System.Language.Value = Language.AmericanEnglish;
  425. System.Region.Value = Region.USA;
  426. System.TimeZone.Value = "UTC";
  427. System.SystemTimeOffset.Value = 0;
  428. System.EnableDockedMode.Value = true;
  429. EnableDiscordIntegration.Value = true;
  430. CheckUpdatesOnStart.Value = true;
  431. ShowConfirmExit.Value = true;
  432. HideCursorOnIdle.Value = false;
  433. Graphics.EnableVsync.Value = true;
  434. Graphics.EnableShaderCache.Value = true;
  435. System.EnablePtc.Value = true;
  436. System.EnableFsIntegrityChecks.Value = true;
  437. System.FsGlobalAccessLogMode.Value = 0;
  438. System.AudioBackend.Value = AudioBackend.OpenAl;
  439. System.IgnoreMissingServices.Value = false;
  440. Ui.GuiColumns.FavColumn.Value = true;
  441. Ui.GuiColumns.IconColumn.Value = true;
  442. Ui.GuiColumns.AppColumn.Value = true;
  443. Ui.GuiColumns.DevColumn.Value = true;
  444. Ui.GuiColumns.VersionColumn.Value = true;
  445. Ui.GuiColumns.TimePlayedColumn.Value = true;
  446. Ui.GuiColumns.LastPlayedColumn.Value = true;
  447. Ui.GuiColumns.FileExtColumn.Value = true;
  448. Ui.GuiColumns.FileSizeColumn.Value = true;
  449. Ui.GuiColumns.PathColumn.Value = true;
  450. Ui.ColumnSort.SortColumnId.Value = 0;
  451. Ui.ColumnSort.SortAscending.Value = false;
  452. Ui.GameDirs.Value = new List<string>();
  453. Ui.EnableCustomTheme.Value = false;
  454. Ui.CustomThemePath.Value = "";
  455. Ui.StartFullscreen.Value = false;
  456. Hid.EnableKeyboard.Value = false;
  457. Hid.Hotkeys.Value = new KeyboardHotkeys
  458. {
  459. ToggleVsync = Key.Tab
  460. };
  461. Hid.InputConfig.Value = new List<InputConfig>
  462. {
  463. new KeyboardConfig
  464. {
  465. Index = 0,
  466. ControllerType = ControllerType.JoyconPair,
  467. PlayerIndex = PlayerIndex.Player1,
  468. LeftJoycon = new NpadKeyboardLeft
  469. {
  470. StickUp = Key.W,
  471. StickDown = Key.S,
  472. StickLeft = Key.A,
  473. StickRight = Key.D,
  474. StickButton = Key.F,
  475. DPadUp = Key.Up,
  476. DPadDown = Key.Down,
  477. DPadLeft = Key.Left,
  478. DPadRight = Key.Right,
  479. ButtonMinus = Key.Minus,
  480. ButtonL = Key.E,
  481. ButtonZl = Key.Q,
  482. ButtonSl = Key.Home,
  483. ButtonSr = Key.End
  484. },
  485. RightJoycon = new NpadKeyboardRight
  486. {
  487. StickUp = Key.I,
  488. StickDown = Key.K,
  489. StickLeft = Key.J,
  490. StickRight = Key.L,
  491. StickButton = Key.H,
  492. ButtonA = Key.Z,
  493. ButtonB = Key.X,
  494. ButtonX = Key.C,
  495. ButtonY = Key.V,
  496. ButtonPlus = Key.Plus,
  497. ButtonR = Key.U,
  498. ButtonZr = Key.O,
  499. ButtonSl = Key.PageUp,
  500. ButtonSr = Key.PageDown
  501. },
  502. EnableMotion = false,
  503. MirrorInput = false,
  504. Slot = 0,
  505. AltSlot = 0,
  506. Sensitivity = 100,
  507. GyroDeadzone = 1,
  508. DsuServerHost = "127.0.0.1",
  509. DsuServerPort = 26760
  510. }
  511. };
  512. }
  513. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  514. {
  515. bool configurationFileUpdated = false;
  516. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  517. {
  518. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  519. LoadDefault();
  520. return;
  521. }
  522. if (configurationFileFormat.Version < 2)
  523. {
  524. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  525. configurationFileFormat.SystemRegion = Region.USA;
  526. configurationFileUpdated = true;
  527. }
  528. if (configurationFileFormat.Version < 3)
  529. {
  530. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  531. configurationFileFormat.SystemTimeZone = "UTC";
  532. configurationFileUpdated = true;
  533. }
  534. if (configurationFileFormat.Version < 4)
  535. {
  536. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  537. configurationFileFormat.MaxAnisotropy = -1;
  538. configurationFileUpdated = true;
  539. }
  540. if (configurationFileFormat.Version < 5)
  541. {
  542. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  543. configurationFileFormat.SystemTimeOffset = 0;
  544. configurationFileUpdated = true;
  545. }
  546. if (configurationFileFormat.Version < 6)
  547. {
  548. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6.");
  549. configurationFileFormat.ControllerConfig = new List<ControllerConfig>();
  550. configurationFileFormat.KeyboardConfig = new List<KeyboardConfig>
  551. {
  552. new KeyboardConfig
  553. {
  554. Index = 0,
  555. ControllerType = ControllerType.JoyconPair,
  556. PlayerIndex = PlayerIndex.Player1,
  557. LeftJoycon = new NpadKeyboardLeft
  558. {
  559. StickUp = Key.W,
  560. StickDown = Key.S,
  561. StickLeft = Key.A,
  562. StickRight = Key.D,
  563. StickButton = Key.F,
  564. DPadUp = Key.Up,
  565. DPadDown = Key.Down,
  566. DPadLeft = Key.Left,
  567. DPadRight = Key.Right,
  568. ButtonMinus = Key.Minus,
  569. ButtonL = Key.E,
  570. ButtonZl = Key.Q,
  571. ButtonSl = Key.Unbound,
  572. ButtonSr = Key.Unbound
  573. },
  574. RightJoycon = new NpadKeyboardRight
  575. {
  576. StickUp = Key.I,
  577. StickDown = Key.K,
  578. StickLeft = Key.J,
  579. StickRight = Key.L,
  580. StickButton = Key.H,
  581. ButtonA = Key.Z,
  582. ButtonB = Key.X,
  583. ButtonX = Key.C,
  584. ButtonY = Key.V,
  585. ButtonPlus = Key.Plus,
  586. ButtonR = Key.U,
  587. ButtonZr = Key.O,
  588. ButtonSl = Key.Unbound,
  589. ButtonSr = Key.Unbound
  590. },
  591. EnableMotion = false,
  592. MirrorInput = false,
  593. Slot = 0,
  594. AltSlot = 0,
  595. Sensitivity = 100,
  596. GyroDeadzone = 1,
  597. DsuServerHost = "127.0.0.1",
  598. DsuServerPort = 26760
  599. }
  600. };
  601. configurationFileUpdated = true;
  602. }
  603. // Only needed for version 6 configurations.
  604. if (configurationFileFormat.Version == 6)
  605. {
  606. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
  607. for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
  608. {
  609. if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
  610. {
  611. configurationFileFormat.KeyboardConfig[i].Index++;
  612. }
  613. }
  614. }
  615. if (configurationFileFormat.Version < 8)
  616. {
  617. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  618. configurationFileFormat.EnablePtc = true;
  619. configurationFileUpdated = true;
  620. }
  621. if (configurationFileFormat.Version < 9)
  622. {
  623. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  624. configurationFileFormat.ColumnSort = new ColumnSort
  625. {
  626. SortColumnId = 0,
  627. SortAscending = false
  628. };
  629. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  630. {
  631. ToggleVsync = Key.Tab
  632. };
  633. configurationFileUpdated = true;
  634. }
  635. if (configurationFileFormat.Version < 10)
  636. {
  637. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  638. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  639. configurationFileUpdated = true;
  640. }
  641. if (configurationFileFormat.Version < 11)
  642. {
  643. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  644. configurationFileFormat.ResScale = 1;
  645. configurationFileFormat.ResScaleCustom = 1.0f;
  646. configurationFileUpdated = true;
  647. }
  648. if (configurationFileFormat.Version < 12)
  649. {
  650. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  651. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  652. configurationFileUpdated = true;
  653. }
  654. if (configurationFileFormat.Version < 14)
  655. {
  656. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  657. configurationFileFormat.CheckUpdatesOnStart = true;
  658. configurationFileUpdated = true;
  659. }
  660. if (configurationFileFormat.Version < 16)
  661. {
  662. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  663. configurationFileFormat.EnableShaderCache = true;
  664. configurationFileUpdated = true;
  665. }
  666. if (configurationFileFormat.Version < 17)
  667. {
  668. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  669. configurationFileFormat.StartFullscreen = false;
  670. configurationFileUpdated = true;
  671. }
  672. if (configurationFileFormat.Version < 18)
  673. {
  674. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  675. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  676. configurationFileUpdated = true;
  677. }
  678. if (configurationFileFormat.Version < 20)
  679. {
  680. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  681. configurationFileFormat.ShowConfirmExit = true;
  682. configurationFileUpdated = true;
  683. }
  684. if (configurationFileFormat.Version < 22)
  685. {
  686. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  687. configurationFileFormat.HideCursorOnIdle = false;
  688. configurationFileUpdated = true;
  689. }
  690. List<InputConfig> inputConfig = new List<InputConfig>();
  691. inputConfig.AddRange(configurationFileFormat.ControllerConfig);
  692. inputConfig.AddRange(configurationFileFormat.KeyboardConfig);
  693. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  694. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  695. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  696. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  697. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  698. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  699. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  700. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  701. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  702. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  703. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  704. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  705. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  706. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  707. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  708. System.Language.Value = configurationFileFormat.SystemLanguage;
  709. System.Region.Value = configurationFileFormat.SystemRegion;
  710. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  711. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  712. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  713. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  714. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  715. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  716. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  717. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  718. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  719. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  720. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  721. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  722. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  723. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  724. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  725. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  726. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  727. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  728. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  729. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  730. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  731. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  732. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  733. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  734. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  735. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  736. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  737. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  738. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  739. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  740. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  741. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  742. Hid.InputConfig.Value = inputConfig;
  743. if (configurationFileUpdated)
  744. {
  745. ToFileFormat().SaveConfig(configurationFilePath);
  746. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  747. }
  748. }
  749. public static void Initialize()
  750. {
  751. if (Instance != null)
  752. {
  753. throw new InvalidOperationException("Configuration is already initialized");
  754. }
  755. Instance = new ConfigurationState();
  756. }
  757. }
  758. }