MainWindow.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  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. _emulationContext = new HLE.Switch(configuration);
  513. }
  514. private SurfaceKHR CreateVulkanSurface(Instance instance, Vk vk)
  515. {
  516. return new SurfaceKHR((ulong)((VKRenderer)RendererWidget).CreateWindowSurface(instance.Handle));
  517. }
  518. private void SetupProgressUiHandlers()
  519. {
  520. if (_emulationContext.Processes.ActiveApplication.DiskCacheLoadState != null)
  521. {
  522. _emulationContext.Processes.ActiveApplication.DiskCacheLoadState.StateChanged -= ProgressHandler;
  523. _emulationContext.Processes.ActiveApplication.DiskCacheLoadState.StateChanged += ProgressHandler;
  524. }
  525. _emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
  526. _emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
  527. }
  528. private void ProgressHandler<T>(T state, int current, int total) where T : Enum
  529. {
  530. bool visible;
  531. string label;
  532. switch (state)
  533. {
  534. case LoadState ptcState:
  535. visible = ptcState != LoadState.Loaded;
  536. label = $"PTC : {current}/{total}";
  537. break;
  538. case ShaderCacheLoadingState shaderCacheState:
  539. visible = shaderCacheState != ShaderCacheLoadingState.Loaded;
  540. label = $"Shaders : {current}/{total}";
  541. break;
  542. default:
  543. throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
  544. }
  545. Application.Invoke(delegate
  546. {
  547. _loadingStatusLabel.Text = label;
  548. _loadingStatusBar.Fraction = total > 0 ? (double)current / total : 0;
  549. _loadingStatusBar.Visible = visible;
  550. _loadingStatusLabel.Visible = visible;
  551. });
  552. }
  553. public void UpdateGameTable()
  554. {
  555. if (_updatingGameTable || _gameLoaded)
  556. {
  557. return;
  558. }
  559. _updatingGameTable = true;
  560. _tableStore.Clear();
  561. Thread applicationLibraryThread = new Thread(() =>
  562. {
  563. _applicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language);
  564. _updatingGameTable = false;
  565. });
  566. applicationLibraryThread.Name = "GUI.ApplicationLibraryThread";
  567. applicationLibraryThread.IsBackground = true;
  568. applicationLibraryThread.Start();
  569. }
  570. [Conditional("RELEASE")]
  571. public void PerformanceCheck()
  572. {
  573. if (ConfigurationState.Instance.Logger.EnableTrace.Value)
  574. {
  575. MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  576. {
  577. Title = "Ryujinx - Warning",
  578. Text = "You have trace logging enabled, which is designed to be used by developers only.",
  579. SecondaryText = "For optimal performance, it's recommended to disable trace logging. Would you like to disable trace logging now?"
  580. };
  581. if (debugWarningDialog.Run() == (int)ResponseType.Yes)
  582. {
  583. ConfigurationState.Instance.Logger.EnableTrace.Value = false;
  584. SaveConfig();
  585. }
  586. debugWarningDialog.Dispose();
  587. }
  588. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  589. {
  590. MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  591. {
  592. Title = "Ryujinx - Warning",
  593. Text = "You have shader dumping enabled, which is designed to be used by developers only.",
  594. SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
  595. };
  596. if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes)
  597. {
  598. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  599. SaveConfig();
  600. }
  601. shadersDumpWarningDialog.Dispose();
  602. }
  603. }
  604. private bool LoadApplication(string path, bool isFirmwareTitle)
  605. {
  606. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  607. if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError))
  608. {
  609. if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion))
  610. {
  611. string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})";
  612. ResponseType responseDialog = (ResponseType)GtkDialog.CreateConfirmationDialog("No Firmware Installed", message).Run();
  613. if (responseDialog != ResponseType.Yes || !SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _))
  614. {
  615. UserErrorDialog.CreateUserErrorDialog(userError);
  616. return false;
  617. }
  618. // Tell the user that we installed a firmware for them.
  619. firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  620. RefreshFirmwareLabel();
  621. message = $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start.";
  622. GtkDialog.CreateInfoDialog($"Firmware {firmwareVersion.VersionString} was installed", message);
  623. }
  624. else
  625. {
  626. UserErrorDialog.CreateUserErrorDialog(userError);
  627. return false;
  628. }
  629. }
  630. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  631. if (isFirmwareTitle)
  632. {
  633. Logger.Info?.Print(LogClass.Application, "Loading as Firmware Title (NCA).");
  634. return _emulationContext.LoadNca(path);
  635. }
  636. if (Directory.Exists(path))
  637. {
  638. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  639. if (romFsFiles.Length == 0)
  640. {
  641. romFsFiles = Directory.GetFiles(path, "*.romfs");
  642. }
  643. if (romFsFiles.Length > 0)
  644. {
  645. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  646. return _emulationContext.LoadCart(path, romFsFiles[0]);
  647. }
  648. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  649. return _emulationContext.LoadCart(path);
  650. }
  651. if (File.Exists(path))
  652. {
  653. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  654. {
  655. case ".xci":
  656. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  657. return _emulationContext.LoadXci(path);
  658. case ".nca":
  659. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  660. return _emulationContext.LoadNca(path);
  661. case ".nsp":
  662. case ".pfs0":
  663. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  664. return _emulationContext.LoadNsp(path);
  665. default:
  666. Logger.Info?.Print(LogClass.Application, "Loading as Homebrew.");
  667. try
  668. {
  669. return _emulationContext.LoadProgram(path);
  670. }
  671. catch (ArgumentOutOfRangeException)
  672. {
  673. Logger.Error?.Print(LogClass.Application, "The specified file is not supported by Ryujinx.");
  674. return false;
  675. }
  676. }
  677. }
  678. Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  679. return false;
  680. }
  681. public void RunApplication(string path, bool startFullscreen = false)
  682. {
  683. if (_gameLoaded)
  684. {
  685. GtkDialog.CreateInfoDialog("A game has already been loaded", "Please stop emulation or close the emulator before launching another game.");
  686. }
  687. else
  688. {
  689. PerformanceCheck();
  690. Logger.RestartTime();
  691. RendererWidget = CreateRendererWidget();
  692. SwitchToRenderWidget(startFullscreen);
  693. InitializeSwitchInstance();
  694. UpdateGraphicsConfig();
  695. bool isFirmwareTitle = false;
  696. if (path.StartsWith("@SystemContent"))
  697. {
  698. path = _virtualFileSystem.SwitchPathToSystemPath(path);
  699. isFirmwareTitle = true;
  700. }
  701. if (!LoadApplication(path, isFirmwareTitle))
  702. {
  703. _emulationContext.Dispose();
  704. SwitchToGameTable();
  705. return;
  706. }
  707. SetupProgressUiHandlers();
  708. _currentEmulatedGamePath = path;
  709. _deviceExitStatus.Reset();
  710. Translator.IsReadyForTranslation.Reset();
  711. Thread windowThread = new(CreateGameWindow)
  712. {
  713. Name = "GUI.WindowThread"
  714. };
  715. windowThread.Start();
  716. _gameLoaded = true;
  717. _actionMenu.Sensitive = true;
  718. UpdateMenuItem.Sensitive = false;
  719. _lastScannedAmiiboId = "";
  720. _firmwareInstallFile.Sensitive = false;
  721. _firmwareInstallDirectory.Sensitive = false;
  722. DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Processes.ActiveApplication.ProgramIdText,
  723. _emulationContext.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString());
  724. _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Processes.ActiveApplication.ProgramIdText, appMetadata =>
  725. {
  726. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  727. });
  728. }
  729. }
  730. private RendererWidgetBase CreateRendererWidget()
  731. {
  732. if (ConfigurationState.Instance.Graphics.GraphicsBackend == GraphicsBackend.Vulkan)
  733. {
  734. return new VKRenderer(InputManager, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  735. }
  736. else
  737. {
  738. return new GlRenderer(InputManager, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  739. }
  740. }
  741. private void SwitchToRenderWidget(bool startFullscreen = false)
  742. {
  743. _viewBox.Remove(_gameTableWindow);
  744. RendererWidget.Expand = true;
  745. _viewBox.Child = RendererWidget;
  746. RendererWidget.ShowAll();
  747. EditFooterForGameRenderer();
  748. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  749. {
  750. ToggleExtraWidgets(false);
  751. }
  752. else if (startFullscreen || ConfigurationState.Instance.Ui.StartFullscreen.Value)
  753. {
  754. FullScreen_Toggled(null, null);
  755. }
  756. }
  757. private void SwitchToGameTable()
  758. {
  759. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  760. {
  761. ToggleExtraWidgets(true);
  762. }
  763. RendererWidget.Exit();
  764. if (RendererWidget.Window != Window && RendererWidget.Window != null)
  765. {
  766. RendererWidget.Window.Dispose();
  767. }
  768. RendererWidget.Dispose();
  769. if (OperatingSystem.IsWindows())
  770. {
  771. _windowsMultimediaTimerResolution?.Dispose();
  772. _windowsMultimediaTimerResolution = null;
  773. }
  774. DisplaySleep.Restore();
  775. _viewBox.Remove(RendererWidget);
  776. _viewBox.Add(_gameTableWindow);
  777. _gameTableWindow.Expand = true;
  778. Window.Title = $"Ryujinx {Program.Version}";
  779. _emulationContext = null;
  780. _gameLoaded = false;
  781. RendererWidget = null;
  782. DiscordIntegrationModule.SwitchToMainMenu();
  783. RecreateFooterForMenu();
  784. UpdateColumns();
  785. UpdateGameTable();
  786. RefreshFirmwareLabel();
  787. HandleRelaunch();
  788. }
  789. private void CreateGameWindow()
  790. {
  791. if (OperatingSystem.IsWindows())
  792. {
  793. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  794. }
  795. DisplaySleep.Prevent();
  796. RendererWidget.Initialize(_emulationContext);
  797. RendererWidget.WaitEvent.WaitOne();
  798. RendererWidget.Start();
  799. _emulationContext.Dispose();
  800. _deviceExitStatus.Set();
  801. // NOTE: Everything that is here will not be executed when you close the UI.
  802. Application.Invoke(delegate
  803. {
  804. SwitchToGameTable();
  805. });
  806. }
  807. private void RecreateFooterForMenu()
  808. {
  809. _listStatusBox.Show();
  810. _statusBar.Hide();
  811. }
  812. private void EditFooterForGameRenderer()
  813. {
  814. _listStatusBox.Hide();
  815. _statusBar.Show();
  816. }
  817. public void ToggleExtraWidgets(bool show)
  818. {
  819. if (RendererWidget != null)
  820. {
  821. if (show)
  822. {
  823. _menuBar.ShowAll();
  824. _footerBox.Show();
  825. _statusBar.Show();
  826. }
  827. else
  828. {
  829. _menuBar.Hide();
  830. _footerBox.Hide();
  831. }
  832. }
  833. }
  834. private void UpdateGameMetadata(string titleId)
  835. {
  836. if (_gameLoaded)
  837. {
  838. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  839. {
  840. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  841. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  842. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  843. });
  844. }
  845. }
  846. public void UpdateGraphicsConfig()
  847. {
  848. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  849. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  850. Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
  851. Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  852. Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  853. Graphics.Gpu.GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  854. Graphics.Gpu.GraphicsConfig.EnableTextureRecompression = ConfigurationState.Instance.Graphics.EnableTextureRecompression;
  855. Graphics.Gpu.GraphicsConfig.EnableMacroHLE = ConfigurationState.Instance.Graphics.EnableMacroHLE;
  856. }
  857. public void SaveConfig()
  858. {
  859. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  860. }
  861. private void End()
  862. {
  863. if (_ending)
  864. {
  865. return;
  866. }
  867. _ending = true;
  868. if (_emulationContext != null)
  869. {
  870. UpdateGameMetadata(_emulationContext.Processes.ActiveApplication.ProgramIdText);
  871. if (RendererWidget != null)
  872. {
  873. // We tell the widget that we are exiting.
  874. RendererWidget.Exit();
  875. // Wait for the other thread to dispose the HLE context before exiting.
  876. _deviceExitStatus.WaitOne();
  877. RendererWidget.Dispose();
  878. }
  879. }
  880. Dispose();
  881. Program.Exit();
  882. Application.Quit();
  883. }
  884. //
  885. // Events
  886. //
  887. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  888. {
  889. Application.Invoke(delegate
  890. {
  891. _tableStore.AppendValues(
  892. args.AppData.Favorite,
  893. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  894. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  895. args.AppData.Developer,
  896. args.AppData.Version,
  897. args.AppData.TimePlayed,
  898. args.AppData.LastPlayed,
  899. args.AppData.FileExtension,
  900. args.AppData.FileSize,
  901. args.AppData.Path,
  902. args.AppData.ControlHolder);
  903. });
  904. }
  905. private void ApplicationCount_Updated(object sender, ApplicationCountUpdatedEventArgs args)
  906. {
  907. Application.Invoke(delegate
  908. {
  909. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  910. float barValue = 0;
  911. if (args.NumAppsFound != 0)
  912. {
  913. barValue = (float)args.NumAppsLoaded / args.NumAppsFound;
  914. }
  915. _progressBar.Fraction = barValue;
  916. // Reset the vertical scrollbar to the top when titles finish loading
  917. if (args.NumAppsLoaded == args.NumAppsFound)
  918. {
  919. _gameTableWindow.Vadjustment.Value = 0;
  920. }
  921. });
  922. }
  923. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  924. {
  925. Application.Invoke(delegate
  926. {
  927. _gameStatus.Text = args.GameStatus;
  928. _fifoStatus.Text = args.FifoStatus;
  929. _gpuName.Text = args.GpuName;
  930. _dockedMode.Text = args.DockedMode;
  931. _aspectRatio.Text = args.AspectRatio;
  932. _gpuBackend.Text = args.GpuBackend;
  933. _volumeStatus.Text = GetVolumeLabelText(args.Volume);
  934. if (args.VSyncEnabled)
  935. {
  936. _vSyncStatus.Attributes = new Pango.AttrList();
  937. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(11822, 60138, 51657));
  938. }
  939. else
  940. {
  941. _vSyncStatus.Attributes = new Pango.AttrList();
  942. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(ushort.MaxValue, 17733, 21588));
  943. }
  944. });
  945. }
  946. private void FavToggle_Toggled(object sender, ToggledArgs args)
  947. {
  948. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  949. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  950. bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
  951. _tableStore.SetValue(treeIter, 0, newToggleValue);
  952. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  953. {
  954. appMetadata.Favorite = newToggleValue;
  955. });
  956. }
  957. private void Column_Clicked(object sender, EventArgs args)
  958. {
  959. TreeViewColumn column = (TreeViewColumn)sender;
  960. ConfigurationState.Instance.Ui.ColumnSort.SortColumnId.Value = column.SortColumnId;
  961. ConfigurationState.Instance.Ui.ColumnSort.SortAscending.Value = column.SortOrder == SortType.Ascending;
  962. SaveConfig();
  963. }
  964. private void Row_Activated(object sender, RowActivatedArgs args)
  965. {
  966. _gameTableSelection.GetSelected(out TreeIter treeIter);
  967. string path = (string)_tableStore.GetValue(treeIter, 9);
  968. RunApplication(path);
  969. }
  970. private void VSyncStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  971. {
  972. _emulationContext.EnableDeviceVsync = !_emulationContext.EnableDeviceVsync;
  973. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {_emulationContext.EnableDeviceVsync}");
  974. }
  975. private void DockedMode_Clicked(object sender, ButtonReleaseEventArgs args)
  976. {
  977. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  978. }
  979. private string GetVolumeLabelText(float volume)
  980. {
  981. string icon = volume == 0 ? "🔇" : "🔊";
  982. return $"{icon} {(int)(volume * 100)}%";
  983. }
  984. private void VolumeStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  985. {
  986. if (_emulationContext != null)
  987. {
  988. if (_emulationContext.IsAudioMuted())
  989. {
  990. _emulationContext.SetVolume(ConfigurationState.Instance.System.AudioVolume);
  991. }
  992. else
  993. {
  994. _emulationContext.SetVolume(0);
  995. }
  996. }
  997. }
  998. private void AspectRatio_Clicked(object sender, ButtonReleaseEventArgs args)
  999. {
  1000. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  1001. ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames<AspectRatio>().Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  1002. }
  1003. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  1004. {
  1005. if (args.Event.Button != 3 /* Right Click */)
  1006. {
  1007. return;
  1008. }
  1009. _gameTableSelection.GetSelected(out TreeIter treeIter);
  1010. if (treeIter.UserData == IntPtr.Zero)
  1011. {
  1012. return;
  1013. }
  1014. string titleFilePath = _tableStore.GetValue(treeIter, 9).ToString();
  1015. string titleName = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[0];
  1016. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  1017. BlitStruct<ApplicationControlProperty> controlData = (BlitStruct<ApplicationControlProperty>)_tableStore.GetValue(treeIter, 10);
  1018. _ = new GameTableContextMenu(this, _virtualFileSystem, _accountManager, _libHacHorizonManager.RyujinxClient, titleFilePath, titleName, titleId, controlData);
  1019. }
  1020. private void Load_Application_File(object sender, EventArgs args)
  1021. {
  1022. using (FileChooserNative fileChooser = new FileChooserNative("Choose the file to open", this, FileChooserAction.Open, "Open", "Cancel"))
  1023. {
  1024. FileFilter filter = new FileFilter()
  1025. {
  1026. Name = "Switch Executables"
  1027. };
  1028. filter.AddPattern("*.xci");
  1029. filter.AddPattern("*.nsp");
  1030. filter.AddPattern("*.pfs0");
  1031. filter.AddPattern("*.nca");
  1032. filter.AddPattern("*.nro");
  1033. filter.AddPattern("*.nso");
  1034. fileChooser.AddFilter(filter);
  1035. if (fileChooser.Run() == (int)ResponseType.Accept)
  1036. {
  1037. RunApplication(fileChooser.Filename);
  1038. }
  1039. }
  1040. }
  1041. private void Load_Application_Folder(object sender, EventArgs args)
  1042. {
  1043. using (FileChooserNative fileChooser = new FileChooserNative("Choose the folder to open", this, FileChooserAction.SelectFolder, "Open", "Cancel"))
  1044. {
  1045. if (fileChooser.Run() == (int)ResponseType.Accept)
  1046. {
  1047. RunApplication(fileChooser.Filename);
  1048. }
  1049. }
  1050. }
  1051. private void FileMenu_StateChanged(object o, StateChangedArgs args)
  1052. {
  1053. _appletMenu.Sensitive = _emulationContext == null && _contentManager.GetCurrentFirmwareVersion() != null && _contentManager.GetCurrentFirmwareVersion().Major > 3;
  1054. _loadApplicationFile.Sensitive = _emulationContext == null;
  1055. _loadApplicationFolder.Sensitive = _emulationContext == null;
  1056. }
  1057. private void Load_Mii_Edit_Applet(object sender, EventArgs args)
  1058. {
  1059. string contentPath = _contentManager.GetInstalledContentPath(0x0100000000001009, StorageId.BuiltInSystem, NcaContentType.Program);
  1060. RunApplication(contentPath);
  1061. }
  1062. private void Open_Ryu_Folder(object sender, EventArgs args)
  1063. {
  1064. OpenHelper.OpenFolder(AppDataManager.BaseDirPath);
  1065. }
  1066. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  1067. {
  1068. string logPath = System.IO.Path.Combine(ReleaseInformation.GetBaseApplicationDirectory(), "Logs");
  1069. new DirectoryInfo(logPath).Create();
  1070. OpenHelper.OpenFolder(logPath);
  1071. }
  1072. private void Exit_Pressed(object sender, EventArgs args)
  1073. {
  1074. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  1075. {
  1076. End();
  1077. }
  1078. }
  1079. private void Window_Close(object sender, DeleteEventArgs args)
  1080. {
  1081. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  1082. {
  1083. End();
  1084. }
  1085. else
  1086. {
  1087. args.RetVal = true;
  1088. }
  1089. }
  1090. private void StopEmulation_Pressed(object sender, EventArgs args)
  1091. {
  1092. if (_emulationContext != null)
  1093. {
  1094. UpdateGameMetadata(_emulationContext.Processes.ActiveApplication.ProgramIdText);
  1095. }
  1096. _pauseEmulation.Sensitive = false;
  1097. _resumeEmulation.Sensitive = false;
  1098. UpdateMenuItem.Sensitive = true;
  1099. RendererWidget?.Exit();
  1100. }
  1101. private void PauseEmulation_Pressed(object sender, EventArgs args)
  1102. {
  1103. _pauseEmulation.Sensitive = false;
  1104. _resumeEmulation.Sensitive = true;
  1105. _emulationContext.System.TogglePauseEmulation(true);
  1106. }
  1107. private void ResumeEmulation_Pressed(object sender, EventArgs args)
  1108. {
  1109. _pauseEmulation.Sensitive = true;
  1110. _resumeEmulation.Sensitive = false;
  1111. _emulationContext.System.TogglePauseEmulation(false);
  1112. }
  1113. public void ActivatePauseMenu()
  1114. {
  1115. _pauseEmulation.Sensitive = true;
  1116. _resumeEmulation.Sensitive = false;
  1117. }
  1118. public void TogglePause()
  1119. {
  1120. _pauseEmulation.Sensitive ^= true;
  1121. _resumeEmulation.Sensitive ^= true;
  1122. _emulationContext.System.TogglePauseEmulation(_resumeEmulation.Sensitive);
  1123. }
  1124. private void Installer_File_Pressed(object o, EventArgs args)
  1125. {
  1126. FileChooserNative fileChooser = new FileChooserNative("Choose the firmware file to open", this, FileChooserAction.Open, "Open", "Cancel");
  1127. FileFilter filter = new FileFilter
  1128. {
  1129. Name = "Switch Firmware Files"
  1130. };
  1131. filter.AddPattern("*.zip");
  1132. filter.AddPattern("*.xci");
  1133. fileChooser.AddFilter(filter);
  1134. HandleInstallerDialog(fileChooser);
  1135. }
  1136. private void Installer_Directory_Pressed(object o, EventArgs args)
  1137. {
  1138. FileChooserNative directoryChooser = new FileChooserNative("Choose the firmware directory to open", this, FileChooserAction.SelectFolder, "Open", "Cancel");
  1139. HandleInstallerDialog(directoryChooser);
  1140. }
  1141. private void HandleInstallerDialog(FileChooserNative fileChooser)
  1142. {
  1143. if (fileChooser.Run() == (int)ResponseType.Accept)
  1144. {
  1145. try
  1146. {
  1147. string filename = fileChooser.Filename;
  1148. fileChooser.Dispose();
  1149. SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);
  1150. if (firmwareVersion is null)
  1151. {
  1152. GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}.");
  1153. return;
  1154. }
  1155. string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}";
  1156. SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();
  1157. string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
  1158. if (currentVersion != null)
  1159. {
  1160. dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. ";
  1161. }
  1162. dialogMessage += "\n\nDo you want to continue?";
  1163. ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run();
  1164. MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware...");
  1165. if (responseInstallDialog == ResponseType.Yes)
  1166. {
  1167. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  1168. Thread thread = new Thread(() =>
  1169. {
  1170. Application.Invoke(delegate
  1171. {
  1172. waitingDialog.Run();
  1173. });
  1174. try
  1175. {
  1176. _contentManager.InstallFirmware(filename);
  1177. Application.Invoke(delegate
  1178. {
  1179. waitingDialog.Dispose();
  1180. string message = $"System version {firmwareVersion.VersionString} successfully installed.";
  1181. GtkDialog.CreateInfoDialog(dialogTitle, message);
  1182. Logger.Info?.Print(LogClass.Application, message);
  1183. // Purge Applet Cache.
  1184. DirectoryInfo miiEditorCacheFolder = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, "0100000000001009", "cache"));
  1185. if (miiEditorCacheFolder.Exists)
  1186. {
  1187. miiEditorCacheFolder.Delete(true);
  1188. }
  1189. });
  1190. }
  1191. catch (Exception ex)
  1192. {
  1193. Application.Invoke(delegate
  1194. {
  1195. waitingDialog.Dispose();
  1196. GtkDialog.CreateErrorDialog(ex.Message);
  1197. });
  1198. }
  1199. finally
  1200. {
  1201. RefreshFirmwareLabel();
  1202. }
  1203. });
  1204. thread.Name = "GUI.FirmwareInstallerThread";
  1205. thread.Start();
  1206. }
  1207. }
  1208. catch (MissingKeyException ex)
  1209. {
  1210. Logger.Error?.Print(LogClass.Application, ex.ToString());
  1211. UserErrorDialog.CreateUserErrorDialog(UserError.FirmwareParsingFailed);
  1212. }
  1213. catch (Exception ex)
  1214. {
  1215. GtkDialog.CreateErrorDialog(ex.Message);
  1216. }
  1217. }
  1218. else
  1219. {
  1220. fileChooser.Dispose();
  1221. }
  1222. }
  1223. private void RefreshFirmwareLabel()
  1224. {
  1225. SystemVersion currentFirmware = _contentManager.GetCurrentFirmwareVersion();
  1226. Application.Invoke(delegate
  1227. {
  1228. _firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
  1229. });
  1230. }
  1231. private void InstallFileTypes_Pressed(object sender, EventArgs e)
  1232. {
  1233. if (FileAssociationHelper.Install())
  1234. {
  1235. GtkDialog.CreateInfoDialog("Install file types", "File types successfully installed!");
  1236. }
  1237. else
  1238. {
  1239. GtkDialog.CreateErrorDialog("Failed to install file types.");
  1240. }
  1241. }
  1242. private void UninstallFileTypes_Pressed(object sender, EventArgs e)
  1243. {
  1244. if (FileAssociationHelper.Uninstall())
  1245. {
  1246. GtkDialog.CreateInfoDialog("Uninstall file types", "File types successfully uninstalled!");
  1247. }
  1248. else
  1249. {
  1250. GtkDialog.CreateErrorDialog("Failed to uninstall file types.");
  1251. }
  1252. }
  1253. private void HandleRelaunch()
  1254. {
  1255. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  1256. {
  1257. _userChannelPersistence.ShouldRestart = false;
  1258. RunApplication(_currentEmulatedGamePath);
  1259. }
  1260. else
  1261. {
  1262. // otherwise, clear state.
  1263. _userChannelPersistence = new UserChannelPersistence();
  1264. _currentEmulatedGamePath = null;
  1265. _actionMenu.Sensitive = false;
  1266. _firmwareInstallFile.Sensitive = true;
  1267. _firmwareInstallDirectory.Sensitive = true;
  1268. }
  1269. }
  1270. private void FullScreen_Toggled(object sender, EventArgs args)
  1271. {
  1272. if (!Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  1273. {
  1274. Fullscreen();
  1275. ToggleExtraWidgets(false);
  1276. }
  1277. else
  1278. {
  1279. Unfullscreen();
  1280. ToggleExtraWidgets(true);
  1281. }
  1282. }
  1283. private void StartFullScreen_Toggled(object sender, EventArgs args)
  1284. {
  1285. ConfigurationState.Instance.Ui.StartFullscreen.Value = _startFullScreen.Active;
  1286. SaveConfig();
  1287. }
  1288. private void ShowConsole_Toggled(object sender, EventArgs args)
  1289. {
  1290. ConfigurationState.Instance.Ui.ShowConsole.Value = _showConsole.Active;
  1291. SaveConfig();
  1292. }
  1293. private void OptionMenu_StateChanged(object o, StateChangedArgs args)
  1294. {
  1295. _manageUserProfiles.Sensitive = _emulationContext == null;
  1296. }
  1297. private void Settings_Pressed(object sender, EventArgs args)
  1298. {
  1299. SettingsWindow settingsWindow = new SettingsWindow(this, _virtualFileSystem, _contentManager);
  1300. settingsWindow.SetSizeRequest((int)(settingsWindow.DefaultWidth * Program.WindowScaleFactor), (int)(settingsWindow.DefaultHeight * Program.WindowScaleFactor));
  1301. settingsWindow.Show();
  1302. }
  1303. private void HideUi_Pressed(object sender, EventArgs args)
  1304. {
  1305. ToggleExtraWidgets(false);
  1306. }
  1307. private void ManageCheats_Pressed(object sender, EventArgs args)
  1308. {
  1309. var window = new CheatWindow(_virtualFileSystem,
  1310. _emulationContext.Processes.ActiveApplication.ProgramId,
  1311. _emulationContext.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString());
  1312. window.Destroyed += CheatWindow_Destroyed;
  1313. window.Show();
  1314. }
  1315. private void CheatWindow_Destroyed(object sender, EventArgs e)
  1316. {
  1317. _emulationContext.EnableCheats();
  1318. (sender as CheatWindow).Destroyed -= CheatWindow_Destroyed;
  1319. }
  1320. private void ManageUserProfiles_Pressed(object sender, EventArgs args)
  1321. {
  1322. UserProfilesManagerWindow userProfilesManagerWindow = new UserProfilesManagerWindow(_accountManager, _contentManager, _virtualFileSystem);
  1323. userProfilesManagerWindow.SetSizeRequest((int)(userProfilesManagerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(userProfilesManagerWindow.DefaultHeight * Program.WindowScaleFactor));
  1324. userProfilesManagerWindow.Show();
  1325. }
  1326. private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args)
  1327. {
  1328. if (_emulationContext != null)
  1329. {
  1330. _emulationContext.System.SimulateWakeUpMessage();
  1331. }
  1332. }
  1333. private void ActionMenu_StateChanged(object o, StateChangedArgs args)
  1334. {
  1335. _scanAmiibo.Sensitive = _emulationContext != null && _emulationContext.System.SearchingForAmiibo(out int _);
  1336. _takeScreenshot.Sensitive = _emulationContext != null;
  1337. }
  1338. private void Scan_Amiibo(object sender, EventArgs args)
  1339. {
  1340. if (_emulationContext.System.SearchingForAmiibo(out int deviceId))
  1341. {
  1342. AmiiboWindow amiiboWindow = new AmiiboWindow
  1343. {
  1344. LastScannedAmiiboShowAll = _lastScannedAmiiboShowAll,
  1345. LastScannedAmiiboId = _lastScannedAmiiboId,
  1346. DeviceId = deviceId,
  1347. TitleId = _emulationContext.Processes.ActiveApplication.ProgramIdText.ToUpper()
  1348. };
  1349. amiiboWindow.DeleteEvent += AmiiboWindow_DeleteEvent;
  1350. amiiboWindow.Show();
  1351. }
  1352. else
  1353. {
  1354. 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.");
  1355. }
  1356. }
  1357. private void Take_Screenshot(object sender, EventArgs args)
  1358. {
  1359. if (_emulationContext != null && RendererWidget != null)
  1360. {
  1361. RendererWidget.ScreenshotRequested = true;
  1362. }
  1363. }
  1364. private void AmiiboWindow_DeleteEvent(object sender, DeleteEventArgs args)
  1365. {
  1366. if (((AmiiboWindow)sender).AmiiboId != "" && ((AmiiboWindow)sender).Response == ResponseType.Ok)
  1367. {
  1368. _lastScannedAmiiboId = ((AmiiboWindow)sender).AmiiboId;
  1369. _lastScannedAmiiboShowAll = ((AmiiboWindow)sender).LastScannedAmiiboShowAll;
  1370. _emulationContext.System.ScanAmiibo(((AmiiboWindow)sender).DeviceId, ((AmiiboWindow)sender).AmiiboId, ((AmiiboWindow)sender).UseRandomUuid);
  1371. }
  1372. }
  1373. private void Update_Pressed(object sender, EventArgs args)
  1374. {
  1375. if (Updater.CanUpdate(true))
  1376. {
  1377. Updater.BeginParse(this, true).ContinueWith(task =>
  1378. {
  1379. Logger.Error?.Print(LogClass.Application, $"Updater error: {task.Exception}");
  1380. }, TaskContinuationOptions.OnlyOnFaulted);
  1381. }
  1382. }
  1383. private void About_Pressed(object sender, EventArgs args)
  1384. {
  1385. AboutWindow aboutWindow = new AboutWindow();
  1386. aboutWindow.SetSizeRequest((int)(aboutWindow.DefaultWidth * Program.WindowScaleFactor), (int)(aboutWindow.DefaultHeight * Program.WindowScaleFactor));
  1387. aboutWindow.Show();
  1388. }
  1389. private void Fav_Toggled(object sender, EventArgs args)
  1390. {
  1391. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  1392. SaveConfig();
  1393. UpdateColumns();
  1394. }
  1395. private void Icon_Toggled(object sender, EventArgs args)
  1396. {
  1397. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  1398. SaveConfig();
  1399. UpdateColumns();
  1400. }
  1401. private void App_Toggled(object sender, EventArgs args)
  1402. {
  1403. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  1404. SaveConfig();
  1405. UpdateColumns();
  1406. }
  1407. private void Developer_Toggled(object sender, EventArgs args)
  1408. {
  1409. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  1410. SaveConfig();
  1411. UpdateColumns();
  1412. }
  1413. private void Version_Toggled(object sender, EventArgs args)
  1414. {
  1415. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  1416. SaveConfig();
  1417. UpdateColumns();
  1418. }
  1419. private void TimePlayed_Toggled(object sender, EventArgs args)
  1420. {
  1421. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  1422. SaveConfig();
  1423. UpdateColumns();
  1424. }
  1425. private void LastPlayed_Toggled(object sender, EventArgs args)
  1426. {
  1427. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  1428. SaveConfig();
  1429. UpdateColumns();
  1430. }
  1431. private void FileExt_Toggled(object sender, EventArgs args)
  1432. {
  1433. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  1434. SaveConfig();
  1435. UpdateColumns();
  1436. }
  1437. private void FileSize_Toggled(object sender, EventArgs args)
  1438. {
  1439. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  1440. SaveConfig();
  1441. UpdateColumns();
  1442. }
  1443. private void Path_Toggled(object sender, EventArgs args)
  1444. {
  1445. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  1446. SaveConfig();
  1447. UpdateColumns();
  1448. }
  1449. private void NSP_Shown_Toggled(object sender, EventArgs args)
  1450. {
  1451. ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value = _nspShown.Active;
  1452. SaveConfig();
  1453. UpdateGameTable();
  1454. }
  1455. private void PFS0_Shown_Toggled(object sender, EventArgs args)
  1456. {
  1457. ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value = _pfs0Shown.Active;
  1458. SaveConfig();
  1459. UpdateGameTable();
  1460. }
  1461. private void XCI_Shown_Toggled (object sender, EventArgs args)
  1462. {
  1463. ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value = _xciShown.Active;
  1464. SaveConfig();
  1465. UpdateGameTable();
  1466. }
  1467. private void NCA_Shown_Toggled (object sender, EventArgs args)
  1468. {
  1469. ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value = _ncaShown.Active;
  1470. SaveConfig();
  1471. UpdateGameTable();
  1472. }
  1473. private void NRO_Shown_Toggled (object sender, EventArgs args)
  1474. {
  1475. ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value = _nroShown.Active;
  1476. SaveConfig();
  1477. UpdateGameTable();
  1478. }
  1479. private void NSO_Shown_Toggled (object sender, EventArgs args)
  1480. {
  1481. ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value = _nsoShown.Active;
  1482. SaveConfig();
  1483. UpdateGameTable();
  1484. }
  1485. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  1486. {
  1487. UpdateGameTable();
  1488. }
  1489. }
  1490. }