MainWindow.cs 51 KB

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