ConfigurationState.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Configuration;
  3. using Ryujinx.Common.Configuration.Hid;
  4. using Ryujinx.Common.Configuration.Hid.Controller;
  5. using Ryujinx.Common.Configuration.Hid.Keyboard;
  6. using Ryujinx.Common.Logging;
  7. using Ryujinx.Configuration.System;
  8. using Ryujinx.Configuration.Ui;
  9. using System;
  10. using System.Collections.Generic;
  11. namespace Ryujinx.Configuration
  12. {
  13. public class ConfigurationState
  14. {
  15. /// <summary>
  16. /// UI configuration section
  17. /// </summary>
  18. public class UiSection
  19. {
  20. public class Columns
  21. {
  22. public ReactiveObject<bool> FavColumn { get; private set; }
  23. public ReactiveObject<bool> IconColumn { get; private set; }
  24. public ReactiveObject<bool> AppColumn { get; private set; }
  25. public ReactiveObject<bool> DevColumn { get; private set; }
  26. public ReactiveObject<bool> VersionColumn { get; private set; }
  27. public ReactiveObject<bool> TimePlayedColumn { get; private set; }
  28. public ReactiveObject<bool> LastPlayedColumn { get; private set; }
  29. public ReactiveObject<bool> FileExtColumn { get; private set; }
  30. public ReactiveObject<bool> FileSizeColumn { get; private set; }
  31. public ReactiveObject<bool> PathColumn { get; private set; }
  32. public Columns()
  33. {
  34. FavColumn = new ReactiveObject<bool>();
  35. IconColumn = new ReactiveObject<bool>();
  36. AppColumn = new ReactiveObject<bool>();
  37. DevColumn = new ReactiveObject<bool>();
  38. VersionColumn = new ReactiveObject<bool>();
  39. TimePlayedColumn = new ReactiveObject<bool>();
  40. LastPlayedColumn = new ReactiveObject<bool>();
  41. FileExtColumn = new ReactiveObject<bool>();
  42. FileSizeColumn = new ReactiveObject<bool>();
  43. PathColumn = new ReactiveObject<bool>();
  44. }
  45. }
  46. public class ColumnSortSettings
  47. {
  48. public ReactiveObject<int> SortColumnId { get; private set; }
  49. public ReactiveObject<bool> SortAscending { get; private set; }
  50. public ColumnSortSettings()
  51. {
  52. SortColumnId = new ReactiveObject<int>();
  53. SortAscending = new ReactiveObject<bool>();
  54. }
  55. }
  56. /// <summary>
  57. /// Used to toggle columns in the GUI
  58. /// </summary>
  59. public Columns GuiColumns { get; private set; }
  60. /// <summary>
  61. /// Used to configure column sort settings in the GUI
  62. /// </summary>
  63. public ColumnSortSettings ColumnSort { get; private set; }
  64. /// <summary>
  65. /// A list of directories containing games to be used to load games into the games list
  66. /// </summary>
  67. public ReactiveObject<List<string>> GameDirs { get; private set; }
  68. /// <summary>
  69. /// Enable or disable custom themes in the GUI
  70. /// </summary>
  71. public ReactiveObject<bool> EnableCustomTheme { get; private set; }
  72. /// <summary>
  73. /// Path to custom GUI theme
  74. /// </summary>
  75. public ReactiveObject<string> CustomThemePath { get; private set; }
  76. /// <summary>
  77. /// Start games in fullscreen mode
  78. /// </summary>
  79. public ReactiveObject<bool> StartFullscreen { get; private set; }
  80. public UiSection()
  81. {
  82. GuiColumns = new Columns();
  83. ColumnSort = new ColumnSortSettings();
  84. GameDirs = new ReactiveObject<List<string>>();
  85. EnableCustomTheme = new ReactiveObject<bool>();
  86. CustomThemePath = new ReactiveObject<string>();
  87. StartFullscreen = new ReactiveObject<bool>();
  88. }
  89. }
  90. /// <summary>
  91. /// Logger configuration section
  92. /// </summary>
  93. public class LoggerSection
  94. {
  95. /// <summary>
  96. /// Enables printing debug log messages
  97. /// </summary>
  98. public ReactiveObject<bool> EnableDebug { get; private set; }
  99. /// <summary>
  100. /// Enables printing stub log messages
  101. /// </summary>
  102. public ReactiveObject<bool> EnableStub { get; private set; }
  103. /// <summary>
  104. /// Enables printing info log messages
  105. /// </summary>
  106. public ReactiveObject<bool> EnableInfo { get; private set; }
  107. /// <summary>
  108. /// Enables printing warning log messages
  109. /// </summary>
  110. public ReactiveObject<bool> EnableWarn { get; private set; }
  111. /// <summary>
  112. /// Enables printing error log messages
  113. /// </summary>
  114. public ReactiveObject<bool> EnableError { get; private set; }
  115. /// <summary>
  116. /// Enables printing guest log messages
  117. /// </summary>
  118. public ReactiveObject<bool> EnableGuest { get; private set; }
  119. /// <summary>
  120. /// Enables printing FS access log messages
  121. /// </summary>
  122. public ReactiveObject<bool> EnableFsAccessLog { get; private set; }
  123. /// <summary>
  124. /// Controls which log messages are written to the log targets
  125. /// </summary>
  126. public ReactiveObject<LogClass[]> FilteredClasses { get; private set; }
  127. /// <summary>
  128. /// Enables or disables logging to a file on disk
  129. /// </summary>
  130. public ReactiveObject<bool> EnableFileLog { get; private set; }
  131. /// <summary>
  132. /// Controls which OpenGL log messages are recorded in the log
  133. /// </summary>
  134. public ReactiveObject<GraphicsDebugLevel> GraphicsDebugLevel { get; private set; }
  135. public LoggerSection()
  136. {
  137. EnableDebug = new ReactiveObject<bool>();
  138. EnableStub = new ReactiveObject<bool>();
  139. EnableInfo = new ReactiveObject<bool>();
  140. EnableWarn = new ReactiveObject<bool>();
  141. EnableError = new ReactiveObject<bool>();
  142. EnableGuest = new ReactiveObject<bool>();
  143. EnableFsAccessLog = new ReactiveObject<bool>();
  144. FilteredClasses = new ReactiveObject<LogClass[]>();
  145. EnableFileLog = new ReactiveObject<bool>();
  146. EnableFileLog.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFileLog));
  147. GraphicsDebugLevel = new ReactiveObject<GraphicsDebugLevel>();
  148. }
  149. }
  150. /// <summary>
  151. /// System configuration section
  152. /// </summary>
  153. public class SystemSection
  154. {
  155. /// <summary>
  156. /// Change System Language
  157. /// </summary>
  158. public ReactiveObject<Language> Language { get; private set; }
  159. /// <summary>
  160. /// Change System Region
  161. /// </summary>
  162. public ReactiveObject<Region> Region { get; private set; }
  163. /// <summary>
  164. /// Change System TimeZone
  165. /// </summary>
  166. public ReactiveObject<string> TimeZone { get; private set; }
  167. /// <summary>
  168. /// System Time Offset in Seconds
  169. /// </summary>
  170. public ReactiveObject<long> SystemTimeOffset { get; private set; }
  171. /// <summary>
  172. /// Enables or disables Docked Mode
  173. /// </summary>
  174. public ReactiveObject<bool> EnableDockedMode { get; private set; }
  175. /// <summary>
  176. /// Enables or disables profiled translation cache persistency
  177. /// </summary>
  178. public ReactiveObject<bool> EnablePtc { get; private set; }
  179. /// <summary>
  180. /// Enables integrity checks on Game content files
  181. /// </summary>
  182. public ReactiveObject<bool> EnableFsIntegrityChecks { get; private set; }
  183. /// <summary>
  184. /// Enables FS access log output to the console. Possible modes are 0-3
  185. /// </summary>
  186. public ReactiveObject<int> FsGlobalAccessLogMode { get; private set; }
  187. /// <summary>
  188. /// The selected audio backend
  189. /// </summary>
  190. public ReactiveObject<AudioBackend> AudioBackend { get; private set; }
  191. /// <summary>
  192. /// The selected memory manager mode
  193. /// </summary>
  194. public ReactiveObject<MemoryManagerMode> MemoryManagerMode { get; private set; }
  195. /// <summary>
  196. /// Defines the amount of RAM available on the emulated system, and how it is distributed
  197. /// </summary>
  198. public ReactiveObject<bool> ExpandRam { get; private set; }
  199. /// <summary>
  200. /// Enable or disable ignoring missing services
  201. /// </summary>
  202. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  203. public SystemSection()
  204. {
  205. Language = new ReactiveObject<Language>();
  206. Region = new ReactiveObject<Region>();
  207. TimeZone = new ReactiveObject<string>();
  208. SystemTimeOffset = new ReactiveObject<long>();
  209. EnableDockedMode = new ReactiveObject<bool>();
  210. EnableDockedMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableDockedMode));
  211. EnablePtc = new ReactiveObject<bool>();
  212. EnablePtc.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnablePtc));
  213. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  214. EnableFsIntegrityChecks.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFsIntegrityChecks));
  215. FsGlobalAccessLogMode = new ReactiveObject<int>();
  216. FsGlobalAccessLogMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(FsGlobalAccessLogMode));
  217. AudioBackend = new ReactiveObject<AudioBackend>();
  218. AudioBackend.Event += static (sender, e) => LogValueChange(sender, e, nameof(AudioBackend));
  219. MemoryManagerMode = new ReactiveObject<MemoryManagerMode>();
  220. MemoryManagerMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(MemoryManagerMode));
  221. ExpandRam = new ReactiveObject<bool>();
  222. ExpandRam.Event += static (sender, e) => LogValueChange(sender, e, nameof(ExpandRam));
  223. IgnoreMissingServices = new ReactiveObject<bool>();
  224. IgnoreMissingServices.Event += static (sender, e) => LogValueChange(sender, e, nameof(IgnoreMissingServices));
  225. }
  226. }
  227. /// <summary>
  228. /// Hid configuration section
  229. /// </summary>
  230. public class HidSection
  231. {
  232. /// <summary>
  233. /// Enable or disable keyboard support (Independent from controllers binding)
  234. /// </summary>
  235. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  236. /// <summary>
  237. /// Enable or disable mouse support (Independent from controllers binding)
  238. /// </summary>
  239. public ReactiveObject<bool> EnableMouse { get; private set; }
  240. /// <summary>
  241. /// Hotkey Keyboard Bindings
  242. /// </summary>
  243. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  244. /// <summary>
  245. /// Input device configuration.
  246. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  247. /// TODO: Implement a ReactiveList class.
  248. /// </summary>
  249. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  250. public HidSection()
  251. {
  252. EnableKeyboard = new ReactiveObject<bool>();
  253. EnableMouse = new ReactiveObject<bool>();
  254. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  255. InputConfig = new ReactiveObject<List<InputConfig>>();
  256. }
  257. }
  258. /// <summary>
  259. /// Graphics configuration section
  260. /// </summary>
  261. public class GraphicsSection
  262. {
  263. /// <summary>
  264. /// Whether or not backend threading is enabled. The "Auto" setting will determine whether threading should be enabled at runtime.
  265. /// </summary>
  266. public ReactiveObject<BackendThreading> BackendThreading { get; private set; }
  267. /// <summary>
  268. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  269. /// </summary>
  270. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  271. /// <summary>
  272. /// Aspect Ratio applied to the renderer window.
  273. /// </summary>
  274. public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
  275. /// <summary>
  276. /// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
  277. /// </summary>
  278. public ReactiveObject<int> ResScale { get; private set; }
  279. /// <summary>
  280. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
  281. /// </summary>
  282. public ReactiveObject<float> ResScaleCustom { get; private set; }
  283. /// <summary>
  284. /// Dumps shaders in this local directory
  285. /// </summary>
  286. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  287. /// <summary>
  288. /// Enables or disables Vertical Sync
  289. /// </summary>
  290. public ReactiveObject<bool> EnableVsync { get; private set; }
  291. /// <summary>
  292. /// Enables or disables Shader cache
  293. /// </summary>
  294. public ReactiveObject<bool> EnableShaderCache { get; private set; }
  295. public GraphicsSection()
  296. {
  297. BackendThreading = new ReactiveObject<BackendThreading>();
  298. BackendThreading.Event += static (sender, e) => LogValueChange(sender, e, nameof(BackendThreading));
  299. ResScale = new ReactiveObject<int>();
  300. ResScale.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScale));
  301. ResScaleCustom = new ReactiveObject<float>();
  302. ResScaleCustom.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScaleCustom));
  303. MaxAnisotropy = new ReactiveObject<float>();
  304. MaxAnisotropy.Event += static (sender, e) => LogValueChange(sender, e, nameof(MaxAnisotropy));
  305. AspectRatio = new ReactiveObject<AspectRatio>();
  306. AspectRatio.Event += static (sender, e) => LogValueChange(sender, e, nameof(AspectRatio));
  307. ShadersDumpPath = new ReactiveObject<string>();
  308. EnableVsync = new ReactiveObject<bool>();
  309. EnableVsync.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableVsync));
  310. EnableShaderCache = new ReactiveObject<bool>();
  311. EnableShaderCache.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableShaderCache));
  312. }
  313. }
  314. /// <summary>
  315. /// The default configuration instance
  316. /// </summary>
  317. public static ConfigurationState Instance { get; private set; }
  318. /// <summary>
  319. /// The Ui section
  320. /// </summary>
  321. public UiSection Ui { get; private set; }
  322. /// <summary>
  323. /// The Logger section
  324. /// </summary>
  325. public LoggerSection Logger { get; private set; }
  326. /// <summary>
  327. /// The System section
  328. /// </summary>
  329. public SystemSection System { get; private set; }
  330. /// <summary>
  331. /// The Graphics section
  332. /// </summary>
  333. public GraphicsSection Graphics { get; private set; }
  334. /// <summary>
  335. /// The Hid section
  336. /// </summary>
  337. public HidSection Hid { get; private set; }
  338. /// <summary>
  339. /// Enables or disables Discord Rich Presence
  340. /// </summary>
  341. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  342. /// <summary>
  343. /// Checks for updates when Ryujinx starts when enabled
  344. /// </summary>
  345. public ReactiveObject<bool> CheckUpdatesOnStart { get; private set; }
  346. /// <summary>
  347. /// Show "Confirm Exit" Dialog
  348. /// </summary>
  349. public ReactiveObject<bool> ShowConfirmExit { get; private set; }
  350. /// <summary>
  351. /// Hide Cursor on Idle
  352. /// </summary>
  353. public ReactiveObject<bool> HideCursorOnIdle { get; private set; }
  354. private ConfigurationState()
  355. {
  356. Ui = new UiSection();
  357. Logger = new LoggerSection();
  358. System = new SystemSection();
  359. Graphics = new GraphicsSection();
  360. Hid = new HidSection();
  361. EnableDiscordIntegration = new ReactiveObject<bool>();
  362. CheckUpdatesOnStart = new ReactiveObject<bool>();
  363. ShowConfirmExit = new ReactiveObject<bool>();
  364. HideCursorOnIdle = new ReactiveObject<bool>();
  365. }
  366. public ConfigurationFileFormat ToFileFormat()
  367. {
  368. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  369. {
  370. Version = ConfigurationFileFormat.CurrentVersion,
  371. EnableFileLog = Logger.EnableFileLog,
  372. BackendThreading = Graphics.BackendThreading,
  373. ResScale = Graphics.ResScale,
  374. ResScaleCustom = Graphics.ResScaleCustom,
  375. MaxAnisotropy = Graphics.MaxAnisotropy,
  376. AspectRatio = Graphics.AspectRatio,
  377. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  378. LoggingEnableDebug = Logger.EnableDebug,
  379. LoggingEnableStub = Logger.EnableStub,
  380. LoggingEnableInfo = Logger.EnableInfo,
  381. LoggingEnableWarn = Logger.EnableWarn,
  382. LoggingEnableError = Logger.EnableError,
  383. LoggingEnableGuest = Logger.EnableGuest,
  384. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  385. LoggingFilteredClasses = Logger.FilteredClasses,
  386. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  387. SystemLanguage = System.Language,
  388. SystemRegion = System.Region,
  389. SystemTimeZone = System.TimeZone,
  390. SystemTimeOffset = System.SystemTimeOffset,
  391. DockedMode = System.EnableDockedMode,
  392. EnableDiscordIntegration = EnableDiscordIntegration,
  393. CheckUpdatesOnStart = CheckUpdatesOnStart,
  394. ShowConfirmExit = ShowConfirmExit,
  395. HideCursorOnIdle = HideCursorOnIdle,
  396. EnableVsync = Graphics.EnableVsync,
  397. EnableShaderCache = Graphics.EnableShaderCache,
  398. EnablePtc = System.EnablePtc,
  399. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  400. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  401. AudioBackend = System.AudioBackend,
  402. MemoryManagerMode = System.MemoryManagerMode,
  403. ExpandRam = System.ExpandRam,
  404. IgnoreMissingServices = System.IgnoreMissingServices,
  405. GuiColumns = new GuiColumns
  406. {
  407. FavColumn = Ui.GuiColumns.FavColumn,
  408. IconColumn = Ui.GuiColumns.IconColumn,
  409. AppColumn = Ui.GuiColumns.AppColumn,
  410. DevColumn = Ui.GuiColumns.DevColumn,
  411. VersionColumn = Ui.GuiColumns.VersionColumn,
  412. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  413. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  414. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  415. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  416. PathColumn = Ui.GuiColumns.PathColumn,
  417. },
  418. ColumnSort = new ColumnSort
  419. {
  420. SortColumnId = Ui.ColumnSort.SortColumnId,
  421. SortAscending = Ui.ColumnSort.SortAscending
  422. },
  423. GameDirs = Ui.GameDirs,
  424. EnableCustomTheme = Ui.EnableCustomTheme,
  425. CustomThemePath = Ui.CustomThemePath,
  426. StartFullscreen = Ui.StartFullscreen,
  427. EnableKeyboard = Hid.EnableKeyboard,
  428. EnableMouse = Hid.EnableMouse,
  429. Hotkeys = Hid.Hotkeys,
  430. KeyboardConfig = new List<object>(),
  431. ControllerConfig = new List<object>(),
  432. InputConfig = Hid.InputConfig,
  433. };
  434. return configurationFile;
  435. }
  436. public void LoadDefault()
  437. {
  438. Logger.EnableFileLog.Value = true;
  439. Graphics.BackendThreading.Value = BackendThreading.Auto;
  440. Graphics.ResScale.Value = 1;
  441. Graphics.ResScaleCustom.Value = 1.0f;
  442. Graphics.MaxAnisotropy.Value = -1.0f;
  443. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  444. Graphics.ShadersDumpPath.Value = "";
  445. Logger.EnableDebug.Value = false;
  446. Logger.EnableStub.Value = true;
  447. Logger.EnableInfo.Value = true;
  448. Logger.EnableWarn.Value = true;
  449. Logger.EnableError.Value = true;
  450. Logger.EnableGuest.Value = true;
  451. Logger.EnableFsAccessLog.Value = false;
  452. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  453. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  454. System.Language.Value = Language.AmericanEnglish;
  455. System.Region.Value = Region.USA;
  456. System.TimeZone.Value = "UTC";
  457. System.SystemTimeOffset.Value = 0;
  458. System.EnableDockedMode.Value = true;
  459. EnableDiscordIntegration.Value = true;
  460. CheckUpdatesOnStart.Value = true;
  461. ShowConfirmExit.Value = true;
  462. HideCursorOnIdle.Value = false;
  463. Graphics.EnableVsync.Value = true;
  464. Graphics.EnableShaderCache.Value = true;
  465. System.EnablePtc.Value = true;
  466. System.EnableFsIntegrityChecks.Value = true;
  467. System.FsGlobalAccessLogMode.Value = 0;
  468. System.AudioBackend.Value = AudioBackend.SDL2;
  469. System.MemoryManagerMode.Value = MemoryManagerMode.HostMappedUnsafe;
  470. System.ExpandRam.Value = false;
  471. System.IgnoreMissingServices.Value = false;
  472. Ui.GuiColumns.FavColumn.Value = true;
  473. Ui.GuiColumns.IconColumn.Value = true;
  474. Ui.GuiColumns.AppColumn.Value = true;
  475. Ui.GuiColumns.DevColumn.Value = true;
  476. Ui.GuiColumns.VersionColumn.Value = true;
  477. Ui.GuiColumns.TimePlayedColumn.Value = true;
  478. Ui.GuiColumns.LastPlayedColumn.Value = true;
  479. Ui.GuiColumns.FileExtColumn.Value = true;
  480. Ui.GuiColumns.FileSizeColumn.Value = true;
  481. Ui.GuiColumns.PathColumn.Value = true;
  482. Ui.ColumnSort.SortColumnId.Value = 0;
  483. Ui.ColumnSort.SortAscending.Value = false;
  484. Ui.GameDirs.Value = new List<string>();
  485. Ui.EnableCustomTheme.Value = false;
  486. Ui.CustomThemePath.Value = "";
  487. Ui.StartFullscreen.Value = false;
  488. Hid.EnableKeyboard.Value = false;
  489. Hid.EnableMouse.Value = false;
  490. Hid.Hotkeys.Value = new KeyboardHotkeys
  491. {
  492. ToggleVsync = Key.Tab,
  493. Screenshot = Key.F8,
  494. ShowUi = Key.F4
  495. };
  496. Hid.InputConfig.Value = new List<InputConfig>
  497. {
  498. new StandardKeyboardInputConfig
  499. {
  500. Version = InputConfig.CurrentVersion,
  501. Backend = InputBackendType.WindowKeyboard,
  502. Id = "0",
  503. PlayerIndex = PlayerIndex.Player1,
  504. ControllerType = ControllerType.JoyconPair,
  505. LeftJoycon = new LeftJoyconCommonConfig<Key>
  506. {
  507. DpadUp = Key.Up,
  508. DpadDown = Key.Down,
  509. DpadLeft = Key.Left,
  510. DpadRight = Key.Right,
  511. ButtonMinus = Key.Minus,
  512. ButtonL = Key.E,
  513. ButtonZl = Key.Q,
  514. ButtonSl = Key.Unbound,
  515. ButtonSr = Key.Unbound
  516. },
  517. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  518. {
  519. StickUp = Key.W,
  520. StickDown = Key.S,
  521. StickLeft = Key.A,
  522. StickRight = Key.D,
  523. StickButton = Key.F,
  524. },
  525. RightJoycon = new RightJoyconCommonConfig<Key>
  526. {
  527. ButtonA = Key.Z,
  528. ButtonB = Key.X,
  529. ButtonX = Key.C,
  530. ButtonY = Key.V,
  531. ButtonPlus = Key.Plus,
  532. ButtonR = Key.U,
  533. ButtonZr = Key.O,
  534. ButtonSl = Key.Unbound,
  535. ButtonSr = Key.Unbound
  536. },
  537. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  538. {
  539. StickUp = Key.I,
  540. StickDown = Key.K,
  541. StickLeft = Key.J,
  542. StickRight = Key.L,
  543. StickButton = Key.H,
  544. }
  545. }
  546. };
  547. }
  548. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  549. {
  550. bool configurationFileUpdated = false;
  551. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  552. {
  553. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  554. LoadDefault();
  555. return;
  556. }
  557. if (configurationFileFormat.Version < 2)
  558. {
  559. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  560. configurationFileFormat.SystemRegion = Region.USA;
  561. configurationFileUpdated = true;
  562. }
  563. if (configurationFileFormat.Version < 3)
  564. {
  565. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  566. configurationFileFormat.SystemTimeZone = "UTC";
  567. configurationFileUpdated = true;
  568. }
  569. if (configurationFileFormat.Version < 4)
  570. {
  571. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  572. configurationFileFormat.MaxAnisotropy = -1;
  573. configurationFileUpdated = true;
  574. }
  575. if (configurationFileFormat.Version < 5)
  576. {
  577. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  578. configurationFileFormat.SystemTimeOffset = 0;
  579. configurationFileUpdated = true;
  580. }
  581. if (configurationFileFormat.Version < 8)
  582. {
  583. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  584. configurationFileFormat.EnablePtc = true;
  585. configurationFileUpdated = true;
  586. }
  587. if (configurationFileFormat.Version < 9)
  588. {
  589. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  590. configurationFileFormat.ColumnSort = new ColumnSort
  591. {
  592. SortColumnId = 0,
  593. SortAscending = false
  594. };
  595. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  596. {
  597. ToggleVsync = Key.Tab
  598. };
  599. configurationFileUpdated = true;
  600. }
  601. if (configurationFileFormat.Version < 10)
  602. {
  603. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  604. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  605. configurationFileUpdated = true;
  606. }
  607. if (configurationFileFormat.Version < 11)
  608. {
  609. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  610. configurationFileFormat.ResScale = 1;
  611. configurationFileFormat.ResScaleCustom = 1.0f;
  612. configurationFileUpdated = true;
  613. }
  614. if (configurationFileFormat.Version < 12)
  615. {
  616. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  617. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  618. configurationFileUpdated = true;
  619. }
  620. if (configurationFileFormat.Version < 14)
  621. {
  622. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  623. configurationFileFormat.CheckUpdatesOnStart = true;
  624. configurationFileUpdated = true;
  625. }
  626. if (configurationFileFormat.Version < 16)
  627. {
  628. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  629. configurationFileFormat.EnableShaderCache = true;
  630. configurationFileUpdated = true;
  631. }
  632. if (configurationFileFormat.Version < 17)
  633. {
  634. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  635. configurationFileFormat.StartFullscreen = false;
  636. configurationFileUpdated = true;
  637. }
  638. if (configurationFileFormat.Version < 18)
  639. {
  640. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  641. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  642. configurationFileUpdated = true;
  643. }
  644. if (configurationFileFormat.Version < 20)
  645. {
  646. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  647. configurationFileFormat.ShowConfirmExit = true;
  648. configurationFileUpdated = true;
  649. }
  650. if (configurationFileFormat.Version < 22)
  651. {
  652. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  653. configurationFileFormat.HideCursorOnIdle = false;
  654. configurationFileUpdated = true;
  655. }
  656. if (configurationFileFormat.Version < 24)
  657. {
  658. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24.");
  659. configurationFileFormat.InputConfig = new List<InputConfig>
  660. {
  661. new StandardKeyboardInputConfig
  662. {
  663. Version = InputConfig.CurrentVersion,
  664. Backend = InputBackendType.WindowKeyboard,
  665. Id = "0",
  666. PlayerIndex = PlayerIndex.Player1,
  667. ControllerType = ControllerType.JoyconPair,
  668. LeftJoycon = new LeftJoyconCommonConfig<Key>
  669. {
  670. DpadUp = Key.Up,
  671. DpadDown = Key.Down,
  672. DpadLeft = Key.Left,
  673. DpadRight = Key.Right,
  674. ButtonMinus = Key.Minus,
  675. ButtonL = Key.E,
  676. ButtonZl = Key.Q,
  677. ButtonSl = Key.Unbound,
  678. ButtonSr = Key.Unbound
  679. },
  680. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  681. {
  682. StickUp = Key.W,
  683. StickDown = Key.S,
  684. StickLeft = Key.A,
  685. StickRight = Key.D,
  686. StickButton = Key.F,
  687. },
  688. RightJoycon = new RightJoyconCommonConfig<Key>
  689. {
  690. ButtonA = Key.Z,
  691. ButtonB = Key.X,
  692. ButtonX = Key.C,
  693. ButtonY = Key.V,
  694. ButtonPlus = Key.Plus,
  695. ButtonR = Key.U,
  696. ButtonZr = Key.O,
  697. ButtonSl = Key.Unbound,
  698. ButtonSr = Key.Unbound
  699. },
  700. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  701. {
  702. StickUp = Key.I,
  703. StickDown = Key.K,
  704. StickLeft = Key.J,
  705. StickRight = Key.L,
  706. StickButton = Key.H,
  707. }
  708. }
  709. };
  710. configurationFileUpdated = true;
  711. }
  712. if (configurationFileFormat.Version < 25)
  713. {
  714. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 25.");
  715. configurationFileUpdated = true;
  716. }
  717. if (configurationFileFormat.Version < 26)
  718. {
  719. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 26.");
  720. configurationFileFormat.MemoryManagerMode = MemoryManagerMode.HostMappedUnsafe;
  721. configurationFileUpdated = true;
  722. }
  723. if (configurationFileFormat.Version < 27)
  724. {
  725. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 27.");
  726. configurationFileFormat.EnableMouse = false;
  727. configurationFileUpdated = true;
  728. }
  729. if (configurationFileFormat.Version < 28)
  730. {
  731. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 28.");
  732. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  733. {
  734. ToggleVsync = Key.Tab,
  735. Screenshot = Key.F8
  736. };
  737. configurationFileUpdated = true;
  738. }
  739. if (configurationFileFormat.Version < 29)
  740. {
  741. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 29.");
  742. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  743. {
  744. ToggleVsync = Key.Tab,
  745. Screenshot = Key.F8,
  746. ShowUi = Key.F4
  747. };
  748. configurationFileUpdated = true;
  749. }
  750. if (configurationFileFormat.Version < 30)
  751. {
  752. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 30.");
  753. foreach (InputConfig config in configurationFileFormat.InputConfig)
  754. {
  755. if (config is StandardControllerInputConfig controllerConfig)
  756. {
  757. controllerConfig.Rumble = new RumbleConfigController
  758. {
  759. EnableRumble = false,
  760. StrongRumble = 1f,
  761. WeakRumble = 1f
  762. };
  763. }
  764. }
  765. configurationFileUpdated = true;
  766. }
  767. if (configurationFileFormat.Version < 31)
  768. {
  769. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 31.");
  770. configurationFileFormat.BackendThreading = BackendThreading.Auto;
  771. configurationFileUpdated = true;
  772. }
  773. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  774. Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading;
  775. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  776. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  777. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  778. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  779. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  780. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  781. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  782. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  783. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  784. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  785. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  786. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  787. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  788. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  789. System.Language.Value = configurationFileFormat.SystemLanguage;
  790. System.Region.Value = configurationFileFormat.SystemRegion;
  791. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  792. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  793. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  794. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  795. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  796. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  797. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  798. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  799. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  800. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  801. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  802. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  803. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  804. System.MemoryManagerMode.Value = configurationFileFormat.MemoryManagerMode;
  805. System.ExpandRam.Value = configurationFileFormat.ExpandRam;
  806. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  807. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  808. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  809. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  810. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  811. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  812. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  813. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  814. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  815. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  816. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  817. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  818. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  819. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  820. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  821. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  822. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  823. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  824. Hid.EnableMouse.Value = configurationFileFormat.EnableMouse;
  825. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  826. Hid.InputConfig.Value = configurationFileFormat.InputConfig;
  827. if (Hid.InputConfig.Value == null)
  828. {
  829. Hid.InputConfig.Value = new List<InputConfig>();
  830. }
  831. if (configurationFileUpdated)
  832. {
  833. ToFileFormat().SaveConfig(configurationFilePath);
  834. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  835. }
  836. }
  837. private static void LogValueChange<T>(object sender, ReactiveEventArgs<T> eventArgs, string valueName)
  838. {
  839. Common.Logging.Logger.Info?.Print(LogClass.Configuration, $"{valueName} set to: {eventArgs.NewValue}");
  840. }
  841. public static void Initialize()
  842. {
  843. if (Instance != null)
  844. {
  845. throw new InvalidOperationException("Configuration is already initialized");
  846. }
  847. Instance = new ConfigurationState();
  848. }
  849. }
  850. }