MainWindow.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. using ARMeilleure.Translation;
  2. using ARMeilleure.Translation.PTC;
  3. using Gtk;
  4. using LibHac.Common;
  5. using LibHac.Ns;
  6. using Ryujinx.Audio;
  7. using Ryujinx.Audio.Backends.Dummy;
  8. using Ryujinx.Audio.Backends.OpenAL;
  9. using Ryujinx.Audio.Backends.SoundIo;
  10. using Ryujinx.Audio.Integration;
  11. using Ryujinx.Common.Configuration;
  12. using Ryujinx.Common.Logging;
  13. using Ryujinx.Common.System;
  14. using Ryujinx.Configuration;
  15. using Ryujinx.Graphics.GAL;
  16. using Ryujinx.Graphics.OpenGL;
  17. using Ryujinx.HLE.FileSystem;
  18. using Ryujinx.HLE.FileSystem.Content;
  19. using Ryujinx.HLE.HOS;
  20. using Ryujinx.Modules;
  21. using Ryujinx.Ui.App;
  22. using Ryujinx.Ui.Applet;
  23. using Ryujinx.Ui.Helper;
  24. using Ryujinx.Ui.Widgets;
  25. using Ryujinx.Ui.Windows;
  26. using System;
  27. using System.Diagnostics;
  28. using System.IO;
  29. using System.Reflection;
  30. using System.Runtime.InteropServices;
  31. using System.Threading;
  32. using System.Threading.Tasks;
  33. using GUI = Gtk.Builder.ObjectAttribute;
  34. namespace Ryujinx.Ui
  35. {
  36. public class MainWindow : Window
  37. {
  38. private readonly VirtualFileSystem _virtualFileSystem;
  39. private readonly ContentManager _contentManager;
  40. private UserChannelPersistence _userChannelPersistence;
  41. private HLE.Switch _emulationContext;
  42. private WindowsMultimediaTimerResolution _windowsMultimediaTimerResolution;
  43. private readonly ApplicationLibrary _applicationLibrary;
  44. private readonly GtkHostUiHandler _uiHandler;
  45. private readonly AutoResetEvent _deviceExitStatus;
  46. private readonly ListStore _tableStore;
  47. private bool _updatingGameTable;
  48. private bool _gameLoaded;
  49. private bool _ending;
  50. private string _currentEmulatedGamePath = null;
  51. private string _lastScannedAmiiboId = "";
  52. private bool _lastScannedAmiiboShowAll = false;
  53. public GlRenderer GlRendererWidget;
  54. #pragma warning disable CS0169, CS0649, IDE0044
  55. [GUI] public MenuItem ExitMenuItem;
  56. [GUI] public MenuItem UpdateMenuItem;
  57. [GUI] MenuBar _menuBar;
  58. [GUI] Box _footerBox;
  59. [GUI] Box _statusBar;
  60. [GUI] MenuItem _optionMenu;
  61. [GUI] MenuItem _actionMenu;
  62. [GUI] MenuItem _stopEmulation;
  63. [GUI] MenuItem _simulateWakeUpMessage;
  64. [GUI] MenuItem _scanAmiibo;
  65. [GUI] MenuItem _fullScreen;
  66. [GUI] CheckMenuItem _startFullScreen;
  67. [GUI] CheckMenuItem _favToggle;
  68. [GUI] MenuItem _firmwareInstallDirectory;
  69. [GUI] MenuItem _firmwareInstallFile;
  70. [GUI] Label _fifoStatus;
  71. [GUI] CheckMenuItem _iconToggle;
  72. [GUI] CheckMenuItem _developerToggle;
  73. [GUI] CheckMenuItem _appToggle;
  74. [GUI] CheckMenuItem _timePlayedToggle;
  75. [GUI] CheckMenuItem _versionToggle;
  76. [GUI] CheckMenuItem _lastPlayedToggle;
  77. [GUI] CheckMenuItem _fileExtToggle;
  78. [GUI] CheckMenuItem _pathToggle;
  79. [GUI] CheckMenuItem _fileSizeToggle;
  80. [GUI] Label _dockedMode;
  81. [GUI] Label _aspectRatio;
  82. [GUI] Label _gameStatus;
  83. [GUI] TreeView _gameTable;
  84. [GUI] TreeSelection _gameTableSelection;
  85. [GUI] ScrolledWindow _gameTableWindow;
  86. [GUI] Label _gpuName;
  87. [GUI] Label _progressLabel;
  88. [GUI] Label _firmwareVersionLabel;
  89. [GUI] ProgressBar _progressBar;
  90. [GUI] Box _viewBox;
  91. [GUI] Label _vSyncStatus;
  92. [GUI] Box _listStatusBox;
  93. [GUI] Label _loadingStatusLabel;
  94. [GUI] ProgressBar _loadingStatusBar;
  95. private string _loadingStatusTitle = "";
  96. #pragma warning restore CS0649, IDE0044, CS0169
  97. public MainWindow() : this(new Builder("Ryujinx.Ui.MainWindow.glade")) { }
  98. private MainWindow(Builder builder) : base(builder.GetObject("_mainWin").Handle)
  99. {
  100. builder.Autoconnect(this);
  101. // Apply custom theme if needed.
  102. ThemeHelper.ApplyTheme();
  103. // Sets overridden fields.
  104. int monitorWidth = Display.PrimaryMonitor.Geometry.Width * Display.PrimaryMonitor.ScaleFactor;
  105. int monitorHeight = Display.PrimaryMonitor.Geometry.Height * Display.PrimaryMonitor.ScaleFactor;
  106. DefaultWidth = monitorWidth < 1280 ? monitorWidth : 1280;
  107. DefaultHeight = monitorHeight < 760 ? monitorHeight : 760;
  108. Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.Resources.Logo_Ryujinx.png");
  109. Title = $"Ryujinx {Program.Version}";
  110. // Hide emulation context status bar.
  111. _statusBar.Hide();
  112. // Instanciate HLE objects.
  113. _virtualFileSystem = VirtualFileSystem.CreateInstance();
  114. _contentManager = new ContentManager(_virtualFileSystem);
  115. _userChannelPersistence = new UserChannelPersistence();
  116. // Instanciate GUI objects.
  117. _applicationLibrary = new ApplicationLibrary(_virtualFileSystem);
  118. _uiHandler = new GtkHostUiHandler(this);
  119. _deviceExitStatus = new AutoResetEvent(false);
  120. WindowStateEvent += WindowStateEvent_Changed;
  121. DeleteEvent += Window_Close;
  122. _applicationLibrary.ApplicationAdded += Application_Added;
  123. _applicationLibrary.ApplicationCountUpdated += ApplicationCount_Updated;
  124. _actionMenu.StateChanged += ActionMenu_StateChanged;
  125. _gameTable.ButtonReleaseEvent += Row_Clicked;
  126. _fullScreen.Activated += FullScreen_Toggled;
  127. GlRenderer.StatusUpdatedEvent += Update_StatusBar;
  128. if (ConfigurationState.Instance.Ui.StartFullscreen)
  129. {
  130. _startFullScreen.Active = true;
  131. }
  132. _actionMenu.Sensitive = false;
  133. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _favToggle.Active = true;
  134. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _iconToggle.Active = true;
  135. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _appToggle.Active = true;
  136. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _developerToggle.Active = true;
  137. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _versionToggle.Active = true;
  138. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _timePlayedToggle.Active = true;
  139. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _lastPlayedToggle.Active = true;
  140. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _fileExtToggle.Active = true;
  141. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _fileSizeToggle.Active = true;
  142. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _pathToggle.Active = true;
  143. _favToggle.Toggled += Fav_Toggled;
  144. _iconToggle.Toggled += Icon_Toggled;
  145. _appToggle.Toggled += App_Toggled;
  146. _developerToggle.Toggled += Developer_Toggled;
  147. _versionToggle.Toggled += Version_Toggled;
  148. _timePlayedToggle.Toggled += TimePlayed_Toggled;
  149. _lastPlayedToggle.Toggled += LastPlayed_Toggled;
  150. _fileExtToggle.Toggled += FileExt_Toggled;
  151. _fileSizeToggle.Toggled += FileSize_Toggled;
  152. _pathToggle.Toggled += Path_Toggled;
  153. _gameTable.Model = _tableStore = new ListStore(
  154. typeof(bool),
  155. typeof(Gdk.Pixbuf),
  156. typeof(string),
  157. typeof(string),
  158. typeof(string),
  159. typeof(string),
  160. typeof(string),
  161. typeof(string),
  162. typeof(string),
  163. typeof(string),
  164. typeof(BlitStruct<ApplicationControlProperty>));
  165. _tableStore.SetSortFunc(5, SortHelper.TimePlayedSort);
  166. _tableStore.SetSortFunc(6, SortHelper.LastPlayedSort);
  167. _tableStore.SetSortFunc(8, SortHelper.FileSizeSort);
  168. int columnId = ConfigurationState.Instance.Ui.ColumnSort.SortColumnId;
  169. bool ascending = ConfigurationState.Instance.Ui.ColumnSort.SortAscending;
  170. _tableStore.SetSortColumnId(columnId, ascending ? SortType.Ascending : SortType.Descending);
  171. _gameTable.EnableSearch = true;
  172. _gameTable.SearchColumn = 2;
  173. UpdateColumns();
  174. UpdateGameTable();
  175. ConfigurationState.Instance.Ui.GameDirs.Event += (sender, args) =>
  176. {
  177. if (args.OldValue != args.NewValue)
  178. {
  179. UpdateGameTable();
  180. }
  181. };
  182. Task.Run(RefreshFirmwareLabel);
  183. }
  184. private void WindowStateEvent_Changed(object o, WindowStateEventArgs args)
  185. {
  186. _fullScreen.Label = args.Event.NewWindowState.HasFlag(Gdk.WindowState.Fullscreen) ? "Exit Fullscreen" : "Enter Fullscreen";
  187. }
  188. private void UpdateColumns()
  189. {
  190. foreach (TreeViewColumn column in _gameTable.Columns)
  191. {
  192. _gameTable.RemoveColumn(column);
  193. }
  194. CellRendererToggle favToggle = new CellRendererToggle();
  195. favToggle.Toggled += FavToggle_Toggled;
  196. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _gameTable.AppendColumn("Fav", favToggle, "active", 0);
  197. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1);
  198. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2);
  199. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3);
  200. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _gameTable.AppendColumn("Version", new CellRendererText(), "text", 4);
  201. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _gameTable.AppendColumn("Time Played", new CellRendererText(), "text", 5);
  202. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _gameTable.AppendColumn("Last Played", new CellRendererText(), "text", 6);
  203. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _gameTable.AppendColumn("File Ext", new CellRendererText(), "text", 7);
  204. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _gameTable.AppendColumn("File Size", new CellRendererText(), "text", 8);
  205. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _gameTable.AppendColumn("Path", new CellRendererText(), "text", 9);
  206. foreach (TreeViewColumn column in _gameTable.Columns)
  207. {
  208. switch (column.Title)
  209. {
  210. case "Fav":
  211. column.SortColumnId = 0;
  212. column.Clicked += Column_Clicked;
  213. break;
  214. case "Application":
  215. column.SortColumnId = 2;
  216. column.Clicked += Column_Clicked;
  217. break;
  218. case "Developer":
  219. column.SortColumnId = 3;
  220. column.Clicked += Column_Clicked;
  221. break;
  222. case "Version":
  223. column.SortColumnId = 4;
  224. column.Clicked += Column_Clicked;
  225. break;
  226. case "Time Played":
  227. column.SortColumnId = 5;
  228. column.Clicked += Column_Clicked;
  229. break;
  230. case "Last Played":
  231. column.SortColumnId = 6;
  232. column.Clicked += Column_Clicked;
  233. break;
  234. case "File Ext":
  235. column.SortColumnId = 7;
  236. column.Clicked += Column_Clicked;
  237. break;
  238. case "File Size":
  239. column.SortColumnId = 8;
  240. column.Clicked += Column_Clicked;
  241. break;
  242. case "Path":
  243. column.SortColumnId = 9;
  244. column.Clicked += Column_Clicked;
  245. break;
  246. }
  247. }
  248. }
  249. private void InitializeSwitchInstance()
  250. {
  251. _virtualFileSystem.Reload();
  252. IRenderer renderer = new Renderer();
  253. IHardwareDeviceDriver deviceDriver = new DummyHardwareDeviceDriver();
  254. if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.SoundIo)
  255. {
  256. if (SoundIoHardwareDeviceDriver.IsSupported)
  257. {
  258. deviceDriver = new SoundIoHardwareDeviceDriver();
  259. }
  260. else
  261. {
  262. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  263. }
  264. }
  265. else if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.OpenAl)
  266. {
  267. if (OpenALHardwareDeviceDriver.IsSupported)
  268. {
  269. deviceDriver = new OpenALHardwareDeviceDriver();
  270. }
  271. else
  272. {
  273. Logger.Warning?.Print(LogClass.Audio, "OpenAL is not supported, trying to fall back to SoundIO.");
  274. if (SoundIoHardwareDeviceDriver.IsSupported)
  275. {
  276. Logger.Warning?.Print(LogClass.Audio, "Found SoundIO, changing configuration.");
  277. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SoundIo;
  278. SaveConfig();
  279. deviceDriver = new SoundIoHardwareDeviceDriver();
  280. }
  281. else
  282. {
  283. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  284. }
  285. }
  286. }
  287. _emulationContext = new HLE.Switch(_virtualFileSystem, _contentManager, _userChannelPersistence, renderer, deviceDriver)
  288. {
  289. UiHandler = _uiHandler
  290. };
  291. _emulationContext.Initialize();
  292. }
  293. private void SetupProgressUiHandlers()
  294. {
  295. Ptc.PtcTranslationStateChanged -= PtcStatusChanged;
  296. Ptc.PtcTranslationStateChanged += PtcStatusChanged;
  297. Ptc.PtcTranslationProgressChanged -= LoadingProgressChanged;
  298. Ptc.PtcTranslationProgressChanged += LoadingProgressChanged;
  299. _emulationContext.Gpu.ShaderCacheStateChanged -= ShaderCacheStatusChanged;
  300. _emulationContext.Gpu.ShaderCacheStateChanged += ShaderCacheStatusChanged;
  301. _emulationContext.Gpu.ShaderCacheProgressChanged -= LoadingProgressChanged;
  302. _emulationContext.Gpu.ShaderCacheProgressChanged += LoadingProgressChanged;
  303. }
  304. private void ShaderCacheStatusChanged(bool state)
  305. {
  306. _loadingStatusTitle = "Shaders";
  307. Application.Invoke(delegate
  308. {
  309. _loadingStatusBar.Visible = _loadingStatusLabel.Visible = state;
  310. });
  311. }
  312. private void PtcStatusChanged(bool state)
  313. {
  314. _loadingStatusTitle = "PTC";
  315. Application.Invoke(delegate
  316. {
  317. _loadingStatusBar.Visible = _loadingStatusLabel.Visible = state;
  318. });
  319. }
  320. private void LoadingProgressChanged(int value, int total)
  321. {
  322. Application.Invoke(delegate
  323. {
  324. _loadingStatusBar.Fraction = (double)value / total;
  325. _loadingStatusLabel.Text = $"{_loadingStatusTitle} : {value}/{total}";
  326. });
  327. }
  328. public void UpdateGameTable()
  329. {
  330. if (_updatingGameTable || _gameLoaded)
  331. {
  332. return;
  333. }
  334. _updatingGameTable = true;
  335. _tableStore.Clear();
  336. Thread applicationLibraryThread = new Thread(() =>
  337. {
  338. _applicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language);
  339. _updatingGameTable = false;
  340. });
  341. applicationLibraryThread.Name = "GUI.ApplicationLibraryThread";
  342. applicationLibraryThread.IsBackground = true;
  343. applicationLibraryThread.Start();
  344. }
  345. [Conditional("RELEASE")]
  346. public void PerformanceCheck()
  347. {
  348. if (ConfigurationState.Instance.Logger.EnableDebug.Value)
  349. {
  350. MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  351. {
  352. Title = "Ryujinx - Warning",
  353. Text = "You have debug logging enabled, which is designed to be used by developers only.",
  354. SecondaryText = "For optimal performance, it's recommended to disable debug logging. Would you like to disable debug logging now?"
  355. };
  356. if (debugWarningDialog.Run() == (int)ResponseType.Yes)
  357. {
  358. ConfigurationState.Instance.Logger.EnableDebug.Value = false;
  359. SaveConfig();
  360. }
  361. debugWarningDialog.Dispose();
  362. }
  363. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  364. {
  365. MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  366. {
  367. Title = "Ryujinx - Warning",
  368. Text = "You have shader dumping enabled, which is designed to be used by developers only.",
  369. SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
  370. };
  371. if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes)
  372. {
  373. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  374. SaveConfig();
  375. }
  376. shadersDumpWarningDialog.Dispose();
  377. }
  378. }
  379. public void LoadApplication(string path)
  380. {
  381. if (_gameLoaded)
  382. {
  383. GtkDialog.CreateInfoDialog("A game has already been loaded", "Please stop emulation or close the emulator before launching another game.");
  384. }
  385. else
  386. {
  387. PerformanceCheck();
  388. Logger.RestartTime();
  389. InitializeSwitchInstance();
  390. UpdateGraphicsConfig();
  391. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  392. bool isDirectory = Directory.Exists(path);
  393. if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError))
  394. {
  395. if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion))
  396. {
  397. if (userError == UserError.NoFirmware)
  398. {
  399. string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})";
  400. ResponseType responseDialog = (ResponseType)GtkDialog.CreateConfirmationDialog("No Firmware Installed", message).Run();
  401. if (responseDialog != ResponseType.Yes)
  402. {
  403. UserErrorDialog.CreateUserErrorDialog(userError);
  404. _emulationContext.Dispose();
  405. return;
  406. }
  407. }
  408. if (!SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _))
  409. {
  410. UserErrorDialog.CreateUserErrorDialog(userError);
  411. _emulationContext.Dispose();
  412. return;
  413. }
  414. // Tell the user that we installed a firmware for them.
  415. if (userError == UserError.NoFirmware)
  416. {
  417. firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  418. RefreshFirmwareLabel();
  419. string message = $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start.";
  420. GtkDialog.CreateInfoDialog($"Firmware {firmwareVersion.VersionString} was installed", message);
  421. }
  422. }
  423. else
  424. {
  425. UserErrorDialog.CreateUserErrorDialog(userError);
  426. _emulationContext.Dispose();
  427. return;
  428. }
  429. }
  430. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  431. if (Directory.Exists(path))
  432. {
  433. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  434. if (romFsFiles.Length == 0)
  435. {
  436. romFsFiles = Directory.GetFiles(path, "*.romfs");
  437. }
  438. if (romFsFiles.Length > 0)
  439. {
  440. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  441. _emulationContext.LoadCart(path, romFsFiles[0]);
  442. }
  443. else
  444. {
  445. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  446. _emulationContext.LoadCart(path);
  447. }
  448. }
  449. else if (File.Exists(path))
  450. {
  451. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  452. {
  453. case ".xci":
  454. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  455. _emulationContext.LoadXci(path);
  456. break;
  457. case ".nca":
  458. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  459. _emulationContext.LoadNca(path);
  460. break;
  461. case ".nsp":
  462. case ".pfs0":
  463. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  464. _emulationContext.LoadNsp(path);
  465. break;
  466. default:
  467. Logger.Info?.Print(LogClass.Application, "Loading as Homebrew.");
  468. try
  469. {
  470. _emulationContext.LoadProgram(path);
  471. }
  472. catch (ArgumentOutOfRangeException)
  473. {
  474. Logger.Error?.Print(LogClass.Application, "The specified file is not supported by Ryujinx.");
  475. }
  476. break;
  477. }
  478. }
  479. else
  480. {
  481. Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  482. _emulationContext.Dispose();
  483. return;
  484. }
  485. _currentEmulatedGamePath = path;
  486. _deviceExitStatus.Reset();
  487. SetupProgressUiHandlers();
  488. Translator.IsReadyForTranslation.Reset();
  489. #if MACOS_BUILD
  490. CreateGameWindow();
  491. #else
  492. Thread windowThread = new Thread(() =>
  493. {
  494. CreateGameWindow();
  495. })
  496. {
  497. Name = "GUI.WindowThread"
  498. };
  499. windowThread.Start();
  500. #endif
  501. _gameLoaded = true;
  502. _actionMenu.Sensitive = true;
  503. _lastScannedAmiiboId = "";
  504. _firmwareInstallFile.Sensitive = false;
  505. _firmwareInstallDirectory.Sensitive = false;
  506. DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Application.TitleIdText, _emulationContext.Application.TitleName);
  507. _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Application.TitleIdText, appMetadata =>
  508. {
  509. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  510. });
  511. }
  512. }
  513. private void CreateGameWindow()
  514. {
  515. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  516. {
  517. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  518. }
  519. DisplaySleep.Prevent();
  520. GlRendererWidget = new GlRenderer(_emulationContext, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  521. Application.Invoke(delegate
  522. {
  523. _viewBox.Remove(_gameTableWindow);
  524. GlRendererWidget.Expand = true;
  525. _viewBox.Child = GlRendererWidget;
  526. GlRendererWidget.ShowAll();
  527. EditFooterForGameRenderer();
  528. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  529. {
  530. ToggleExtraWidgets(false);
  531. }
  532. else if (ConfigurationState.Instance.Ui.StartFullscreen.Value)
  533. {
  534. FullScreen_Toggled(null, null);
  535. }
  536. });
  537. GlRendererWidget.WaitEvent.WaitOne();
  538. GlRendererWidget.Start();
  539. Ptc.Close();
  540. PtcProfiler.Stop();
  541. _emulationContext.Dispose();
  542. _deviceExitStatus.Set();
  543. // NOTE: Everything that is here will not be executed when you close the UI.
  544. Application.Invoke(delegate
  545. {
  546. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  547. {
  548. ToggleExtraWidgets(true);
  549. }
  550. GlRendererWidget.Exit();
  551. if(GlRendererWidget.Window != Window && GlRendererWidget.Window != null)
  552. {
  553. GlRendererWidget.Window.Dispose();
  554. }
  555. GlRendererWidget.Dispose();
  556. _windowsMultimediaTimerResolution?.Dispose();
  557. _windowsMultimediaTimerResolution = null;
  558. DisplaySleep.Restore();
  559. _viewBox.Remove(GlRendererWidget);
  560. _viewBox.Add(_gameTableWindow);
  561. _gameTableWindow.Expand = true;
  562. Window.Title = $"Ryujinx {Program.Version}";
  563. _emulationContext = null;
  564. _gameLoaded = false;
  565. GlRendererWidget = null;
  566. DiscordIntegrationModule.SwitchToMainMenu();
  567. RecreateFooterForMenu();
  568. UpdateColumns();
  569. UpdateGameTable();
  570. Task.Run(RefreshFirmwareLabel);
  571. Task.Run(HandleRelaunch);
  572. _actionMenu.Sensitive = false;
  573. _firmwareInstallFile.Sensitive = true;
  574. _firmwareInstallDirectory.Sensitive = true;
  575. });
  576. }
  577. private void RecreateFooterForMenu()
  578. {
  579. _listStatusBox.Show();
  580. _statusBar.Hide();
  581. }
  582. private void EditFooterForGameRenderer()
  583. {
  584. _listStatusBox.Hide();
  585. _statusBar.Show();
  586. }
  587. public void ToggleExtraWidgets(bool show)
  588. {
  589. if (GlRendererWidget != null)
  590. {
  591. if (show)
  592. {
  593. _menuBar.ShowAll();
  594. _footerBox.Show();
  595. _statusBar.Show();
  596. }
  597. else
  598. {
  599. _menuBar.Hide();
  600. _footerBox.Hide();
  601. }
  602. }
  603. }
  604. private void UpdateGameMetadata(string titleId)
  605. {
  606. if (_gameLoaded)
  607. {
  608. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  609. {
  610. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  611. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  612. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  613. });
  614. }
  615. }
  616. public void UpdateGraphicsConfig()
  617. {
  618. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  619. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  620. Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
  621. Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  622. Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  623. Graphics.Gpu.GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  624. }
  625. public void SaveConfig()
  626. {
  627. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  628. }
  629. private void End()
  630. {
  631. if (_ending)
  632. {
  633. return;
  634. }
  635. _ending = true;
  636. if (_emulationContext != null)
  637. {
  638. UpdateGameMetadata(_emulationContext.Application.TitleIdText);
  639. if (GlRendererWidget != null)
  640. {
  641. // We tell the widget that we are exiting.
  642. GlRendererWidget.Exit();
  643. // Wait for the other thread to dispose the HLE context before exiting.
  644. _deviceExitStatus.WaitOne();
  645. GlRendererWidget.Dispose();
  646. }
  647. }
  648. Dispose();
  649. Program.Exit();
  650. Application.Quit();
  651. }
  652. //
  653. // Events
  654. //
  655. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  656. {
  657. Application.Invoke(delegate
  658. {
  659. _tableStore.AppendValues(
  660. args.AppData.Favorite,
  661. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  662. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  663. args.AppData.Developer,
  664. args.AppData.Version,
  665. args.AppData.TimePlayed,
  666. args.AppData.LastPlayed,
  667. args.AppData.FileExtension,
  668. args.AppData.FileSize,
  669. args.AppData.Path,
  670. args.AppData.ControlHolder);
  671. });
  672. }
  673. private void ApplicationCount_Updated(object sender, ApplicationCountUpdatedEventArgs args)
  674. {
  675. Application.Invoke(delegate
  676. {
  677. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  678. float barValue = 0;
  679. if (args.NumAppsFound != 0)
  680. {
  681. barValue = (float)args.NumAppsLoaded / args.NumAppsFound;
  682. }
  683. _progressBar.Fraction = barValue;
  684. // Reset the vertical scrollbar to the top when titles finish loading
  685. if (args.NumAppsLoaded == args.NumAppsFound)
  686. {
  687. _gameTableWindow.Vadjustment.Value = 0;
  688. }
  689. });
  690. }
  691. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  692. {
  693. Application.Invoke(delegate
  694. {
  695. _gameStatus.Text = args.GameStatus;
  696. _fifoStatus.Text = args.FifoStatus;
  697. _gpuName.Text = args.GpuName;
  698. _dockedMode.Text = args.DockedMode;
  699. _aspectRatio.Text = args.AspectRatio;
  700. if (args.VSyncEnabled)
  701. {
  702. _vSyncStatus.Attributes = new Pango.AttrList();
  703. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(11822, 60138, 51657));
  704. }
  705. else
  706. {
  707. _vSyncStatus.Attributes = new Pango.AttrList();
  708. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(ushort.MaxValue, 17733, 21588));
  709. }
  710. });
  711. }
  712. private void FavToggle_Toggled(object sender, ToggledArgs args)
  713. {
  714. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  715. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  716. bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
  717. _tableStore.SetValue(treeIter, 0, newToggleValue);
  718. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  719. {
  720. appMetadata.Favorite = newToggleValue;
  721. });
  722. }
  723. private void Column_Clicked(object sender, EventArgs args)
  724. {
  725. TreeViewColumn column = (TreeViewColumn)sender;
  726. ConfigurationState.Instance.Ui.ColumnSort.SortColumnId.Value = column.SortColumnId;
  727. ConfigurationState.Instance.Ui.ColumnSort.SortAscending.Value = column.SortOrder == SortType.Ascending;
  728. SaveConfig();
  729. }
  730. private void Row_Activated(object sender, RowActivatedArgs args)
  731. {
  732. _gameTableSelection.GetSelected(out TreeIter treeIter);
  733. string path = (string)_tableStore.GetValue(treeIter, 9);
  734. LoadApplication(path);
  735. }
  736. private void VSyncStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  737. {
  738. _emulationContext.EnableDeviceVsync = !_emulationContext.EnableDeviceVsync;
  739. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {_emulationContext.EnableDeviceVsync}");
  740. }
  741. private void DockedMode_Clicked(object sender, ButtonReleaseEventArgs args)
  742. {
  743. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  744. }
  745. private void AspectRatio_Clicked(object sender, ButtonReleaseEventArgs args)
  746. {
  747. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  748. ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  749. }
  750. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  751. {
  752. if (args.Event.Button != 3 /* Right Click */)
  753. {
  754. return;
  755. }
  756. _gameTableSelection.GetSelected(out TreeIter treeIter);
  757. if (treeIter.UserData == IntPtr.Zero)
  758. {
  759. return;
  760. }
  761. string titleFilePath = _tableStore.GetValue(treeIter, 9).ToString();
  762. string titleName = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[0];
  763. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  764. BlitStruct<ApplicationControlProperty> controlData = (BlitStruct<ApplicationControlProperty>)_tableStore.GetValue(treeIter, 10);
  765. _ = new GameTableContextMenu(this, _virtualFileSystem, titleFilePath, titleName, titleId, controlData);
  766. }
  767. private void Load_Application_File(object sender, EventArgs args)
  768. {
  769. using (FileChooserDialog fileChooser = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept))
  770. {
  771. fileChooser.Filter = new FileFilter();
  772. fileChooser.Filter.AddPattern("*.nsp");
  773. fileChooser.Filter.AddPattern("*.pfs0");
  774. fileChooser.Filter.AddPattern("*.xci");
  775. fileChooser.Filter.AddPattern("*.nca");
  776. fileChooser.Filter.AddPattern("*.nro");
  777. fileChooser.Filter.AddPattern("*.nso");
  778. if (fileChooser.Run() == (int)ResponseType.Accept)
  779. {
  780. LoadApplication(fileChooser.Filename);
  781. }
  782. }
  783. }
  784. private void Load_Application_Folder(object sender, EventArgs args)
  785. {
  786. using (FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept))
  787. {
  788. if (fileChooser.Run() == (int)ResponseType.Accept)
  789. {
  790. LoadApplication(fileChooser.Filename);
  791. }
  792. }
  793. }
  794. private void Open_Ryu_Folder(object sender, EventArgs args)
  795. {
  796. OpenHelper.OpenFolder(AppDataManager.BaseDirPath);
  797. }
  798. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  799. {
  800. string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  801. new DirectoryInfo(logPath).Create();
  802. OpenHelper.OpenFolder(logPath);
  803. }
  804. private void Exit_Pressed(object sender, EventArgs args)
  805. {
  806. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  807. {
  808. End();
  809. }
  810. }
  811. private void Window_Close(object sender, DeleteEventArgs args)
  812. {
  813. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  814. {
  815. End();
  816. }
  817. else
  818. {
  819. args.RetVal = true;
  820. }
  821. }
  822. private void StopEmulation_Pressed(object sender, EventArgs args)
  823. {
  824. GlRendererWidget?.Exit();
  825. }
  826. private void Installer_File_Pressed(object o, EventArgs args)
  827. {
  828. FileChooserDialog fileChooser = new FileChooserDialog("Choose the firmware file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  829. fileChooser.Filter = new FileFilter();
  830. fileChooser.Filter.AddPattern("*.zip");
  831. fileChooser.Filter.AddPattern("*.xci");
  832. HandleInstallerDialog(fileChooser);
  833. }
  834. private void Installer_Directory_Pressed(object o, EventArgs args)
  835. {
  836. FileChooserDialog directoryChooser = new FileChooserDialog("Choose the firmware directory to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  837. HandleInstallerDialog(directoryChooser);
  838. }
  839. private void HandleInstallerDialog(FileChooserDialog fileChooser)
  840. {
  841. if (fileChooser.Run() == (int)ResponseType.Accept)
  842. {
  843. try
  844. {
  845. string filename = fileChooser.Filename;
  846. fileChooser.Dispose();
  847. SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);
  848. string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}";
  849. if (firmwareVersion == null)
  850. {
  851. GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}.");
  852. return;
  853. }
  854. SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();
  855. string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
  856. if (currentVersion != null)
  857. {
  858. dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. ";
  859. }
  860. dialogMessage += "\n\nDo you want to continue?";
  861. ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run();
  862. MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware...");
  863. if (responseInstallDialog == ResponseType.Yes)
  864. {
  865. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  866. Thread thread = new Thread(() =>
  867. {
  868. Application.Invoke(delegate
  869. {
  870. waitingDialog.Run();
  871. });
  872. try
  873. {
  874. _contentManager.InstallFirmware(filename);
  875. Application.Invoke(delegate
  876. {
  877. waitingDialog.Dispose();
  878. string message = $"System version {firmwareVersion.VersionString} successfully installed.";
  879. GtkDialog.CreateInfoDialog(dialogTitle, message);
  880. Logger.Info?.Print(LogClass.Application, message);
  881. });
  882. }
  883. catch (Exception ex)
  884. {
  885. Application.Invoke(delegate
  886. {
  887. waitingDialog.Dispose();
  888. GtkDialog.CreateErrorDialog(ex.Message);
  889. });
  890. }
  891. finally
  892. {
  893. RefreshFirmwareLabel();
  894. }
  895. });
  896. thread.Name = "GUI.FirmwareInstallerThread";
  897. thread.Start();
  898. }
  899. }
  900. catch (LibHac.MissingKeyException ex)
  901. {
  902. Logger.Error?.Print(LogClass.Application, ex.ToString());
  903. UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
  904. }
  905. catch (Exception ex)
  906. {
  907. GtkDialog.CreateErrorDialog(ex.Message);
  908. }
  909. }
  910. else
  911. {
  912. fileChooser.Dispose();
  913. }
  914. }
  915. private void RefreshFirmwareLabel()
  916. {
  917. SystemVersion currentFirmware = _contentManager.GetCurrentFirmwareVersion();
  918. Application.Invoke(delegate
  919. {
  920. _firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
  921. });
  922. }
  923. private void HandleRelaunch()
  924. {
  925. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  926. {
  927. _userChannelPersistence.ShouldRestart = false;
  928. LoadApplication(_currentEmulatedGamePath);
  929. }
  930. else
  931. {
  932. // otherwise, clear state.
  933. _userChannelPersistence = new UserChannelPersistence();
  934. _currentEmulatedGamePath = null;
  935. }
  936. }
  937. private void FullScreen_Toggled(object sender, EventArgs args)
  938. {
  939. if (!Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  940. {
  941. Fullscreen();
  942. ToggleExtraWidgets(false);
  943. }
  944. else
  945. {
  946. Unfullscreen();
  947. ToggleExtraWidgets(true);
  948. }
  949. }
  950. private void StartFullScreen_Toggled(object sender, EventArgs args)
  951. {
  952. ConfigurationState.Instance.Ui.StartFullscreen.Value = _startFullScreen.Active;
  953. SaveConfig();
  954. }
  955. private void Settings_Pressed(object sender, EventArgs args)
  956. {
  957. SettingsWindow settingsWindow = new SettingsWindow(this, _virtualFileSystem, _contentManager);
  958. settingsWindow.SetSizeRequest((int)(settingsWindow.DefaultWidth * Program.WindowScaleFactor), (int)(settingsWindow.DefaultHeight * Program.WindowScaleFactor));
  959. settingsWindow.Show();
  960. }
  961. private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args)
  962. {
  963. if (_emulationContext != null)
  964. {
  965. _emulationContext.System.SimulateWakeUpMessage();
  966. }
  967. }
  968. private void ActionMenu_StateChanged(object o, StateChangedArgs args)
  969. {
  970. _scanAmiibo.Sensitive = _emulationContext != null && _emulationContext.System.SearchingForAmiibo(out int _);
  971. }
  972. private void Scan_Amiibo(object sender, EventArgs args)
  973. {
  974. if (_emulationContext.System.SearchingForAmiibo(out int deviceId))
  975. {
  976. AmiiboWindow amiiboWindow = new AmiiboWindow
  977. {
  978. LastScannedAmiiboShowAll = _lastScannedAmiiboShowAll,
  979. LastScannedAmiiboId = _lastScannedAmiiboId,
  980. DeviceId = deviceId,
  981. TitleId = _emulationContext.Application.TitleIdText.ToUpper()
  982. };
  983. amiiboWindow.DeleteEvent += AmiiboWindow_DeleteEvent;
  984. amiiboWindow.Show();
  985. }
  986. else
  987. {
  988. 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.");
  989. }
  990. }
  991. private void AmiiboWindow_DeleteEvent(object sender, DeleteEventArgs args)
  992. {
  993. if (((AmiiboWindow)sender).AmiiboId != "" && ((AmiiboWindow)sender).Response == ResponseType.Ok)
  994. {
  995. _lastScannedAmiiboId = ((AmiiboWindow)sender).AmiiboId;
  996. _lastScannedAmiiboShowAll = ((AmiiboWindow)sender).LastScannedAmiiboShowAll;
  997. _emulationContext.System.ScanAmiibo(((AmiiboWindow)sender).DeviceId, ((AmiiboWindow)sender).AmiiboId, ((AmiiboWindow)sender).UseRandomUuid);
  998. }
  999. }
  1000. private void Update_Pressed(object sender, EventArgs args)
  1001. {
  1002. if (Updater.CanUpdate(true))
  1003. {
  1004. Updater.BeginParse(this, true).ContinueWith(task =>
  1005. {
  1006. Logger.Error?.Print(LogClass.Application, $"Updater error: {task.Exception}");
  1007. }, TaskContinuationOptions.OnlyOnFaulted);
  1008. }
  1009. }
  1010. private void About_Pressed(object sender, EventArgs args)
  1011. {
  1012. AboutWindow aboutWindow = new AboutWindow();
  1013. aboutWindow.SetSizeRequest((int)(aboutWindow.DefaultWidth * Program.WindowScaleFactor), (int)(aboutWindow.DefaultHeight * Program.WindowScaleFactor));
  1014. aboutWindow.Show();
  1015. }
  1016. private void Fav_Toggled(object sender, EventArgs args)
  1017. {
  1018. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  1019. SaveConfig();
  1020. UpdateColumns();
  1021. }
  1022. private void Icon_Toggled(object sender, EventArgs args)
  1023. {
  1024. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  1025. SaveConfig();
  1026. UpdateColumns();
  1027. }
  1028. private void App_Toggled(object sender, EventArgs args)
  1029. {
  1030. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  1031. SaveConfig();
  1032. UpdateColumns();
  1033. }
  1034. private void Developer_Toggled(object sender, EventArgs args)
  1035. {
  1036. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  1037. SaveConfig();
  1038. UpdateColumns();
  1039. }
  1040. private void Version_Toggled(object sender, EventArgs args)
  1041. {
  1042. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  1043. SaveConfig();
  1044. UpdateColumns();
  1045. }
  1046. private void TimePlayed_Toggled(object sender, EventArgs args)
  1047. {
  1048. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  1049. SaveConfig();
  1050. UpdateColumns();
  1051. }
  1052. private void LastPlayed_Toggled(object sender, EventArgs args)
  1053. {
  1054. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  1055. SaveConfig();
  1056. UpdateColumns();
  1057. }
  1058. private void FileExt_Toggled(object sender, EventArgs args)
  1059. {
  1060. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  1061. SaveConfig();
  1062. UpdateColumns();
  1063. }
  1064. private void FileSize_Toggled(object sender, EventArgs args)
  1065. {
  1066. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  1067. SaveConfig();
  1068. UpdateColumns();
  1069. }
  1070. private void Path_Toggled(object sender, EventArgs args)
  1071. {
  1072. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  1073. SaveConfig();
  1074. UpdateColumns();
  1075. }
  1076. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  1077. {
  1078. UpdateGameTable();
  1079. }
  1080. }
  1081. }