ConfigurationState.cs 49 KB

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