MainWindow.cs 75 KB

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