MainWindow.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. using ARMeilleure.Translation;
  2. using Gtk;
  3. using LibHac.Common;
  4. using LibHac.Common.Keys;
  5. using LibHac.Ncm;
  6. using LibHac.Ns;
  7. using LibHac.Tools.FsSystem;
  8. using LibHac.Tools.FsSystem.NcaUtils;
  9. using Ryujinx.Audio.Backends.Dummy;
  10. using Ryujinx.Audio.Backends.OpenAL;
  11. using Ryujinx.Audio.Backends.SDL2;
  12. using Ryujinx.Audio.Backends.SoundIo;
  13. using Ryujinx.Audio.Integration;
  14. using Ryujinx.Common;
  15. using Ryujinx.Common.Configuration;
  16. using Ryujinx.Common.Logging;
  17. using Ryujinx.Common.SystemInterop;
  18. using Ryujinx.Cpu;
  19. using Ryujinx.Graphics.GAL;
  20. using Ryujinx.Graphics.GAL.Multithreading;
  21. using Ryujinx.Graphics.OpenGL;
  22. using Ryujinx.Graphics.Vulkan;
  23. using Ryujinx.HLE.FileSystem;
  24. using Ryujinx.HLE.HOS;
  25. using Ryujinx.HLE.HOS.Services.Account.Acc;
  26. using Ryujinx.HLE.HOS.SystemState;
  27. using Ryujinx.Input.GTK3;
  28. using Ryujinx.Input.HLE;
  29. using Ryujinx.Input.SDL2;
  30. using Ryujinx.Modules;
  31. using Ryujinx.Ui.App.Common;
  32. using Ryujinx.Ui.Applet;
  33. using Ryujinx.Ui.Common;
  34. using Ryujinx.Ui.Common.Configuration;
  35. using Ryujinx.Ui.Common.Helper;
  36. using Ryujinx.Ui.Helper;
  37. using Ryujinx.Ui.Widgets;
  38. using Ryujinx.Ui.Windows;
  39. using Silk.NET.Vulkan;
  40. using SPB.Graphics.Vulkan;
  41. using System;
  42. using System.Diagnostics;
  43. using System.IO;
  44. using System.Reflection;
  45. using System.Threading;
  46. using System.Threading.Tasks;
  47. using GUI = Gtk.Builder.ObjectAttribute;
  48. using ShaderCacheLoadingState = Ryujinx.Graphics.Gpu.Shader.ShaderCacheState;
  49. namespace Ryujinx.Ui
  50. {
  51. public class MainWindow : Window
  52. {
  53. private readonly VirtualFileSystem _virtualFileSystem;
  54. private readonly ContentManager _contentManager;
  55. private readonly AccountManager _accountManager;
  56. private readonly LibHacHorizonManager _libHacHorizonManager;
  57. private UserChannelPersistence _userChannelPersistence;
  58. private HLE.Switch _emulationContext;
  59. private WindowsMultimediaTimerResolution _windowsMultimediaTimerResolution;
  60. private readonly ApplicationLibrary _applicationLibrary;
  61. private readonly GtkHostUiHandler _uiHandler;
  62. private readonly AutoResetEvent _deviceExitStatus;
  63. private readonly ListStore _tableStore;
  64. private bool _updatingGameTable;
  65. private bool _gameLoaded;
  66. private bool _ending;
  67. private string _currentEmulatedGamePath = null;
  68. private string _lastScannedAmiiboId = "";
  69. private bool _lastScannedAmiiboShowAll = false;
  70. public RendererWidgetBase RendererWidget;
  71. public InputManager InputManager;
  72. public bool IsFocused;
  73. #pragma warning disable CS0169, CS0649, IDE0044
  74. [GUI] public MenuItem ExitMenuItem;
  75. [GUI] public MenuItem UpdateMenuItem;
  76. [GUI] MenuBar _menuBar;
  77. [GUI] Box _footerBox;
  78. [GUI] Box _statusBar;
  79. [GUI] MenuItem _optionMenu;
  80. [GUI] MenuItem _manageUserProfiles;
  81. [GUI] MenuItem _fileMenu;
  82. [GUI] MenuItem _loadApplicationFile;
  83. [GUI] MenuItem _loadApplicationFolder;
  84. [GUI] MenuItem _appletMenu;
  85. [GUI] MenuItem _actionMenu;
  86. [GUI] MenuItem _pauseEmulation;
  87. [GUI] MenuItem _resumeEmulation;
  88. [GUI] MenuItem _stopEmulation;
  89. [GUI] MenuItem _simulateWakeUpMessage;
  90. [GUI] MenuItem _scanAmiibo;
  91. [GUI] MenuItem _takeScreenshot;
  92. [GUI] MenuItem _hideUi;
  93. [GUI] MenuItem _fullScreen;
  94. [GUI] CheckMenuItem _startFullScreen;
  95. [GUI] CheckMenuItem _showConsole;
  96. [GUI] CheckMenuItem _favToggle;
  97. [GUI] MenuItem _firmwareInstallDirectory;
  98. [GUI] MenuItem _firmwareInstallFile;
  99. [GUI] MenuItem _fileTypesSubMenu;
  100. [GUI] Label _fifoStatus;
  101. [GUI] CheckMenuItem _iconToggle;
  102. [GUI] CheckMenuItem _developerToggle;
  103. [GUI] CheckMenuItem _appToggle;
  104. [GUI] CheckMenuItem _timePlayedToggle;
  105. [GUI] CheckMenuItem _versionToggle;
  106. [GUI] CheckMenuItem _lastPlayedToggle;
  107. [GUI] CheckMenuItem _fileExtToggle;
  108. [GUI] CheckMenuItem _pathToggle;
  109. [GUI] CheckMenuItem _fileSizeToggle;
  110. [GUI] CheckMenuItem _nspShown;
  111. [GUI] CheckMenuItem _pfs0Shown;
  112. [GUI] CheckMenuItem _xciShown;
  113. [GUI] CheckMenuItem _ncaShown;
  114. [GUI] CheckMenuItem _nroShown;
  115. [GUI] CheckMenuItem _nsoShown;
  116. [GUI] Label _gpuBackend;
  117. [GUI] Label _dockedMode;
  118. [GUI] Label _aspectRatio;
  119. [GUI] Label _gameStatus;
  120. [GUI] TreeView _gameTable;
  121. [GUI] TreeSelection _gameTableSelection;
  122. [GUI] ScrolledWindow _gameTableWindow;
  123. [GUI] Label _gpuName;
  124. [GUI] Label _progressLabel;
  125. [GUI] Label _firmwareVersionLabel;
  126. [GUI] Gtk.ProgressBar _progressBar;
  127. [GUI] Box _viewBox;
  128. [GUI] Label _vSyncStatus;
  129. [GUI] Label _volumeStatus;
  130. [GUI] Box _listStatusBox;
  131. [GUI] Label _loadingStatusLabel;
  132. [GUI] Gtk.ProgressBar _loadingStatusBar;
  133. #pragma warning restore CS0649, IDE0044, CS0169
  134. public MainWindow() : this(new Builder("Ryujinx.Ui.MainWindow.glade")) { }
  135. private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("_mainWin"))
  136. {
  137. builder.Autoconnect(this);
  138. // Apply custom theme if needed.
  139. ThemeHelper.ApplyTheme();
  140. Gdk.Monitor monitor = Display.GetMonitor(0);
  141. // Sets overridden fields.
  142. int monitorWidth = monitor.Geometry.Width * monitor.ScaleFactor;
  143. int monitorHeight = monitor.Geometry.Height * monitor.ScaleFactor;
  144. DefaultWidth = monitorWidth < 1280 ? monitorWidth : 1280;
  145. DefaultHeight = monitorHeight < 760 ? monitorHeight : 760;
  146. Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
  147. Title = $"Ryujinx {Program.Version}";
  148. // Hide emulation context status bar.
  149. _statusBar.Hide();
  150. // Instantiate HLE objects.
  151. _virtualFileSystem = VirtualFileSystem.CreateInstance();
  152. _libHacHorizonManager = new LibHacHorizonManager();
  153. _libHacHorizonManager.InitializeFsServer(_virtualFileSystem);
  154. _libHacHorizonManager.InitializeArpServer();
  155. _libHacHorizonManager.InitializeBcatServer();
  156. _libHacHorizonManager.InitializeSystemClients();
  157. // Save data created before we supported extra data in directory save data will not work properly if
  158. // given empty extra data. Luckily some of that extra data can be created using the data from the
  159. // save data indexer, which should be enough to check access permissions for user saves.
  160. // Every single save data's extra data will be checked and fixed if needed each time the emulator is opened.
  161. // Consider removing this at some point in the future when we don't need to worry about old saves.
  162. VirtualFileSystem.FixExtraData(_libHacHorizonManager.RyujinxClient);
  163. _contentManager = new ContentManager(_virtualFileSystem);
  164. _accountManager = new AccountManager(_libHacHorizonManager.RyujinxClient, CommandLineState.Profile);
  165. _userChannelPersistence = new UserChannelPersistence();
  166. // Instantiate GUI objects.
  167. _applicationLibrary = new ApplicationLibrary(_virtualFileSystem);
  168. _uiHandler = new GtkHostUiHandler(this);
  169. _deviceExitStatus = new AutoResetEvent(false);
  170. WindowStateEvent += WindowStateEvent_Changed;
  171. DeleteEvent += Window_Close;
  172. FocusInEvent += MainWindow_FocusInEvent;
  173. FocusOutEvent += MainWindow_FocusOutEvent;
  174. _applicationLibrary.ApplicationAdded += Application_Added;
  175. _applicationLibrary.ApplicationCountUpdated += ApplicationCount_Updated;
  176. _fileMenu.StateChanged += FileMenu_StateChanged;
  177. _actionMenu.StateChanged += ActionMenu_StateChanged;
  178. _optionMenu.StateChanged += OptionMenu_StateChanged;
  179. _gameTable.ButtonReleaseEvent += Row_Clicked;
  180. _fullScreen.Activated += FullScreen_Toggled;
  181. RendererWidgetBase.StatusUpdatedEvent += Update_StatusBar;
  182. ConfigurationState.Instance.System.IgnoreMissingServices.Event += UpdateIgnoreMissingServicesState;
  183. ConfigurationState.Instance.Graphics.AspectRatio.Event += UpdateAspectRatioState;
  184. ConfigurationState.Instance.System.EnableDockedMode.Event += UpdateDockedModeState;
  185. ConfigurationState.Instance.System.AudioVolume.Event += UpdateAudioVolumeState;
  186. if (ConfigurationState.Instance.Ui.StartFullscreen)
  187. {
  188. _startFullScreen.Active = true;
  189. }
  190. _showConsole.Active = ConfigurationState.Instance.Ui.ShowConsole.Value;
  191. _showConsole.Visible = ConsoleHelper.SetConsoleWindowStateSupported;
  192. _actionMenu.Sensitive = false;
  193. _pauseEmulation.Sensitive = false;
  194. _resumeEmulation.Sensitive = false;
  195. _nspShown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value;
  196. _pfs0Shown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value;
  197. _xciShown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value;
  198. _ncaShown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value;
  199. _nroShown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value;
  200. _nsoShown.Active = ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value;
  201. _nspShown.Toggled += NSP_Shown_Toggled;
  202. _pfs0Shown.Toggled += PFS0_Shown_Toggled;
  203. _xciShown.Toggled += XCI_Shown_Toggled;
  204. _ncaShown.Toggled += NCA_Shown_Toggled;
  205. _nroShown.Toggled += NRO_Shown_Toggled;
  206. _nsoShown.Toggled += NSO_Shown_Toggled;
  207. _fileTypesSubMenu.Visible = FileAssociationHelper.IsTypeAssociationSupported;
  208. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _favToggle.Active = true;
  209. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _iconToggle.Active = true;
  210. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _appToggle.Active = true;
  211. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _developerToggle.Active = true;
  212. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _versionToggle.Active = true;
  213. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _timePlayedToggle.Active = true;
  214. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _lastPlayedToggle.Active = true;
  215. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _fileExtToggle.Active = true;
  216. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _fileSizeToggle.Active = true;
  217. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _pathToggle.Active = true;
  218. _favToggle.Toggled += Fav_Toggled;
  219. _iconToggle.Toggled += Icon_Toggled;
  220. _appToggle.Toggled += App_Toggled;
  221. _developerToggle.Toggled += Developer_Toggled;
  222. _versionToggle.Toggled += Version_Toggled;
  223. _timePlayedToggle.Toggled += TimePlayed_Toggled;
  224. _lastPlayedToggle.Toggled += LastPlayed_Toggled;
  225. _fileExtToggle.Toggled += FileExt_Toggled;
  226. _fileSizeToggle.Toggled += FileSize_Toggled;
  227. _pathToggle.Toggled += Path_Toggled;
  228. _gameTable.Model = _tableStore = new ListStore(
  229. typeof(bool),
  230. typeof(Gdk.Pixbuf),
  231. typeof(string),
  232. typeof(string),
  233. typeof(string),
  234. typeof(string),
  235. typeof(string),
  236. typeof(string),
  237. typeof(string),
  238. typeof(string),
  239. typeof(BlitStruct<ApplicationControlProperty>));
  240. _tableStore.SetSortFunc(5, SortHelper.TimePlayedSort);
  241. _tableStore.SetSortFunc(6, SortHelper.LastPlayedSort);
  242. _tableStore.SetSortFunc(8, SortHelper.FileSizeSort);
  243. int columnId = ConfigurationState.Instance.Ui.ColumnSort.SortColumnId;
  244. bool ascending = ConfigurationState.Instance.Ui.ColumnSort.SortAscending;
  245. _tableStore.SetSortColumnId(columnId, ascending ? SortType.Ascending : SortType.Descending);
  246. _gameTable.EnableSearch = true;
  247. _gameTable.SearchColumn = 2;
  248. _gameTable.SearchEqualFunc = (model, col, key, iter) => !((string)model.GetValue(iter, col)).Contains(key, StringComparison.InvariantCultureIgnoreCase);
  249. _hideUi.Label = _hideUi.Label.Replace("SHOWUIKEY", ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi.ToString());
  250. UpdateColumns();
  251. UpdateGameTable();
  252. ConfigurationState.Instance.Ui.GameDirs.Event += (sender, args) =>
  253. {
  254. if (args.OldValue != args.NewValue)
  255. {
  256. UpdateGameTable();
  257. }
  258. };
  259. Task.Run(RefreshFirmwareLabel);
  260. InputManager = new InputManager(new GTK3KeyboardDriver(this), new SDL2GamepadDriver());
  261. }
  262. private void UpdateIgnoreMissingServicesState(object sender, ReactiveEventArgs<bool> args)
  263. {
  264. if (_emulationContext != null)
  265. {
  266. _emulationContext.Configuration.IgnoreMissingServices = args.NewValue;
  267. }
  268. }
  269. private void UpdateAspectRatioState(object sender, ReactiveEventArgs<AspectRatio> args)
  270. {
  271. if (_emulationContext != null)
  272. {
  273. _emulationContext.Configuration.AspectRatio = args.NewValue;
  274. }
  275. }
  276. private void UpdateDockedModeState(object sender, ReactiveEventArgs<bool> e)
  277. {
  278. if (_emulationContext != null)
  279. {
  280. _emulationContext.System.ChangeDockedModeState(e.NewValue);
  281. }
  282. }
  283. private void UpdateAudioVolumeState(object sender, ReactiveEventArgs<float> e)
  284. {
  285. _emulationContext?.SetVolume(e.NewValue);
  286. }
  287. private void WindowStateEvent_Changed(object o, WindowStateEventArgs args)
  288. {
  289. _fullScreen.Label = args.Event.NewWindowState.HasFlag(Gdk.WindowState.Fullscreen) ? "Exit Fullscreen" : "Enter Fullscreen";
  290. }
  291. private void MainWindow_FocusOutEvent(object o, FocusOutEventArgs args)
  292. {
  293. IsFocused = false;
  294. }
  295. private void MainWindow_FocusInEvent(object o, FocusInEventArgs args)
  296. {
  297. IsFocused = true;
  298. }
  299. private void UpdateColumns()
  300. {
  301. foreach (TreeViewColumn column in _gameTable.Columns)
  302. {
  303. _gameTable.RemoveColumn(column);
  304. }
  305. CellRendererToggle favToggle = new CellRendererToggle();
  306. favToggle.Toggled += FavToggle_Toggled;
  307. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _gameTable.AppendColumn("Fav", favToggle, "active", 0);
  308. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1);
  309. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2);
  310. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3);
  311. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _gameTable.AppendColumn("Version", new CellRendererText(), "text", 4);
  312. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _gameTable.AppendColumn("Time Played", new CellRendererText(), "text", 5);
  313. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _gameTable.AppendColumn("Last Played", new CellRendererText(), "text", 6);
  314. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _gameTable.AppendColumn("File Ext", new CellRendererText(), "text", 7);
  315. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _gameTable.AppendColumn("File Size", new CellRendererText(), "text", 8);
  316. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _gameTable.AppendColumn("Path", new CellRendererText(), "text", 9);
  317. foreach (TreeViewColumn column in _gameTable.Columns)
  318. {
  319. switch (column.Title)
  320. {
  321. case "Fav":
  322. column.SortColumnId = 0;
  323. column.Clicked += Column_Clicked;
  324. break;
  325. case "Application":
  326. column.SortColumnId = 2;
  327. column.Clicked += Column_Clicked;
  328. break;
  329. case "Developer":
  330. column.SortColumnId = 3;
  331. column.Clicked += Column_Clicked;
  332. break;
  333. case "Version":
  334. column.SortColumnId = 4;
  335. column.Clicked += Column_Clicked;
  336. break;
  337. case "Time Played":
  338. column.SortColumnId = 5;
  339. column.Clicked += Column_Clicked;
  340. break;
  341. case "Last Played":
  342. column.SortColumnId = 6;
  343. column.Clicked += Column_Clicked;
  344. break;
  345. case "File Ext":
  346. column.SortColumnId = 7;
  347. column.Clicked += Column_Clicked;
  348. break;
  349. case "File Size":
  350. column.SortColumnId = 8;
  351. column.Clicked += Column_Clicked;
  352. break;
  353. case "Path":
  354. column.SortColumnId = 9;
  355. column.Clicked += Column_Clicked;
  356. break;
  357. }
  358. }
  359. }
  360. protected override void OnDestroyed()
  361. {
  362. InputManager.Dispose();
  363. }
  364. private void InitializeSwitchInstance()
  365. {
  366. _virtualFileSystem.ReloadKeySet();
  367. IRenderer renderer;
  368. if (ConfigurationState.Instance.Graphics.GraphicsBackend == GraphicsBackend.Vulkan)
  369. {
  370. string preferredGpu = ConfigurationState.Instance.Graphics.PreferredGpu.Value;
  371. renderer = new VulkanRenderer(CreateVulkanSurface, VulkanHelper.GetRequiredInstanceExtensions, preferredGpu);
  372. }
  373. else
  374. {
  375. renderer = new OpenGLRenderer();
  376. }
  377. BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading;
  378. bool threadedGAL = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);
  379. if (threadedGAL)
  380. {
  381. renderer = new ThreadedRenderer(renderer);
  382. }
  383. Logger.Info?.PrintMsg(LogClass.Gpu, $"Backend Threading ({threadingMode}): {threadedGAL}");
  384. IHardwareDeviceDriver deviceDriver = new DummyHardwareDeviceDriver();
  385. if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.SDL2)
  386. {
  387. if (SDL2HardwareDeviceDriver.IsSupported)
  388. {
  389. deviceDriver = new SDL2HardwareDeviceDriver();
  390. }
  391. else
  392. {
  393. Logger.Warning?.Print(LogClass.Audio, "SDL2 is not supported, trying to fall back to OpenAL.");
  394. if (OpenALHardwareDeviceDriver.IsSupported)
  395. {
  396. Logger.Warning?.Print(LogClass.Audio, "Found OpenAL, changing configuration.");
  397. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.OpenAl;
  398. SaveConfig();
  399. deviceDriver = new OpenALHardwareDeviceDriver();
  400. }
  401. else
  402. {
  403. Logger.Warning?.Print(LogClass.Audio, "OpenAL is not supported, trying to fall back to SoundIO.");
  404. if (SoundIoHardwareDeviceDriver.IsSupported)
  405. {
  406. Logger.Warning?.Print(LogClass.Audio, "Found SoundIO, changing configuration.");
  407. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SoundIo;
  408. SaveConfig();
  409. deviceDriver = new SoundIoHardwareDeviceDriver();
  410. }
  411. else
  412. {
  413. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  414. }
  415. }
  416. }
  417. }
  418. else if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.SoundIo)
  419. {
  420. if (SoundIoHardwareDeviceDriver.IsSupported)
  421. {
  422. deviceDriver = new SoundIoHardwareDeviceDriver();
  423. }
  424. else
  425. {
  426. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, trying to fall back to SDL2.");
  427. if (SDL2HardwareDeviceDriver.IsSupported)
  428. {
  429. Logger.Warning?.Print(LogClass.Audio, "Found SDL2, changing configuration.");
  430. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SDL2;
  431. SaveConfig();
  432. deviceDriver = new SDL2HardwareDeviceDriver();
  433. }
  434. else
  435. {
  436. Logger.Warning?.Print(LogClass.Audio, "SDL2 is not supported, trying to fall back to OpenAL.");
  437. if (OpenALHardwareDeviceDriver.IsSupported)
  438. {
  439. Logger.Warning?.Print(LogClass.Audio, "Found OpenAL, changing configuration.");
  440. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.OpenAl;
  441. SaveConfig();
  442. deviceDriver = new OpenALHardwareDeviceDriver();
  443. }
  444. else
  445. {
  446. Logger.Warning?.Print(LogClass.Audio, "OpenAL is not supported, falling back to dummy audio out.");
  447. }
  448. }
  449. }
  450. }
  451. else if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.OpenAl)
  452. {
  453. if (OpenALHardwareDeviceDriver.IsSupported)
  454. {
  455. deviceDriver = new OpenALHardwareDeviceDriver();
  456. }
  457. else
  458. {
  459. Logger.Warning?.Print(LogClass.Audio, "OpenAL is not supported, trying to fall back to SDL2.");
  460. if (SDL2HardwareDeviceDriver.IsSupported)
  461. {
  462. Logger.Warning?.Print(LogClass.Audio, "Found SDL2, changing configuration.");
  463. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SDL2;
  464. SaveConfig();
  465. deviceDriver = new SDL2HardwareDeviceDriver();
  466. }
  467. else
  468. {
  469. Logger.Warning?.Print(LogClass.Audio, "SDL2 is not supported, trying to fall back to SoundIO.");
  470. if (SoundIoHardwareDeviceDriver.IsSupported)
  471. {
  472. Logger.Warning?.Print(LogClass.Audio, "Found SoundIO, changing configuration.");
  473. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SoundIo;
  474. SaveConfig();
  475. deviceDriver = new SoundIoHardwareDeviceDriver();
  476. }
  477. else
  478. {
  479. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  480. }
  481. }
  482. }
  483. }
  484. var memoryConfiguration = ConfigurationState.Instance.System.ExpandRam.Value
  485. ? HLE.MemoryConfiguration.MemoryConfiguration6GiB
  486. : HLE.MemoryConfiguration.MemoryConfiguration4GiB;
  487. IntegrityCheckLevel fsIntegrityCheckLevel = ConfigurationState.Instance.System.EnableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None;
  488. HLE.HLEConfiguration configuration = new HLE.HLEConfiguration(_virtualFileSystem,
  489. _libHacHorizonManager,
  490. _contentManager,
  491. _accountManager,
  492. _userChannelPersistence,
  493. renderer,
  494. deviceDriver,
  495. memoryConfiguration,
  496. _uiHandler,
  497. (SystemLanguage)ConfigurationState.Instance.System.Language.Value,
  498. (RegionCode)ConfigurationState.Instance.System.Region.Value,
  499. ConfigurationState.Instance.Graphics.EnableVsync,
  500. ConfigurationState.Instance.System.EnableDockedMode,
  501. ConfigurationState.Instance.System.EnablePtc,
  502. ConfigurationState.Instance.System.EnableInternetAccess,
  503. fsIntegrityCheckLevel,
  504. ConfigurationState.Instance.System.FsGlobalAccessLogMode,
  505. ConfigurationState.Instance.System.SystemTimeOffset,
  506. ConfigurationState.Instance.System.TimeZone,
  507. ConfigurationState.Instance.System.MemoryManagerMode,
  508. ConfigurationState.Instance.System.IgnoreMissingServices,
  509. ConfigurationState.Instance.Graphics.AspectRatio,
  510. ConfigurationState.Instance.System.AudioVolume,
  511. ConfigurationState.Instance.System.UseHypervisor,
  512. ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value);
  513. _emulationContext = new HLE.Switch(configuration);
  514. }
  515. private SurfaceKHR CreateVulkanSurface(Instance instance, Vk vk)
  516. {
  517. return new SurfaceKHR((ulong)((VKRenderer)RendererWidget).CreateWindowSurface(instance.Handle));
  518. }
  519. private void SetupProgressUiHandlers()
  520. {
  521. if (_emulationContext.Processes.ActiveApplication.DiskCacheLoadState != null)
  522. {
  523. _emulationContext.Processes.ActiveApplication.DiskCacheLoadState.StateChanged -= ProgressHandler;
  524. _emulationContext.Processes.ActiveApplication.DiskCacheLoadState.StateChanged += ProgressHandler;
  525. }
  526. _emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
  527. _emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
  528. }
  529. private void ProgressHandler<T>(T state, int current, int total) where T : Enum
  530. {
  531. bool visible;
  532. string label;
  533. switch (state)
  534. {
  535. case LoadState ptcState:
  536. visible = ptcState != LoadState.Loaded;
  537. label = $"PTC : {current}/{total}";
  538. break;
  539. case ShaderCacheLoadingState shaderCacheState:
  540. visible = shaderCacheState != ShaderCacheLoadingState.Loaded;
  541. label = $"Shaders : {current}/{total}";
  542. break;
  543. default:
  544. throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
  545. }
  546. Application.Invoke(delegate
  547. {
  548. _loadingStatusLabel.Text = label;
  549. _loadingStatusBar.Fraction = total > 0 ? (double)current / total : 0;
  550. _loadingStatusBar.Visible = visible;
  551. _loadingStatusLabel.Visible = visible;
  552. });
  553. }
  554. public void UpdateGameTable()
  555. {
  556. if (_updatingGameTable || _gameLoaded)
  557. {
  558. return;
  559. }
  560. _updatingGameTable = true;
  561. _tableStore.Clear();
  562. Thread applicationLibraryThread = new Thread(() =>
  563. {
  564. _applicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language);
  565. _updatingGameTable = false;
  566. });
  567. applicationLibraryThread.Name = "GUI.ApplicationLibraryThread";
  568. applicationLibraryThread.IsBackground = true;
  569. applicationLibraryThread.Start();
  570. }
  571. [Conditional("RELEASE")]
  572. public void PerformanceCheck()
  573. {
  574. if (ConfigurationState.Instance.Logger.EnableTrace.Value)
  575. {
  576. MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  577. {
  578. Title = "Ryujinx - Warning",
  579. Text = "You have trace logging enabled, which is designed to be used by developers only.",
  580. SecondaryText = "For optimal performance, it's recommended to disable trace logging. Would you like to disable trace logging now?"
  581. };
  582. if (debugWarningDialog.Run() == (int)ResponseType.Yes)
  583. {
  584. ConfigurationState.Instance.Logger.EnableTrace.Value = false;
  585. SaveConfig();
  586. }
  587. debugWarningDialog.Dispose();
  588. }
  589. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  590. {
  591. MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  592. {
  593. Title = "Ryujinx - Warning",
  594. Text = "You have shader dumping enabled, which is designed to be used by developers only.",
  595. SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
  596. };
  597. if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes)
  598. {
  599. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  600. SaveConfig();
  601. }
  602. shadersDumpWarningDialog.Dispose();
  603. }
  604. }
  605. private bool LoadApplication(string path, bool isFirmwareTitle)
  606. {
  607. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  608. if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError))
  609. {
  610. if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion))
  611. {
  612. string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})";
  613. ResponseType responseDialog = (ResponseType)GtkDialog.CreateConfirmationDialog("No Firmware Installed", message).Run();
  614. if (responseDialog != ResponseType.Yes || !SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _))
  615. {
  616. UserErrorDialog.CreateUserErrorDialog(userError);
  617. return false;
  618. }
  619. // Tell the user that we installed a firmware for them.
  620. firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  621. RefreshFirmwareLabel();
  622. message = $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start.";
  623. GtkDialog.CreateInfoDialog($"Firmware {firmwareVersion.VersionString} was installed", message);
  624. }
  625. else
  626. {
  627. UserErrorDialog.CreateUserErrorDialog(userError);
  628. return false;
  629. }
  630. }
  631. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  632. if (isFirmwareTitle)
  633. {
  634. Logger.Info?.Print(LogClass.Application, "Loading as Firmware Title (NCA).");
  635. return _emulationContext.LoadNca(path);
  636. }
  637. if (Directory.Exists(path))
  638. {
  639. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  640. if (romFsFiles.Length == 0)
  641. {
  642. romFsFiles = Directory.GetFiles(path, "*.romfs");
  643. }
  644. if (romFsFiles.Length > 0)
  645. {
  646. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  647. return _emulationContext.LoadCart(path, romFsFiles[0]);
  648. }
  649. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  650. return _emulationContext.LoadCart(path);
  651. }
  652. if (File.Exists(path))
  653. {
  654. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  655. {
  656. case ".xci":
  657. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  658. return _emulationContext.LoadXci(path);
  659. case ".nca":
  660. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  661. return _emulationContext.LoadNca(path);
  662. case ".nsp":
  663. case ".pfs0":
  664. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  665. return _emulationContext.LoadNsp(path);
  666. default:
  667. Logger.Info?.Print(LogClass.Application, "Loading as Homebrew.");
  668. try
  669. {
  670. return _emulationContext.LoadProgram(path);
  671. }
  672. catch (ArgumentOutOfRangeException)
  673. {
  674. Logger.Error?.Print(LogClass.Application, "The specified file is not supported by Ryujinx.");
  675. return false;
  676. }
  677. }
  678. }
  679. Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  680. return false;
  681. }
  682. public void RunApplication(string path, bool startFullscreen = false)
  683. {
  684. if (_gameLoaded)
  685. {
  686. GtkDialog.CreateInfoDialog("A game has already been loaded", "Please stop emulation or close the emulator before launching another game.");
  687. }
  688. else
  689. {
  690. PerformanceCheck();
  691. Logger.RestartTime();
  692. RendererWidget = CreateRendererWidget();
  693. SwitchToRenderWidget(startFullscreen);
  694. InitializeSwitchInstance();
  695. UpdateGraphicsConfig();
  696. bool isFirmwareTitle = false;
  697. if (path.StartsWith("@SystemContent"))
  698. {
  699. path = _virtualFileSystem.SwitchPathToSystemPath(path);
  700. isFirmwareTitle = true;
  701. }
  702. if (!LoadApplication(path, isFirmwareTitle))
  703. {
  704. _emulationContext.Dispose();
  705. SwitchToGameTable();
  706. return;
  707. }
  708. SetupProgressUiHandlers();
  709. _currentEmulatedGamePath = path;
  710. _deviceExitStatus.Reset();
  711. Translator.IsReadyForTranslation.Reset();
  712. Thread windowThread = new(CreateGameWindow)
  713. {
  714. Name = "GUI.WindowThread"
  715. };
  716. windowThread.Start();
  717. _gameLoaded = true;
  718. _actionMenu.Sensitive = true;
  719. UpdateMenuItem.Sensitive = false;
  720. _lastScannedAmiiboId = "";
  721. _firmwareInstallFile.Sensitive = false;
  722. _firmwareInstallDirectory.Sensitive = false;
  723. DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Processes.ActiveApplication.ProgramIdText,
  724. _emulationContext.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString());
  725. _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Processes.ActiveApplication.ProgramIdText, appMetadata =>
  726. {
  727. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  728. });
  729. }
  730. }
  731. private RendererWidgetBase CreateRendererWidget()
  732. {
  733. if (ConfigurationState.Instance.Graphics.GraphicsBackend == GraphicsBackend.Vulkan)
  734. {
  735. return new VKRenderer(InputManager, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  736. }
  737. else
  738. {
  739. return new GlRenderer(InputManager, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  740. }
  741. }
  742. private void SwitchToRenderWidget(bool startFullscreen = false)
  743. {
  744. _viewBox.Remove(_gameTableWindow);
  745. RendererWidget.Expand = true;
  746. _viewBox.Child = RendererWidget;
  747. RendererWidget.ShowAll();
  748. EditFooterForGameRenderer();
  749. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  750. {
  751. ToggleExtraWidgets(false);
  752. }
  753. else if (startFullscreen || ConfigurationState.Instance.Ui.StartFullscreen.Value)
  754. {
  755. FullScreen_Toggled(null, null);
  756. }
  757. }
  758. private void SwitchToGameTable()
  759. {
  760. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  761. {
  762. ToggleExtraWidgets(true);
  763. }
  764. RendererWidget.Exit();
  765. if (RendererWidget.Window != Window && RendererWidget.Window != null)
  766. {
  767. RendererWidget.Window.Dispose();
  768. }
  769. RendererWidget.Dispose();
  770. if (OperatingSystem.IsWindows())
  771. {
  772. _windowsMultimediaTimerResolution?.Dispose();
  773. _windowsMultimediaTimerResolution = null;
  774. }
  775. DisplaySleep.Restore();
  776. _viewBox.Remove(RendererWidget);
  777. _viewBox.Add(_gameTableWindow);
  778. _gameTableWindow.Expand = true;
  779. Window.Title = $"Ryujinx {Program.Version}";
  780. _emulationContext = null;
  781. _gameLoaded = false;
  782. RendererWidget = null;
  783. DiscordIntegrationModule.SwitchToMainMenu();
  784. RecreateFooterForMenu();
  785. UpdateColumns();
  786. UpdateGameTable();
  787. RefreshFirmwareLabel();
  788. HandleRelaunch();
  789. }
  790. private void CreateGameWindow()
  791. {
  792. if (OperatingSystem.IsWindows())
  793. {
  794. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  795. }
  796. DisplaySleep.Prevent();
  797. RendererWidget.Initialize(_emulationContext);
  798. RendererWidget.WaitEvent.WaitOne();
  799. RendererWidget.Start();
  800. _emulationContext.Dispose();
  801. _deviceExitStatus.Set();
  802. // NOTE: Everything that is here will not be executed when you close the UI.
  803. Application.Invoke(delegate
  804. {
  805. SwitchToGameTable();
  806. });
  807. }
  808. private void RecreateFooterForMenu()
  809. {
  810. _listStatusBox.Show();
  811. _statusBar.Hide();
  812. }
  813. private void EditFooterForGameRenderer()
  814. {
  815. _listStatusBox.Hide();
  816. _statusBar.Show();
  817. }
  818. public void ToggleExtraWidgets(bool show)
  819. {
  820. if (RendererWidget != null)
  821. {
  822. if (show)
  823. {
  824. _menuBar.ShowAll();
  825. _footerBox.Show();
  826. _statusBar.Show();
  827. }
  828. else
  829. {
  830. _menuBar.Hide();
  831. _footerBox.Hide();
  832. }
  833. }
  834. }
  835. private void UpdateGameMetadata(string titleId)
  836. {
  837. if (_gameLoaded)
  838. {
  839. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  840. {
  841. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  842. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  843. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  844. });
  845. }
  846. }
  847. public void UpdateGraphicsConfig()
  848. {
  849. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  850. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  851. Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
  852. Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  853. Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  854. Graphics.Gpu.GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  855. Graphics.Gpu.GraphicsConfig.EnableTextureRecompression = ConfigurationState.Instance.Graphics.EnableTextureRecompression;
  856. Graphics.Gpu.GraphicsConfig.EnableMacroHLE = ConfigurationState.Instance.Graphics.EnableMacroHLE;
  857. }
  858. public void SaveConfig()
  859. {
  860. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  861. }
  862. private void End()
  863. {
  864. if (_ending)
  865. {
  866. return;
  867. }
  868. _ending = true;
  869. if (_emulationContext != null)
  870. {
  871. UpdateGameMetadata(_emulationContext.Processes.ActiveApplication.ProgramIdText);
  872. if (RendererWidget != null)
  873. {
  874. // We tell the widget that we are exiting.
  875. RendererWidget.Exit();
  876. // Wait for the other thread to dispose the HLE context before exiting.
  877. _deviceExitStatus.WaitOne();
  878. RendererWidget.Dispose();
  879. }
  880. }
  881. Dispose();
  882. Program.Exit();
  883. Application.Quit();
  884. }
  885. //
  886. // Events
  887. //
  888. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  889. {
  890. Application.Invoke(delegate
  891. {
  892. _tableStore.AppendValues(
  893. args.AppData.Favorite,
  894. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  895. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  896. args.AppData.Developer,
  897. args.AppData.Version,
  898. args.AppData.TimePlayed,
  899. args.AppData.LastPlayed,
  900. args.AppData.FileExtension,
  901. args.AppData.FileSize,
  902. args.AppData.Path,
  903. args.AppData.ControlHolder);
  904. });
  905. }
  906. private void ApplicationCount_Updated(object sender, ApplicationCountUpdatedEventArgs args)
  907. {
  908. Application.Invoke(delegate
  909. {
  910. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  911. float barValue = 0;
  912. if (args.NumAppsFound != 0)
  913. {
  914. barValue = (float)args.NumAppsLoaded / args.NumAppsFound;
  915. }
  916. _progressBar.Fraction = barValue;
  917. // Reset the vertical scrollbar to the top when titles finish loading
  918. if (args.NumAppsLoaded == args.NumAppsFound)
  919. {
  920. _gameTableWindow.Vadjustment.Value = 0;
  921. }
  922. });
  923. }
  924. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  925. {
  926. Application.Invoke(delegate
  927. {
  928. _gameStatus.Text = args.GameStatus;
  929. _fifoStatus.Text = args.FifoStatus;
  930. _gpuName.Text = args.GpuName;
  931. _dockedMode.Text = args.DockedMode;
  932. _aspectRatio.Text = args.AspectRatio;
  933. _gpuBackend.Text = args.GpuBackend;
  934. _volumeStatus.Text = GetVolumeLabelText(args.Volume);
  935. if (args.VSyncEnabled)
  936. {
  937. _vSyncStatus.Attributes = new Pango.AttrList();
  938. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(11822, 60138, 51657));
  939. }
  940. else
  941. {
  942. _vSyncStatus.Attributes = new Pango.AttrList();
  943. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(ushort.MaxValue, 17733, 21588));
  944. }
  945. });
  946. }
  947. private void FavToggle_Toggled(object sender, ToggledArgs args)
  948. {
  949. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  950. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  951. bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
  952. _tableStore.SetValue(treeIter, 0, newToggleValue);
  953. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  954. {
  955. appMetadata.Favorite = newToggleValue;
  956. });
  957. }
  958. private void Column_Clicked(object sender, EventArgs args)
  959. {
  960. TreeViewColumn column = (TreeViewColumn)sender;
  961. ConfigurationState.Instance.Ui.ColumnSort.SortColumnId.Value = column.SortColumnId;
  962. ConfigurationState.Instance.Ui.ColumnSort.SortAscending.Value = column.SortOrder == SortType.Ascending;
  963. SaveConfig();
  964. }
  965. private void Row_Activated(object sender, RowActivatedArgs args)
  966. {
  967. _gameTableSelection.GetSelected(out TreeIter treeIter);
  968. string path = (string)_tableStore.GetValue(treeIter, 9);
  969. RunApplication(path);
  970. }
  971. private void VSyncStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  972. {
  973. _emulationContext.EnableDeviceVsync = !_emulationContext.EnableDeviceVsync;
  974. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {_emulationContext.EnableDeviceVsync}");
  975. }
  976. private void DockedMode_Clicked(object sender, ButtonReleaseEventArgs args)
  977. {
  978. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  979. }
  980. private string GetVolumeLabelText(float volume)
  981. {
  982. string icon = volume == 0 ? "🔇" : "🔊";
  983. return $"{icon} {(int)(volume * 100)}%";
  984. }
  985. private void VolumeStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  986. {
  987. if (_emulationContext != null)
  988. {
  989. if (_emulationContext.IsAudioMuted())
  990. {
  991. _emulationContext.SetVolume(ConfigurationState.Instance.System.AudioVolume);
  992. }
  993. else
  994. {
  995. _emulationContext.SetVolume(0);
  996. }
  997. }
  998. }
  999. private void AspectRatio_Clicked(object sender, ButtonReleaseEventArgs args)
  1000. {
  1001. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  1002. ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames<AspectRatio>().Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  1003. }
  1004. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  1005. {
  1006. if (args.Event.Button != 3 /* Right Click */)
  1007. {
  1008. return;
  1009. }
  1010. _gameTableSelection.GetSelected(out TreeIter treeIter);
  1011. if (treeIter.UserData == IntPtr.Zero)
  1012. {
  1013. return;
  1014. }
  1015. string titleFilePath = _tableStore.GetValue(treeIter, 9).ToString();
  1016. string titleName = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[0];
  1017. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  1018. BlitStruct<ApplicationControlProperty> controlData = (BlitStruct<ApplicationControlProperty>)_tableStore.GetValue(treeIter, 10);
  1019. _ = new GameTableContextMenu(this, _virtualFileSystem, _accountManager, _libHacHorizonManager.RyujinxClient, titleFilePath, titleName, titleId, controlData);
  1020. }
  1021. private void Load_Application_File(object sender, EventArgs args)
  1022. {
  1023. using (FileChooserNative fileChooser = new FileChooserNative("Choose the file to open", this, FileChooserAction.Open, "Open", "Cancel"))
  1024. {
  1025. FileFilter filter = new FileFilter()
  1026. {
  1027. Name = "Switch Executables"
  1028. };
  1029. filter.AddPattern("*.xci");
  1030. filter.AddPattern("*.nsp");
  1031. filter.AddPattern("*.pfs0");
  1032. filter.AddPattern("*.nca");
  1033. filter.AddPattern("*.nro");
  1034. filter.AddPattern("*.nso");
  1035. fileChooser.AddFilter(filter);
  1036. if (fileChooser.Run() == (int)ResponseType.Accept)
  1037. {
  1038. RunApplication(fileChooser.Filename);
  1039. }
  1040. }
  1041. }
  1042. private void Load_Application_Folder(object sender, EventArgs args)
  1043. {
  1044. using (FileChooserNative fileChooser = new FileChooserNative("Choose the folder to open", this, FileChooserAction.SelectFolder, "Open", "Cancel"))
  1045. {
  1046. if (fileChooser.Run() == (int)ResponseType.Accept)
  1047. {
  1048. RunApplication(fileChooser.Filename);
  1049. }
  1050. }
  1051. }
  1052. private void FileMenu_StateChanged(object o, StateChangedArgs args)
  1053. {
  1054. _appletMenu.Sensitive = _emulationContext == null && _contentManager.GetCurrentFirmwareVersion() != null && _contentManager.GetCurrentFirmwareVersion().Major > 3;
  1055. _loadApplicationFile.Sensitive = _emulationContext == null;
  1056. _loadApplicationFolder.Sensitive = _emulationContext == null;
  1057. }
  1058. private void Load_Mii_Edit_Applet(object sender, EventArgs args)
  1059. {
  1060. string contentPath = _contentManager.GetInstalledContentPath(0x0100000000001009, StorageId.BuiltInSystem, NcaContentType.Program);
  1061. RunApplication(contentPath);
  1062. }
  1063. private void Open_Ryu_Folder(object sender, EventArgs args)
  1064. {
  1065. OpenHelper.OpenFolder(AppDataManager.BaseDirPath);
  1066. }
  1067. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  1068. {
  1069. string logPath = System.IO.Path.Combine(ReleaseInformation.GetBaseApplicationDirectory(), "Logs");
  1070. new DirectoryInfo(logPath).Create();
  1071. OpenHelper.OpenFolder(logPath);
  1072. }
  1073. private void Exit_Pressed(object sender, EventArgs args)
  1074. {
  1075. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  1076. {
  1077. End();
  1078. }
  1079. }
  1080. private void Window_Close(object sender, DeleteEventArgs args)
  1081. {
  1082. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  1083. {
  1084. End();
  1085. }
  1086. else
  1087. {
  1088. args.RetVal = true;
  1089. }
  1090. }
  1091. private void StopEmulation_Pressed(object sender, EventArgs args)
  1092. {
  1093. if (_emulationContext != null)
  1094. {
  1095. UpdateGameMetadata(_emulationContext.Processes.ActiveApplication.ProgramIdText);
  1096. }
  1097. _pauseEmulation.Sensitive = false;
  1098. _resumeEmulation.Sensitive = false;
  1099. UpdateMenuItem.Sensitive = true;
  1100. RendererWidget?.Exit();
  1101. }
  1102. private void PauseEmulation_Pressed(object sender, EventArgs args)
  1103. {
  1104. _pauseEmulation.Sensitive = false;
  1105. _resumeEmulation.Sensitive = true;
  1106. _emulationContext.System.TogglePauseEmulation(true);
  1107. }
  1108. private void ResumeEmulation_Pressed(object sender, EventArgs args)
  1109. {
  1110. _pauseEmulation.Sensitive = true;
  1111. _resumeEmulation.Sensitive = false;
  1112. _emulationContext.System.TogglePauseEmulation(false);
  1113. }
  1114. public void ActivatePauseMenu()
  1115. {
  1116. _pauseEmulation.Sensitive = true;
  1117. _resumeEmulation.Sensitive = false;
  1118. }
  1119. public void TogglePause()
  1120. {
  1121. _pauseEmulation.Sensitive ^= true;
  1122. _resumeEmulation.Sensitive ^= true;
  1123. _emulationContext.System.TogglePauseEmulation(_resumeEmulation.Sensitive);
  1124. }
  1125. private void Installer_File_Pressed(object o, EventArgs args)
  1126. {
  1127. FileChooserNative fileChooser = new FileChooserNative("Choose the firmware file to open", this, FileChooserAction.Open, "Open", "Cancel");
  1128. FileFilter filter = new FileFilter
  1129. {
  1130. Name = "Switch Firmware Files"
  1131. };
  1132. filter.AddPattern("*.zip");
  1133. filter.AddPattern("*.xci");
  1134. fileChooser.AddFilter(filter);
  1135. HandleInstallerDialog(fileChooser);
  1136. }
  1137. private void Installer_Directory_Pressed(object o, EventArgs args)
  1138. {
  1139. FileChooserNative directoryChooser = new FileChooserNative("Choose the firmware directory to open", this, FileChooserAction.SelectFolder, "Open", "Cancel");
  1140. HandleInstallerDialog(directoryChooser);
  1141. }
  1142. private void HandleInstallerDialog(FileChooserNative fileChooser)
  1143. {
  1144. if (fileChooser.Run() == (int)ResponseType.Accept)
  1145. {
  1146. try
  1147. {
  1148. string filename = fileChooser.Filename;
  1149. fileChooser.Dispose();
  1150. SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);
  1151. if (firmwareVersion is null)
  1152. {
  1153. GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}.");
  1154. return;
  1155. }
  1156. string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}";
  1157. SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();
  1158. string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
  1159. if (currentVersion != null)
  1160. {
  1161. dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. ";
  1162. }
  1163. dialogMessage += "\n\nDo you want to continue?";
  1164. ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run();
  1165. MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware...");
  1166. if (responseInstallDialog == ResponseType.Yes)
  1167. {
  1168. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  1169. Thread thread = new Thread(() =>
  1170. {
  1171. Application.Invoke(delegate
  1172. {
  1173. waitingDialog.Run();
  1174. });
  1175. try
  1176. {
  1177. _contentManager.InstallFirmware(filename);
  1178. Application.Invoke(delegate
  1179. {
  1180. waitingDialog.Dispose();
  1181. string message = $"System version {firmwareVersion.VersionString} successfully installed.";
  1182. GtkDialog.CreateInfoDialog(dialogTitle, message);
  1183. Logger.Info?.Print(LogClass.Application, message);
  1184. // Purge Applet Cache.
  1185. DirectoryInfo miiEditorCacheFolder = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, "0100000000001009", "cache"));
  1186. if (miiEditorCacheFolder.Exists)
  1187. {
  1188. miiEditorCacheFolder.Delete(true);
  1189. }
  1190. });
  1191. }
  1192. catch (Exception ex)
  1193. {
  1194. Application.Invoke(delegate
  1195. {
  1196. waitingDialog.Dispose();
  1197. GtkDialog.CreateErrorDialog(ex.Message);
  1198. });
  1199. }
  1200. finally
  1201. {
  1202. RefreshFirmwareLabel();
  1203. }
  1204. });
  1205. thread.Name = "GUI.FirmwareInstallerThread";
  1206. thread.Start();
  1207. }
  1208. }
  1209. catch (MissingKeyException ex)
  1210. {
  1211. Logger.Error?.Print(LogClass.Application, ex.ToString());
  1212. UserErrorDialog.CreateUserErrorDialog(UserError.FirmwareParsingFailed);
  1213. }
  1214. catch (Exception ex)
  1215. {
  1216. GtkDialog.CreateErrorDialog(ex.Message);
  1217. }
  1218. }
  1219. else
  1220. {
  1221. fileChooser.Dispose();
  1222. }
  1223. }
  1224. private void RefreshFirmwareLabel()
  1225. {
  1226. SystemVersion currentFirmware = _contentManager.GetCurrentFirmwareVersion();
  1227. Application.Invoke(delegate
  1228. {
  1229. _firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
  1230. });
  1231. }
  1232. private void InstallFileTypes_Pressed(object sender, EventArgs e)
  1233. {
  1234. if (FileAssociationHelper.Install())
  1235. {
  1236. GtkDialog.CreateInfoDialog("Install file types", "File types successfully installed!");
  1237. }
  1238. else
  1239. {
  1240. GtkDialog.CreateErrorDialog("Failed to install file types.");
  1241. }
  1242. }
  1243. private void UninstallFileTypes_Pressed(object sender, EventArgs e)
  1244. {
  1245. if (FileAssociationHelper.Uninstall())
  1246. {
  1247. GtkDialog.CreateInfoDialog("Uninstall file types", "File types successfully uninstalled!");
  1248. }
  1249. else
  1250. {
  1251. GtkDialog.CreateErrorDialog("Failed to uninstall file types.");
  1252. }
  1253. }
  1254. private void HandleRelaunch()
  1255. {
  1256. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  1257. {
  1258. _userChannelPersistence.ShouldRestart = false;
  1259. RunApplication(_currentEmulatedGamePath);
  1260. }
  1261. else
  1262. {
  1263. // otherwise, clear state.
  1264. _userChannelPersistence = new UserChannelPersistence();
  1265. _currentEmulatedGamePath = null;
  1266. _actionMenu.Sensitive = false;
  1267. _firmwareInstallFile.Sensitive = true;
  1268. _firmwareInstallDirectory.Sensitive = true;
  1269. }
  1270. }
  1271. private void FullScreen_Toggled(object sender, EventArgs args)
  1272. {
  1273. if (!Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  1274. {
  1275. Fullscreen();
  1276. ToggleExtraWidgets(false);
  1277. }
  1278. else
  1279. {
  1280. Unfullscreen();
  1281. ToggleExtraWidgets(true);
  1282. }
  1283. }
  1284. private void StartFullScreen_Toggled(object sender, EventArgs args)
  1285. {
  1286. ConfigurationState.Instance.Ui.StartFullscreen.Value = _startFullScreen.Active;
  1287. SaveConfig();
  1288. }
  1289. private void ShowConsole_Toggled(object sender, EventArgs args)
  1290. {
  1291. ConfigurationState.Instance.Ui.ShowConsole.Value = _showConsole.Active;
  1292. SaveConfig();
  1293. }
  1294. private void OptionMenu_StateChanged(object o, StateChangedArgs args)
  1295. {
  1296. _manageUserProfiles.Sensitive = _emulationContext == null;
  1297. }
  1298. private void Settings_Pressed(object sender, EventArgs args)
  1299. {
  1300. SettingsWindow settingsWindow = new SettingsWindow(this, _virtualFileSystem, _contentManager);
  1301. settingsWindow.SetSizeRequest((int)(settingsWindow.DefaultWidth * Program.WindowScaleFactor), (int)(settingsWindow.DefaultHeight * Program.WindowScaleFactor));
  1302. settingsWindow.Show();
  1303. }
  1304. private void HideUi_Pressed(object sender, EventArgs args)
  1305. {
  1306. ToggleExtraWidgets(false);
  1307. }
  1308. private void ManageCheats_Pressed(object sender, EventArgs args)
  1309. {
  1310. var window = new CheatWindow(_virtualFileSystem,
  1311. _emulationContext.Processes.ActiveApplication.ProgramId,
  1312. _emulationContext.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString());
  1313. window.Destroyed += CheatWindow_Destroyed;
  1314. window.Show();
  1315. }
  1316. private void CheatWindow_Destroyed(object sender, EventArgs e)
  1317. {
  1318. _emulationContext.EnableCheats();
  1319. (sender as CheatWindow).Destroyed -= CheatWindow_Destroyed;
  1320. }
  1321. private void ManageUserProfiles_Pressed(object sender, EventArgs args)
  1322. {
  1323. UserProfilesManagerWindow userProfilesManagerWindow = new UserProfilesManagerWindow(_accountManager, _contentManager, _virtualFileSystem);
  1324. userProfilesManagerWindow.SetSizeRequest((int)(userProfilesManagerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(userProfilesManagerWindow.DefaultHeight * Program.WindowScaleFactor));
  1325. userProfilesManagerWindow.Show();
  1326. }
  1327. private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args)
  1328. {
  1329. if (_emulationContext != null)
  1330. {
  1331. _emulationContext.System.SimulateWakeUpMessage();
  1332. }
  1333. }
  1334. private void ActionMenu_StateChanged(object o, StateChangedArgs args)
  1335. {
  1336. _scanAmiibo.Sensitive = _emulationContext != null && _emulationContext.System.SearchingForAmiibo(out int _);
  1337. _takeScreenshot.Sensitive = _emulationContext != null;
  1338. }
  1339. private void Scan_Amiibo(object sender, EventArgs args)
  1340. {
  1341. if (_emulationContext.System.SearchingForAmiibo(out int deviceId))
  1342. {
  1343. AmiiboWindow amiiboWindow = new AmiiboWindow
  1344. {
  1345. LastScannedAmiiboShowAll = _lastScannedAmiiboShowAll,
  1346. LastScannedAmiiboId = _lastScannedAmiiboId,
  1347. DeviceId = deviceId,
  1348. TitleId = _emulationContext.Processes.ActiveApplication.ProgramIdText.ToUpper()
  1349. };
  1350. amiiboWindow.DeleteEvent += AmiiboWindow_DeleteEvent;
  1351. amiiboWindow.Show();
  1352. }
  1353. else
  1354. {
  1355. GtkDialog.CreateInfoDialog($"Amiibo", "The game is currently not ready to receive Amiibo scan data. Ensure that you have an Amiibo-compatible game open and ready to receive Amiibo scan data.");
  1356. }
  1357. }
  1358. private void Take_Screenshot(object sender, EventArgs args)
  1359. {
  1360. if (_emulationContext != null && RendererWidget != null)
  1361. {
  1362. RendererWidget.ScreenshotRequested = true;
  1363. }
  1364. }
  1365. private void AmiiboWindow_DeleteEvent(object sender, DeleteEventArgs args)
  1366. {
  1367. if (((AmiiboWindow)sender).AmiiboId != "" && ((AmiiboWindow)sender).Response == ResponseType.Ok)
  1368. {
  1369. _lastScannedAmiiboId = ((AmiiboWindow)sender).AmiiboId;
  1370. _lastScannedAmiiboShowAll = ((AmiiboWindow)sender).LastScannedAmiiboShowAll;
  1371. _emulationContext.System.ScanAmiibo(((AmiiboWindow)sender).DeviceId, ((AmiiboWindow)sender).AmiiboId, ((AmiiboWindow)sender).UseRandomUuid);
  1372. }
  1373. }
  1374. private void Update_Pressed(object sender, EventArgs args)
  1375. {
  1376. if (Updater.CanUpdate(true))
  1377. {
  1378. Updater.BeginParse(this, true).ContinueWith(task =>
  1379. {
  1380. Logger.Error?.Print(LogClass.Application, $"Updater error: {task.Exception}");
  1381. }, TaskContinuationOptions.OnlyOnFaulted);
  1382. }
  1383. }
  1384. private void About_Pressed(object sender, EventArgs args)
  1385. {
  1386. AboutWindow aboutWindow = new AboutWindow();
  1387. aboutWindow.SetSizeRequest((int)(aboutWindow.DefaultWidth * Program.WindowScaleFactor), (int)(aboutWindow.DefaultHeight * Program.WindowScaleFactor));
  1388. aboutWindow.Show();
  1389. }
  1390. private void Fav_Toggled(object sender, EventArgs args)
  1391. {
  1392. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  1393. SaveConfig();
  1394. UpdateColumns();
  1395. }
  1396. private void Icon_Toggled(object sender, EventArgs args)
  1397. {
  1398. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  1399. SaveConfig();
  1400. UpdateColumns();
  1401. }
  1402. private void App_Toggled(object sender, EventArgs args)
  1403. {
  1404. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  1405. SaveConfig();
  1406. UpdateColumns();
  1407. }
  1408. private void Developer_Toggled(object sender, EventArgs args)
  1409. {
  1410. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  1411. SaveConfig();
  1412. UpdateColumns();
  1413. }
  1414. private void Version_Toggled(object sender, EventArgs args)
  1415. {
  1416. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  1417. SaveConfig();
  1418. UpdateColumns();
  1419. }
  1420. private void TimePlayed_Toggled(object sender, EventArgs args)
  1421. {
  1422. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  1423. SaveConfig();
  1424. UpdateColumns();
  1425. }
  1426. private void LastPlayed_Toggled(object sender, EventArgs args)
  1427. {
  1428. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  1429. SaveConfig();
  1430. UpdateColumns();
  1431. }
  1432. private void FileExt_Toggled(object sender, EventArgs args)
  1433. {
  1434. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  1435. SaveConfig();
  1436. UpdateColumns();
  1437. }
  1438. private void FileSize_Toggled(object sender, EventArgs args)
  1439. {
  1440. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  1441. SaveConfig();
  1442. UpdateColumns();
  1443. }
  1444. private void Path_Toggled(object sender, EventArgs args)
  1445. {
  1446. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  1447. SaveConfig();
  1448. UpdateColumns();
  1449. }
  1450. private void NSP_Shown_Toggled(object sender, EventArgs args)
  1451. {
  1452. ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value = _nspShown.Active;
  1453. SaveConfig();
  1454. UpdateGameTable();
  1455. }
  1456. private void PFS0_Shown_Toggled(object sender, EventArgs args)
  1457. {
  1458. ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value = _pfs0Shown.Active;
  1459. SaveConfig();
  1460. UpdateGameTable();
  1461. }
  1462. private void XCI_Shown_Toggled (object sender, EventArgs args)
  1463. {
  1464. ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value = _xciShown.Active;
  1465. SaveConfig();
  1466. UpdateGameTable();
  1467. }
  1468. private void NCA_Shown_Toggled (object sender, EventArgs args)
  1469. {
  1470. ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value = _ncaShown.Active;
  1471. SaveConfig();
  1472. UpdateGameTable();
  1473. }
  1474. private void NRO_Shown_Toggled (object sender, EventArgs args)
  1475. {
  1476. ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value = _nroShown.Active;
  1477. SaveConfig();
  1478. UpdateGameTable();
  1479. }
  1480. private void NSO_Shown_Toggled (object sender, EventArgs args)
  1481. {
  1482. ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value = _nsoShown.Active;
  1483. SaveConfig();
  1484. UpdateGameTable();
  1485. }
  1486. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  1487. {
  1488. UpdateGameTable();
  1489. }
  1490. }
  1491. }