ConfigurationState.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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. Pause = Key.F5
  496. };
  497. Hid.InputConfig.Value = new List<InputConfig>
  498. {
  499. new StandardKeyboardInputConfig
  500. {
  501. Version = InputConfig.CurrentVersion,
  502. Backend = InputBackendType.WindowKeyboard,
  503. Id = "0",
  504. PlayerIndex = PlayerIndex.Player1,
  505. ControllerType = ControllerType.JoyconPair,
  506. LeftJoycon = new LeftJoyconCommonConfig<Key>
  507. {
  508. DpadUp = Key.Up,
  509. DpadDown = Key.Down,
  510. DpadLeft = Key.Left,
  511. DpadRight = Key.Right,
  512. ButtonMinus = Key.Minus,
  513. ButtonL = Key.E,
  514. ButtonZl = Key.Q,
  515. ButtonSl = Key.Unbound,
  516. ButtonSr = Key.Unbound
  517. },
  518. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  519. {
  520. StickUp = Key.W,
  521. StickDown = Key.S,
  522. StickLeft = Key.A,
  523. StickRight = Key.D,
  524. StickButton = Key.F,
  525. },
  526. RightJoycon = new RightJoyconCommonConfig<Key>
  527. {
  528. ButtonA = Key.Z,
  529. ButtonB = Key.X,
  530. ButtonX = Key.C,
  531. ButtonY = Key.V,
  532. ButtonPlus = Key.Plus,
  533. ButtonR = Key.U,
  534. ButtonZr = Key.O,
  535. ButtonSl = Key.Unbound,
  536. ButtonSr = Key.Unbound
  537. },
  538. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  539. {
  540. StickUp = Key.I,
  541. StickDown = Key.K,
  542. StickLeft = Key.J,
  543. StickRight = Key.L,
  544. StickButton = Key.H,
  545. }
  546. }
  547. };
  548. }
  549. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  550. {
  551. bool configurationFileUpdated = false;
  552. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  553. {
  554. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  555. LoadDefault();
  556. return;
  557. }
  558. if (configurationFileFormat.Version < 2)
  559. {
  560. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  561. configurationFileFormat.SystemRegion = Region.USA;
  562. configurationFileUpdated = true;
  563. }
  564. if (configurationFileFormat.Version < 3)
  565. {
  566. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  567. configurationFileFormat.SystemTimeZone = "UTC";
  568. configurationFileUpdated = true;
  569. }
  570. if (configurationFileFormat.Version < 4)
  571. {
  572. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  573. configurationFileFormat.MaxAnisotropy = -1;
  574. configurationFileUpdated = true;
  575. }
  576. if (configurationFileFormat.Version < 5)
  577. {
  578. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  579. configurationFileFormat.SystemTimeOffset = 0;
  580. configurationFileUpdated = true;
  581. }
  582. if (configurationFileFormat.Version < 8)
  583. {
  584. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  585. configurationFileFormat.EnablePtc = true;
  586. configurationFileUpdated = true;
  587. }
  588. if (configurationFileFormat.Version < 9)
  589. {
  590. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  591. configurationFileFormat.ColumnSort = new ColumnSort
  592. {
  593. SortColumnId = 0,
  594. SortAscending = false
  595. };
  596. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  597. {
  598. ToggleVsync = Key.Tab
  599. };
  600. configurationFileUpdated = true;
  601. }
  602. if (configurationFileFormat.Version < 10)
  603. {
  604. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  605. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  606. configurationFileUpdated = true;
  607. }
  608. if (configurationFileFormat.Version < 11)
  609. {
  610. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  611. configurationFileFormat.ResScale = 1;
  612. configurationFileFormat.ResScaleCustom = 1.0f;
  613. configurationFileUpdated = true;
  614. }
  615. if (configurationFileFormat.Version < 12)
  616. {
  617. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  618. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  619. configurationFileUpdated = true;
  620. }
  621. if (configurationFileFormat.Version < 14)
  622. {
  623. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  624. configurationFileFormat.CheckUpdatesOnStart = true;
  625. configurationFileUpdated = true;
  626. }
  627. if (configurationFileFormat.Version < 16)
  628. {
  629. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  630. configurationFileFormat.EnableShaderCache = true;
  631. configurationFileUpdated = true;
  632. }
  633. if (configurationFileFormat.Version < 17)
  634. {
  635. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  636. configurationFileFormat.StartFullscreen = false;
  637. configurationFileUpdated = true;
  638. }
  639. if (configurationFileFormat.Version < 18)
  640. {
  641. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  642. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  643. configurationFileUpdated = true;
  644. }
  645. if (configurationFileFormat.Version < 20)
  646. {
  647. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  648. configurationFileFormat.ShowConfirmExit = true;
  649. configurationFileUpdated = true;
  650. }
  651. if (configurationFileFormat.Version < 22)
  652. {
  653. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  654. configurationFileFormat.HideCursorOnIdle = false;
  655. configurationFileUpdated = true;
  656. }
  657. if (configurationFileFormat.Version < 24)
  658. {
  659. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24.");
  660. configurationFileFormat.InputConfig = new List<InputConfig>
  661. {
  662. new StandardKeyboardInputConfig
  663. {
  664. Version = InputConfig.CurrentVersion,
  665. Backend = InputBackendType.WindowKeyboard,
  666. Id = "0",
  667. PlayerIndex = PlayerIndex.Player1,
  668. ControllerType = ControllerType.JoyconPair,
  669. LeftJoycon = new LeftJoyconCommonConfig<Key>
  670. {
  671. DpadUp = Key.Up,
  672. DpadDown = Key.Down,
  673. DpadLeft = Key.Left,
  674. DpadRight = Key.Right,
  675. ButtonMinus = Key.Minus,
  676. ButtonL = Key.E,
  677. ButtonZl = Key.Q,
  678. ButtonSl = Key.Unbound,
  679. ButtonSr = Key.Unbound
  680. },
  681. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  682. {
  683. StickUp = Key.W,
  684. StickDown = Key.S,
  685. StickLeft = Key.A,
  686. StickRight = Key.D,
  687. StickButton = Key.F,
  688. },
  689. RightJoycon = new RightJoyconCommonConfig<Key>
  690. {
  691. ButtonA = Key.Z,
  692. ButtonB = Key.X,
  693. ButtonX = Key.C,
  694. ButtonY = Key.V,
  695. ButtonPlus = Key.Plus,
  696. ButtonR = Key.U,
  697. ButtonZr = Key.O,
  698. ButtonSl = Key.Unbound,
  699. ButtonSr = Key.Unbound
  700. },
  701. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  702. {
  703. StickUp = Key.I,
  704. StickDown = Key.K,
  705. StickLeft = Key.J,
  706. StickRight = Key.L,
  707. StickButton = Key.H,
  708. }
  709. }
  710. };
  711. configurationFileUpdated = true;
  712. }
  713. if (configurationFileFormat.Version < 25)
  714. {
  715. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 25.");
  716. configurationFileUpdated = true;
  717. }
  718. if (configurationFileFormat.Version < 26)
  719. {
  720. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 26.");
  721. configurationFileFormat.MemoryManagerMode = MemoryManagerMode.HostMappedUnsafe;
  722. configurationFileUpdated = true;
  723. }
  724. if (configurationFileFormat.Version < 27)
  725. {
  726. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 27.");
  727. configurationFileFormat.EnableMouse = false;
  728. configurationFileUpdated = true;
  729. }
  730. if (configurationFileFormat.Version < 28)
  731. {
  732. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 28.");
  733. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  734. {
  735. ToggleVsync = Key.Tab,
  736. Screenshot = Key.F8
  737. };
  738. configurationFileUpdated = true;
  739. }
  740. if (configurationFileFormat.Version < 29)
  741. {
  742. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 29.");
  743. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  744. {
  745. ToggleVsync = Key.Tab,
  746. Screenshot = Key.F8,
  747. ShowUi = Key.F4
  748. };
  749. configurationFileUpdated = true;
  750. }
  751. if (configurationFileFormat.Version < 30)
  752. {
  753. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 30.");
  754. foreach (InputConfig config in configurationFileFormat.InputConfig)
  755. {
  756. if (config is StandardControllerInputConfig controllerConfig)
  757. {
  758. controllerConfig.Rumble = new RumbleConfigController
  759. {
  760. EnableRumble = false,
  761. StrongRumble = 1f,
  762. WeakRumble = 1f
  763. };
  764. }
  765. }
  766. configurationFileUpdated = true;
  767. }
  768. if (configurationFileFormat.Version < 31)
  769. {
  770. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 31.");
  771. configurationFileFormat.BackendThreading = BackendThreading.Auto;
  772. configurationFileUpdated = true;
  773. }
  774. if (configurationFileFormat.Version < 32)
  775. {
  776. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 32.");
  777. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  778. {
  779. ToggleVsync = configurationFileFormat.Hotkeys.ToggleVsync,
  780. Screenshot = configurationFileFormat.Hotkeys.Screenshot,
  781. ShowUi = configurationFileFormat.Hotkeys.ShowUi,
  782. Pause = Key.F5
  783. };
  784. configurationFileUpdated = true;
  785. }
  786. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  787. Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading;
  788. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  789. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  790. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  791. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  792. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  793. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  794. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  795. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  796. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  797. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  798. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  799. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  800. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  801. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  802. System.Language.Value = configurationFileFormat.SystemLanguage;
  803. System.Region.Value = configurationFileFormat.SystemRegion;
  804. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  805. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  806. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  807. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  808. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  809. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  810. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  811. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  812. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  813. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  814. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  815. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  816. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  817. System.MemoryManagerMode.Value = configurationFileFormat.MemoryManagerMode;
  818. System.ExpandRam.Value = configurationFileFormat.ExpandRam;
  819. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  820. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  821. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  822. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  823. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  824. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  825. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  826. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  827. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  828. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  829. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  830. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  831. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  832. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  833. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  834. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  835. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  836. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  837. Hid.EnableMouse.Value = configurationFileFormat.EnableMouse;
  838. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  839. Hid.InputConfig.Value = configurationFileFormat.InputConfig;
  840. if (Hid.InputConfig.Value == null)
  841. {
  842. Hid.InputConfig.Value = new List<InputConfig>();
  843. }
  844. if (configurationFileUpdated)
  845. {
  846. ToFileFormat().SaveConfig(configurationFilePath);
  847. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  848. }
  849. }
  850. private static void LogValueChange<T>(object sender, ReactiveEventArgs<T> eventArgs, string valueName)
  851. {
  852. Common.Logging.Logger.Info?.Print(LogClass.Configuration, $"{valueName} set to: {eventArgs.NewValue}");
  853. }
  854. public static void Initialize()
  855. {
  856. if (Instance != null)
  857. {
  858. throw new InvalidOperationException("Configuration is already initialized");
  859. }
  860. Instance = new ConfigurationState();
  861. }
  862. }
  863. }