MainWindow.cs 51 KB

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