ConfigurationState.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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. /// Defines the amount of RAM available on the emulated system, and how it is distributed
  191. /// </summary>
  192. public ReactiveObject<bool> ExpandRam { get; private set; }
  193. /// <summary>
  194. /// Enable or disable ignoring missing services
  195. /// </summary>
  196. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  197. public SystemSection()
  198. {
  199. Language = new ReactiveObject<Language>();
  200. Region = new ReactiveObject<Region>();
  201. TimeZone = new ReactiveObject<string>();
  202. SystemTimeOffset = new ReactiveObject<long>();
  203. EnableDockedMode = new ReactiveObject<bool>();
  204. EnablePtc = new ReactiveObject<bool>();
  205. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  206. FsGlobalAccessLogMode = new ReactiveObject<int>();
  207. AudioBackend = new ReactiveObject<AudioBackend>();
  208. ExpandRam = new ReactiveObject<bool>();
  209. IgnoreMissingServices = new ReactiveObject<bool>();
  210. }
  211. }
  212. /// <summary>
  213. /// Hid configuration section
  214. /// </summary>
  215. public class HidSection
  216. {
  217. /// <summary>
  218. /// Enable or disable keyboard support (Independent from controllers binding)
  219. /// </summary>
  220. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  221. /// <summary>
  222. /// Hotkey Keyboard Bindings
  223. /// </summary>
  224. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  225. /// <summary>
  226. /// Input device configuration.
  227. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  228. /// TODO: Implement a ReactiveList class.
  229. /// </summary>
  230. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  231. public HidSection()
  232. {
  233. EnableKeyboard = new ReactiveObject<bool>();
  234. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  235. InputConfig = new ReactiveObject<List<InputConfig>>();
  236. }
  237. }
  238. /// <summary>
  239. /// Graphics configuration section
  240. /// </summary>
  241. public class GraphicsSection
  242. {
  243. /// <summary>
  244. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  245. /// </summary>
  246. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  247. /// <summary>
  248. /// Aspect Ratio applied to the renderer window.
  249. /// </summary>
  250. public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
  251. /// <summary>
  252. /// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
  253. /// </summary>
  254. public ReactiveObject<int> ResScale { get; private set; }
  255. /// <summary>
  256. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
  257. /// </summary>
  258. public ReactiveObject<float> ResScaleCustom { get; private set; }
  259. /// <summary>
  260. /// Dumps shaders in this local directory
  261. /// </summary>
  262. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  263. /// <summary>
  264. /// Enables or disables Vertical Sync
  265. /// </summary>
  266. public ReactiveObject<bool> EnableVsync { get; private set; }
  267. /// <summary>
  268. /// Enables or disables Shader cache
  269. /// </summary>
  270. public ReactiveObject<bool> EnableShaderCache { get; private set; }
  271. public GraphicsSection()
  272. {
  273. ResScale = new ReactiveObject<int>();
  274. ResScaleCustom = new ReactiveObject<float>();
  275. MaxAnisotropy = new ReactiveObject<float>();
  276. AspectRatio = new ReactiveObject<AspectRatio>();
  277. ShadersDumpPath = new ReactiveObject<string>();
  278. EnableVsync = new ReactiveObject<bool>();
  279. EnableShaderCache = new ReactiveObject<bool>();
  280. }
  281. }
  282. /// <summary>
  283. /// The default configuration instance
  284. /// </summary>
  285. public static ConfigurationState Instance { get; private set; }
  286. /// <summary>
  287. /// The Ui section
  288. /// </summary>
  289. public UiSection Ui { get; private set; }
  290. /// <summary>
  291. /// The Logger section
  292. /// </summary>
  293. public LoggerSection Logger { get; private set; }
  294. /// <summary>
  295. /// The System section
  296. /// </summary>
  297. public SystemSection System { get; private set; }
  298. /// <summary>
  299. /// The Graphics section
  300. /// </summary>
  301. public GraphicsSection Graphics { get; private set; }
  302. /// <summary>
  303. /// The Hid section
  304. /// </summary>
  305. public HidSection Hid { get; private set; }
  306. /// <summary>
  307. /// Enables or disables Discord Rich Presence
  308. /// </summary>
  309. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  310. /// <summary>
  311. /// Checks for updates when Ryujinx starts when enabled
  312. /// </summary>
  313. public ReactiveObject<bool> CheckUpdatesOnStart { get; private set; }
  314. /// <summary>
  315. /// Show "Confirm Exit" Dialog
  316. /// </summary>
  317. public ReactiveObject<bool> ShowConfirmExit { get; private set; }
  318. /// <summary>
  319. /// Hide Cursor on Idle
  320. /// </summary>
  321. public ReactiveObject<bool> HideCursorOnIdle { get; private set; }
  322. private ConfigurationState()
  323. {
  324. Ui = new UiSection();
  325. Logger = new LoggerSection();
  326. System = new SystemSection();
  327. Graphics = new GraphicsSection();
  328. Hid = new HidSection();
  329. EnableDiscordIntegration = new ReactiveObject<bool>();
  330. CheckUpdatesOnStart = new ReactiveObject<bool>();
  331. ShowConfirmExit = new ReactiveObject<bool>();
  332. HideCursorOnIdle = new ReactiveObject<bool>();
  333. }
  334. public ConfigurationFileFormat ToFileFormat()
  335. {
  336. List<ControllerConfig> controllerConfigList = new List<ControllerConfig>();
  337. List<KeyboardConfig> keyboardConfigList = new List<KeyboardConfig>();
  338. foreach (InputConfig inputConfig in Hid.InputConfig.Value)
  339. {
  340. if (inputConfig is ControllerConfig controllerConfig)
  341. {
  342. controllerConfigList.Add(controllerConfig);
  343. }
  344. else if (inputConfig is KeyboardConfig keyboardConfig)
  345. {
  346. keyboardConfigList.Add(keyboardConfig);
  347. }
  348. }
  349. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  350. {
  351. Version = ConfigurationFileFormat.CurrentVersion,
  352. ResScale = Graphics.ResScale,
  353. ResScaleCustom = Graphics.ResScaleCustom,
  354. MaxAnisotropy = Graphics.MaxAnisotropy,
  355. AspectRatio = Graphics.AspectRatio,
  356. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  357. LoggingEnableDebug = Logger.EnableDebug,
  358. LoggingEnableStub = Logger.EnableStub,
  359. LoggingEnableInfo = Logger.EnableInfo,
  360. LoggingEnableWarn = Logger.EnableWarn,
  361. LoggingEnableError = Logger.EnableError,
  362. LoggingEnableGuest = Logger.EnableGuest,
  363. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  364. LoggingFilteredClasses = Logger.FilteredClasses,
  365. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  366. EnableFileLog = Logger.EnableFileLog,
  367. SystemLanguage = System.Language,
  368. SystemRegion = System.Region,
  369. SystemTimeZone = System.TimeZone,
  370. SystemTimeOffset = System.SystemTimeOffset,
  371. DockedMode = System.EnableDockedMode,
  372. EnableDiscordIntegration = EnableDiscordIntegration,
  373. CheckUpdatesOnStart = CheckUpdatesOnStart,
  374. ShowConfirmExit = ShowConfirmExit,
  375. HideCursorOnIdle = HideCursorOnIdle,
  376. EnableVsync = Graphics.EnableVsync,
  377. EnableShaderCache = Graphics.EnableShaderCache,
  378. EnablePtc = System.EnablePtc,
  379. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  380. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  381. AudioBackend = System.AudioBackend,
  382. ExpandRam = System.ExpandRam,
  383. IgnoreMissingServices = System.IgnoreMissingServices,
  384. GuiColumns = new GuiColumns
  385. {
  386. FavColumn = Ui.GuiColumns.FavColumn,
  387. IconColumn = Ui.GuiColumns.IconColumn,
  388. AppColumn = Ui.GuiColumns.AppColumn,
  389. DevColumn = Ui.GuiColumns.DevColumn,
  390. VersionColumn = Ui.GuiColumns.VersionColumn,
  391. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  392. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  393. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  394. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  395. PathColumn = Ui.GuiColumns.PathColumn,
  396. },
  397. ColumnSort = new ColumnSort
  398. {
  399. SortColumnId = Ui.ColumnSort.SortColumnId,
  400. SortAscending = Ui.ColumnSort.SortAscending
  401. },
  402. GameDirs = Ui.GameDirs,
  403. EnableCustomTheme = Ui.EnableCustomTheme,
  404. CustomThemePath = Ui.CustomThemePath,
  405. StartFullscreen = Ui.StartFullscreen,
  406. EnableKeyboard = Hid.EnableKeyboard,
  407. Hotkeys = Hid.Hotkeys,
  408. KeyboardConfig = keyboardConfigList,
  409. ControllerConfig = controllerConfigList
  410. };
  411. return configurationFile;
  412. }
  413. public void LoadDefault()
  414. {
  415. Graphics.ResScale.Value = 1;
  416. Graphics.ResScaleCustom.Value = 1.0f;
  417. Graphics.MaxAnisotropy.Value = -1.0f;
  418. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  419. Graphics.ShadersDumpPath.Value = "";
  420. Logger.EnableDebug.Value = false;
  421. Logger.EnableStub.Value = true;
  422. Logger.EnableInfo.Value = true;
  423. Logger.EnableWarn.Value = true;
  424. Logger.EnableError.Value = true;
  425. Logger.EnableGuest.Value = true;
  426. Logger.EnableFsAccessLog.Value = false;
  427. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  428. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  429. Logger.EnableFileLog.Value = true;
  430. System.Language.Value = Language.AmericanEnglish;
  431. System.Region.Value = Region.USA;
  432. System.TimeZone.Value = "UTC";
  433. System.SystemTimeOffset.Value = 0;
  434. System.EnableDockedMode.Value = true;
  435. EnableDiscordIntegration.Value = true;
  436. CheckUpdatesOnStart.Value = true;
  437. ShowConfirmExit.Value = true;
  438. HideCursorOnIdle.Value = false;
  439. Graphics.EnableVsync.Value = true;
  440. Graphics.EnableShaderCache.Value = true;
  441. System.EnablePtc.Value = true;
  442. System.EnableFsIntegrityChecks.Value = true;
  443. System.FsGlobalAccessLogMode.Value = 0;
  444. System.AudioBackend.Value = AudioBackend.OpenAl;
  445. System.ExpandRam.Value = false;
  446. System.IgnoreMissingServices.Value = false;
  447. Ui.GuiColumns.FavColumn.Value = true;
  448. Ui.GuiColumns.IconColumn.Value = true;
  449. Ui.GuiColumns.AppColumn.Value = true;
  450. Ui.GuiColumns.DevColumn.Value = true;
  451. Ui.GuiColumns.VersionColumn.Value = true;
  452. Ui.GuiColumns.TimePlayedColumn.Value = true;
  453. Ui.GuiColumns.LastPlayedColumn.Value = true;
  454. Ui.GuiColumns.FileExtColumn.Value = true;
  455. Ui.GuiColumns.FileSizeColumn.Value = true;
  456. Ui.GuiColumns.PathColumn.Value = true;
  457. Ui.ColumnSort.SortColumnId.Value = 0;
  458. Ui.ColumnSort.SortAscending.Value = false;
  459. Ui.GameDirs.Value = new List<string>();
  460. Ui.EnableCustomTheme.Value = false;
  461. Ui.CustomThemePath.Value = "";
  462. Ui.StartFullscreen.Value = false;
  463. Hid.EnableKeyboard.Value = false;
  464. Hid.Hotkeys.Value = new KeyboardHotkeys
  465. {
  466. ToggleVsync = Key.Tab
  467. };
  468. Hid.InputConfig.Value = new List<InputConfig>
  469. {
  470. new KeyboardConfig
  471. {
  472. Index = 0,
  473. ControllerType = ControllerType.JoyconPair,
  474. PlayerIndex = PlayerIndex.Player1,
  475. LeftJoycon = new NpadKeyboardLeft
  476. {
  477. StickUp = Key.W,
  478. StickDown = Key.S,
  479. StickLeft = Key.A,
  480. StickRight = Key.D,
  481. StickButton = Key.F,
  482. DPadUp = Key.Up,
  483. DPadDown = Key.Down,
  484. DPadLeft = Key.Left,
  485. DPadRight = Key.Right,
  486. ButtonMinus = Key.Minus,
  487. ButtonL = Key.E,
  488. ButtonZl = Key.Q,
  489. ButtonSl = Key.Home,
  490. ButtonSr = Key.End
  491. },
  492. RightJoycon = new NpadKeyboardRight
  493. {
  494. StickUp = Key.I,
  495. StickDown = Key.K,
  496. StickLeft = Key.J,
  497. StickRight = Key.L,
  498. StickButton = Key.H,
  499. ButtonA = Key.Z,
  500. ButtonB = Key.X,
  501. ButtonX = Key.C,
  502. ButtonY = Key.V,
  503. ButtonPlus = Key.Plus,
  504. ButtonR = Key.U,
  505. ButtonZr = Key.O,
  506. ButtonSl = Key.PageUp,
  507. ButtonSr = Key.PageDown
  508. },
  509. EnableMotion = false,
  510. MirrorInput = false,
  511. Slot = 0,
  512. AltSlot = 0,
  513. Sensitivity = 100,
  514. GyroDeadzone = 1,
  515. DsuServerHost = "127.0.0.1",
  516. DsuServerPort = 26760
  517. }
  518. };
  519. }
  520. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  521. {
  522. bool configurationFileUpdated = false;
  523. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  524. {
  525. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  526. LoadDefault();
  527. return;
  528. }
  529. if (configurationFileFormat.Version < 2)
  530. {
  531. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  532. configurationFileFormat.SystemRegion = Region.USA;
  533. configurationFileUpdated = true;
  534. }
  535. if (configurationFileFormat.Version < 3)
  536. {
  537. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  538. configurationFileFormat.SystemTimeZone = "UTC";
  539. configurationFileUpdated = true;
  540. }
  541. if (configurationFileFormat.Version < 4)
  542. {
  543. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  544. configurationFileFormat.MaxAnisotropy = -1;
  545. configurationFileUpdated = true;
  546. }
  547. if (configurationFileFormat.Version < 5)
  548. {
  549. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  550. configurationFileFormat.SystemTimeOffset = 0;
  551. configurationFileUpdated = true;
  552. }
  553. if (configurationFileFormat.Version < 6)
  554. {
  555. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6.");
  556. configurationFileFormat.ControllerConfig = new List<ControllerConfig>();
  557. configurationFileFormat.KeyboardConfig = new List<KeyboardConfig>
  558. {
  559. new KeyboardConfig
  560. {
  561. Index = 0,
  562. ControllerType = ControllerType.JoyconPair,
  563. PlayerIndex = PlayerIndex.Player1,
  564. LeftJoycon = new NpadKeyboardLeft
  565. {
  566. StickUp = Key.W,
  567. StickDown = Key.S,
  568. StickLeft = Key.A,
  569. StickRight = Key.D,
  570. StickButton = Key.F,
  571. DPadUp = Key.Up,
  572. DPadDown = Key.Down,
  573. DPadLeft = Key.Left,
  574. DPadRight = Key.Right,
  575. ButtonMinus = Key.Minus,
  576. ButtonL = Key.E,
  577. ButtonZl = Key.Q,
  578. ButtonSl = Key.Unbound,
  579. ButtonSr = Key.Unbound
  580. },
  581. RightJoycon = new NpadKeyboardRight
  582. {
  583. StickUp = Key.I,
  584. StickDown = Key.K,
  585. StickLeft = Key.J,
  586. StickRight = Key.L,
  587. StickButton = Key.H,
  588. ButtonA = Key.Z,
  589. ButtonB = Key.X,
  590. ButtonX = Key.C,
  591. ButtonY = Key.V,
  592. ButtonPlus = Key.Plus,
  593. ButtonR = Key.U,
  594. ButtonZr = Key.O,
  595. ButtonSl = Key.Unbound,
  596. ButtonSr = Key.Unbound
  597. },
  598. EnableMotion = false,
  599. MirrorInput = false,
  600. Slot = 0,
  601. AltSlot = 0,
  602. Sensitivity = 100,
  603. GyroDeadzone = 1,
  604. DsuServerHost = "127.0.0.1",
  605. DsuServerPort = 26760
  606. }
  607. };
  608. configurationFileUpdated = true;
  609. }
  610. // Only needed for version 6 configurations.
  611. if (configurationFileFormat.Version == 6)
  612. {
  613. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7.");
  614. for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++)
  615. {
  616. if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex)
  617. {
  618. configurationFileFormat.KeyboardConfig[i].Index++;
  619. }
  620. }
  621. }
  622. if (configurationFileFormat.Version < 8)
  623. {
  624. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  625. configurationFileFormat.EnablePtc = true;
  626. configurationFileUpdated = true;
  627. }
  628. if (configurationFileFormat.Version < 9)
  629. {
  630. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  631. configurationFileFormat.ColumnSort = new ColumnSort
  632. {
  633. SortColumnId = 0,
  634. SortAscending = false
  635. };
  636. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  637. {
  638. ToggleVsync = Key.Tab
  639. };
  640. configurationFileUpdated = true;
  641. }
  642. if (configurationFileFormat.Version < 10)
  643. {
  644. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  645. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  646. configurationFileUpdated = true;
  647. }
  648. if (configurationFileFormat.Version < 11)
  649. {
  650. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  651. configurationFileFormat.ResScale = 1;
  652. configurationFileFormat.ResScaleCustom = 1.0f;
  653. configurationFileUpdated = true;
  654. }
  655. if (configurationFileFormat.Version < 12)
  656. {
  657. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  658. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  659. configurationFileUpdated = true;
  660. }
  661. if (configurationFileFormat.Version < 14)
  662. {
  663. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  664. configurationFileFormat.CheckUpdatesOnStart = true;
  665. configurationFileUpdated = true;
  666. }
  667. if (configurationFileFormat.Version < 16)
  668. {
  669. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  670. configurationFileFormat.EnableShaderCache = true;
  671. configurationFileUpdated = true;
  672. }
  673. if (configurationFileFormat.Version < 17)
  674. {
  675. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  676. configurationFileFormat.StartFullscreen = false;
  677. configurationFileUpdated = true;
  678. }
  679. if (configurationFileFormat.Version < 18)
  680. {
  681. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  682. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  683. configurationFileUpdated = true;
  684. }
  685. if (configurationFileFormat.Version < 20)
  686. {
  687. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  688. configurationFileFormat.ShowConfirmExit = true;
  689. configurationFileUpdated = true;
  690. }
  691. if (configurationFileFormat.Version < 22)
  692. {
  693. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  694. configurationFileFormat.HideCursorOnIdle = false;
  695. configurationFileUpdated = true;
  696. }
  697. List<InputConfig> inputConfig = new List<InputConfig>();
  698. inputConfig.AddRange(configurationFileFormat.ControllerConfig);
  699. inputConfig.AddRange(configurationFileFormat.KeyboardConfig);
  700. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  701. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  702. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  703. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  704. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  705. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  706. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  707. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  708. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  709. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  710. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  711. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  712. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  713. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  714. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  715. System.Language.Value = configurationFileFormat.SystemLanguage;
  716. System.Region.Value = configurationFileFormat.SystemRegion;
  717. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  718. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  719. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  720. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  721. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  722. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  723. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  724. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  725. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  726. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  727. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  728. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  729. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  730. System.ExpandRam.Value = configurationFileFormat.ExpandRam;
  731. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  732. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  733. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  734. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  735. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  736. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  737. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  738. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  739. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  740. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  741. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  742. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  743. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  744. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  745. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  746. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  747. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  748. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  749. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  750. Hid.InputConfig.Value = inputConfig;
  751. if (configurationFileUpdated)
  752. {
  753. ToFileFormat().SaveConfig(configurationFilePath);
  754. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  755. }
  756. }
  757. public static void Initialize()
  758. {
  759. if (Instance != null)
  760. {
  761. throw new InvalidOperationException("Configuration is already initialized");
  762. }
  763. Instance = new ConfigurationState();
  764. }
  765. }
  766. }