MainWindow.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  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. _emulationContext = new HLE.Switch(_virtualFileSystem, _contentManager, _userChannelPersistence, renderer, deviceDriver)
  289. {
  290. UiHandler = _uiHandler
  291. };
  292. _emulationContext.Initialize();
  293. }
  294. private void SetupProgressUiHandlers()
  295. {
  296. Ptc.PtcStateChanged -= ProgressHandler;
  297. Ptc.PtcStateChanged += ProgressHandler;
  298. _emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
  299. _emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
  300. }
  301. private void ProgressHandler<T>(T state, int current, int total) where T : Enum
  302. {
  303. bool visible;
  304. string label;
  305. switch (state)
  306. {
  307. case PtcLoadingState ptcState:
  308. visible = ptcState != PtcLoadingState.Loaded;
  309. label = $"PTC : {current}/{total}";
  310. break;
  311. case ShaderCacheLoadingState shaderCacheState:
  312. visible = shaderCacheState != ShaderCacheLoadingState.Loaded;
  313. label = $"Shaders : {current}/{total}";
  314. break;
  315. default:
  316. throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
  317. }
  318. Application.Invoke(delegate
  319. {
  320. _loadingStatusLabel.Text = label;
  321. _loadingStatusBar.Fraction = total > 0 ? (double)current / total : 0;
  322. _loadingStatusBar.Visible = visible;
  323. _loadingStatusLabel.Visible = visible;
  324. });
  325. }
  326. public void UpdateGameTable()
  327. {
  328. if (_updatingGameTable || _gameLoaded)
  329. {
  330. return;
  331. }
  332. _updatingGameTable = true;
  333. _tableStore.Clear();
  334. Thread applicationLibraryThread = new Thread(() =>
  335. {
  336. _applicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language);
  337. _updatingGameTable = false;
  338. });
  339. applicationLibraryThread.Name = "GUI.ApplicationLibraryThread";
  340. applicationLibraryThread.IsBackground = true;
  341. applicationLibraryThread.Start();
  342. }
  343. [Conditional("RELEASE")]
  344. public void PerformanceCheck()
  345. {
  346. if (ConfigurationState.Instance.Logger.EnableDebug.Value)
  347. {
  348. MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  349. {
  350. Title = "Ryujinx - Warning",
  351. Text = "You have debug logging enabled, which is designed to be used by developers only.",
  352. SecondaryText = "For optimal performance, it's recommended to disable debug logging. Would you like to disable debug logging now?"
  353. };
  354. if (debugWarningDialog.Run() == (int)ResponseType.Yes)
  355. {
  356. ConfigurationState.Instance.Logger.EnableDebug.Value = false;
  357. SaveConfig();
  358. }
  359. debugWarningDialog.Dispose();
  360. }
  361. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  362. {
  363. MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  364. {
  365. Title = "Ryujinx - Warning",
  366. Text = "You have shader dumping enabled, which is designed to be used by developers only.",
  367. SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
  368. };
  369. if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes)
  370. {
  371. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  372. SaveConfig();
  373. }
  374. shadersDumpWarningDialog.Dispose();
  375. }
  376. }
  377. public void LoadApplication(string path)
  378. {
  379. if (_gameLoaded)
  380. {
  381. GtkDialog.CreateInfoDialog("A game has already been loaded", "Please stop emulation or close the emulator before launching another game.");
  382. }
  383. else
  384. {
  385. PerformanceCheck();
  386. Logger.RestartTime();
  387. InitializeSwitchInstance();
  388. UpdateGraphicsConfig();
  389. SetupProgressUiHandlers();
  390. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  391. bool isDirectory = Directory.Exists(path);
  392. if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError))
  393. {
  394. if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion))
  395. {
  396. if (userError == UserError.NoFirmware)
  397. {
  398. string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})";
  399. ResponseType responseDialog = (ResponseType)GtkDialog.CreateConfirmationDialog("No Firmware Installed", message).Run();
  400. if (responseDialog != ResponseType.Yes)
  401. {
  402. UserErrorDialog.CreateUserErrorDialog(userError);
  403. _emulationContext.Dispose();
  404. return;
  405. }
  406. }
  407. if (!SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _))
  408. {
  409. UserErrorDialog.CreateUserErrorDialog(userError);
  410. _emulationContext.Dispose();
  411. return;
  412. }
  413. // Tell the user that we installed a firmware for them.
  414. if (userError == UserError.NoFirmware)
  415. {
  416. firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  417. RefreshFirmwareLabel();
  418. 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.";
  419. GtkDialog.CreateInfoDialog($"Firmware {firmwareVersion.VersionString} was installed", message);
  420. }
  421. }
  422. else
  423. {
  424. UserErrorDialog.CreateUserErrorDialog(userError);
  425. _emulationContext.Dispose();
  426. return;
  427. }
  428. }
  429. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  430. if (Directory.Exists(path))
  431. {
  432. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  433. if (romFsFiles.Length == 0)
  434. {
  435. romFsFiles = Directory.GetFiles(path, "*.romfs");
  436. }
  437. if (romFsFiles.Length > 0)
  438. {
  439. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  440. _emulationContext.LoadCart(path, romFsFiles[0]);
  441. }
  442. else
  443. {
  444. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  445. _emulationContext.LoadCart(path);
  446. }
  447. }
  448. else if (File.Exists(path))
  449. {
  450. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  451. {
  452. case ".xci":
  453. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  454. _emulationContext.LoadXci(path);
  455. break;
  456. case ".nca":
  457. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  458. _emulationContext.LoadNca(path);
  459. break;
  460. case ".nsp":
  461. case ".pfs0":
  462. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  463. _emulationContext.LoadNsp(path);
  464. break;
  465. default:
  466. Logger.Info?.Print(LogClass.Application, "Loading as Homebrew.");
  467. try
  468. {
  469. _emulationContext.LoadProgram(path);
  470. }
  471. catch (ArgumentOutOfRangeException)
  472. {
  473. Logger.Error?.Print(LogClass.Application, "The specified file is not supported by Ryujinx.");
  474. }
  475. break;
  476. }
  477. }
  478. else
  479. {
  480. Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  481. _emulationContext.Dispose();
  482. return;
  483. }
  484. _currentEmulatedGamePath = path;
  485. _deviceExitStatus.Reset();
  486. Translator.IsReadyForTranslation.Reset();
  487. #if MACOS_BUILD
  488. CreateGameWindow();
  489. #else
  490. Thread windowThread = new Thread(() =>
  491. {
  492. CreateGameWindow();
  493. })
  494. {
  495. Name = "GUI.WindowThread"
  496. };
  497. windowThread.Start();
  498. #endif
  499. _gameLoaded = true;
  500. _actionMenu.Sensitive = true;
  501. _lastScannedAmiiboId = "";
  502. _firmwareInstallFile.Sensitive = false;
  503. _firmwareInstallDirectory.Sensitive = false;
  504. DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Application.TitleIdText, _emulationContext.Application.TitleName);
  505. _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Application.TitleIdText, appMetadata =>
  506. {
  507. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  508. });
  509. }
  510. }
  511. private void CreateGameWindow()
  512. {
  513. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  514. {
  515. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  516. }
  517. DisplaySleep.Prevent();
  518. GlRendererWidget = new GlRenderer(_emulationContext, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  519. Application.Invoke(delegate
  520. {
  521. _viewBox.Remove(_gameTableWindow);
  522. GlRendererWidget.Expand = true;
  523. _viewBox.Child = GlRendererWidget;
  524. GlRendererWidget.ShowAll();
  525. EditFooterForGameRenderer();
  526. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  527. {
  528. ToggleExtraWidgets(false);
  529. }
  530. else if (ConfigurationState.Instance.Ui.StartFullscreen.Value)
  531. {
  532. FullScreen_Toggled(null, null);
  533. }
  534. });
  535. GlRendererWidget.WaitEvent.WaitOne();
  536. GlRendererWidget.Start();
  537. Ptc.Close();
  538. PtcProfiler.Stop();
  539. _emulationContext.Dispose();
  540. _deviceExitStatus.Set();
  541. // NOTE: Everything that is here will not be executed when you close the UI.
  542. Application.Invoke(delegate
  543. {
  544. if (Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  545. {
  546. ToggleExtraWidgets(true);
  547. }
  548. GlRendererWidget.Exit();
  549. if(GlRendererWidget.Window != Window && GlRendererWidget.Window != null)
  550. {
  551. GlRendererWidget.Window.Dispose();
  552. }
  553. GlRendererWidget.Dispose();
  554. _windowsMultimediaTimerResolution?.Dispose();
  555. _windowsMultimediaTimerResolution = null;
  556. DisplaySleep.Restore();
  557. _viewBox.Remove(GlRendererWidget);
  558. _viewBox.Add(_gameTableWindow);
  559. _gameTableWindow.Expand = true;
  560. Window.Title = $"Ryujinx {Program.Version}";
  561. _emulationContext = null;
  562. _gameLoaded = false;
  563. GlRendererWidget = null;
  564. DiscordIntegrationModule.SwitchToMainMenu();
  565. RecreateFooterForMenu();
  566. UpdateColumns();
  567. UpdateGameTable();
  568. Task.Run(RefreshFirmwareLabel);
  569. Task.Run(HandleRelaunch);
  570. _actionMenu.Sensitive = false;
  571. _firmwareInstallFile.Sensitive = true;
  572. _firmwareInstallDirectory.Sensitive = true;
  573. });
  574. }
  575. private void RecreateFooterForMenu()
  576. {
  577. _listStatusBox.Show();
  578. _statusBar.Hide();
  579. }
  580. private void EditFooterForGameRenderer()
  581. {
  582. _listStatusBox.Hide();
  583. _statusBar.Show();
  584. }
  585. public void ToggleExtraWidgets(bool show)
  586. {
  587. if (GlRendererWidget != null)
  588. {
  589. if (show)
  590. {
  591. _menuBar.ShowAll();
  592. _footerBox.Show();
  593. _statusBar.Show();
  594. }
  595. else
  596. {
  597. _menuBar.Hide();
  598. _footerBox.Hide();
  599. }
  600. }
  601. }
  602. private void UpdateGameMetadata(string titleId)
  603. {
  604. if (_gameLoaded)
  605. {
  606. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  607. {
  608. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  609. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  610. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  611. });
  612. }
  613. }
  614. public void UpdateGraphicsConfig()
  615. {
  616. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  617. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  618. Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
  619. Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  620. Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  621. Graphics.Gpu.GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  622. }
  623. public void SaveConfig()
  624. {
  625. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  626. }
  627. private void End()
  628. {
  629. if (_ending)
  630. {
  631. return;
  632. }
  633. _ending = true;
  634. if (_emulationContext != null)
  635. {
  636. UpdateGameMetadata(_emulationContext.Application.TitleIdText);
  637. if (GlRendererWidget != null)
  638. {
  639. // We tell the widget that we are exiting.
  640. GlRendererWidget.Exit();
  641. // Wait for the other thread to dispose the HLE context before exiting.
  642. _deviceExitStatus.WaitOne();
  643. GlRendererWidget.Dispose();
  644. }
  645. }
  646. Dispose();
  647. Program.Exit();
  648. Application.Quit();
  649. }
  650. //
  651. // Events
  652. //
  653. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  654. {
  655. Application.Invoke(delegate
  656. {
  657. _tableStore.AppendValues(
  658. args.AppData.Favorite,
  659. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  660. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  661. args.AppData.Developer,
  662. args.AppData.Version,
  663. args.AppData.TimePlayed,
  664. args.AppData.LastPlayed,
  665. args.AppData.FileExtension,
  666. args.AppData.FileSize,
  667. args.AppData.Path,
  668. args.AppData.ControlHolder);
  669. });
  670. }
  671. private void ApplicationCount_Updated(object sender, ApplicationCountUpdatedEventArgs args)
  672. {
  673. Application.Invoke(delegate
  674. {
  675. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  676. float barValue = 0;
  677. if (args.NumAppsFound != 0)
  678. {
  679. barValue = (float)args.NumAppsLoaded / args.NumAppsFound;
  680. }
  681. _progressBar.Fraction = barValue;
  682. // Reset the vertical scrollbar to the top when titles finish loading
  683. if (args.NumAppsLoaded == args.NumAppsFound)
  684. {
  685. _gameTableWindow.Vadjustment.Value = 0;
  686. }
  687. });
  688. }
  689. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  690. {
  691. Application.Invoke(delegate
  692. {
  693. _gameStatus.Text = args.GameStatus;
  694. _fifoStatus.Text = args.FifoStatus;
  695. _gpuName.Text = args.GpuName;
  696. _dockedMode.Text = args.DockedMode;
  697. _aspectRatio.Text = args.AspectRatio;
  698. if (args.VSyncEnabled)
  699. {
  700. _vSyncStatus.Attributes = new Pango.AttrList();
  701. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(11822, 60138, 51657));
  702. }
  703. else
  704. {
  705. _vSyncStatus.Attributes = new Pango.AttrList();
  706. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(ushort.MaxValue, 17733, 21588));
  707. }
  708. });
  709. }
  710. private void FavToggle_Toggled(object sender, ToggledArgs args)
  711. {
  712. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  713. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  714. bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
  715. _tableStore.SetValue(treeIter, 0, newToggleValue);
  716. _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  717. {
  718. appMetadata.Favorite = newToggleValue;
  719. });
  720. }
  721. private void Column_Clicked(object sender, EventArgs args)
  722. {
  723. TreeViewColumn column = (TreeViewColumn)sender;
  724. ConfigurationState.Instance.Ui.ColumnSort.SortColumnId.Value = column.SortColumnId;
  725. ConfigurationState.Instance.Ui.ColumnSort.SortAscending.Value = column.SortOrder == SortType.Ascending;
  726. SaveConfig();
  727. }
  728. private void Row_Activated(object sender, RowActivatedArgs args)
  729. {
  730. _gameTableSelection.GetSelected(out TreeIter treeIter);
  731. string path = (string)_tableStore.GetValue(treeIter, 9);
  732. LoadApplication(path);
  733. }
  734. private void VSyncStatus_Clicked(object sender, ButtonReleaseEventArgs args)
  735. {
  736. _emulationContext.EnableDeviceVsync = !_emulationContext.EnableDeviceVsync;
  737. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {_emulationContext.EnableDeviceVsync}");
  738. }
  739. private void DockedMode_Clicked(object sender, ButtonReleaseEventArgs args)
  740. {
  741. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  742. }
  743. private void AspectRatio_Clicked(object sender, ButtonReleaseEventArgs args)
  744. {
  745. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  746. ConfigurationState.Instance.Graphics.AspectRatio.Value = ((int)aspectRatio + 1) > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  747. }
  748. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  749. {
  750. if (args.Event.Button != 3 /* Right Click */)
  751. {
  752. return;
  753. }
  754. _gameTableSelection.GetSelected(out TreeIter treeIter);
  755. if (treeIter.UserData == IntPtr.Zero)
  756. {
  757. return;
  758. }
  759. string titleFilePath = _tableStore.GetValue(treeIter, 9).ToString();
  760. string titleName = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[0];
  761. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  762. BlitStruct<ApplicationControlProperty> controlData = (BlitStruct<ApplicationControlProperty>)_tableStore.GetValue(treeIter, 10);
  763. _ = new GameTableContextMenu(this, _virtualFileSystem, titleFilePath, titleName, titleId, controlData);
  764. }
  765. private void Load_Application_File(object sender, EventArgs args)
  766. {
  767. using (FileChooserDialog fileChooser = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept))
  768. {
  769. fileChooser.Filter = new FileFilter();
  770. fileChooser.Filter.AddPattern("*.nsp");
  771. fileChooser.Filter.AddPattern("*.pfs0");
  772. fileChooser.Filter.AddPattern("*.xci");
  773. fileChooser.Filter.AddPattern("*.nca");
  774. fileChooser.Filter.AddPattern("*.nro");
  775. fileChooser.Filter.AddPattern("*.nso");
  776. if (fileChooser.Run() == (int)ResponseType.Accept)
  777. {
  778. LoadApplication(fileChooser.Filename);
  779. }
  780. }
  781. }
  782. private void Load_Application_Folder(object sender, EventArgs args)
  783. {
  784. using (FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept))
  785. {
  786. if (fileChooser.Run() == (int)ResponseType.Accept)
  787. {
  788. LoadApplication(fileChooser.Filename);
  789. }
  790. }
  791. }
  792. private void Open_Ryu_Folder(object sender, EventArgs args)
  793. {
  794. OpenHelper.OpenFolder(AppDataManager.BaseDirPath);
  795. }
  796. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  797. {
  798. string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  799. new DirectoryInfo(logPath).Create();
  800. OpenHelper.OpenFolder(logPath);
  801. }
  802. private void Exit_Pressed(object sender, EventArgs args)
  803. {
  804. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  805. {
  806. End();
  807. }
  808. }
  809. private void Window_Close(object sender, DeleteEventArgs args)
  810. {
  811. if (!_gameLoaded || !ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  812. {
  813. End();
  814. }
  815. else
  816. {
  817. args.RetVal = true;
  818. }
  819. }
  820. private void StopEmulation_Pressed(object sender, EventArgs args)
  821. {
  822. GlRendererWidget?.Exit();
  823. }
  824. private void Installer_File_Pressed(object o, EventArgs args)
  825. {
  826. FileChooserDialog fileChooser = new FileChooserDialog("Choose the firmware file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  827. fileChooser.Filter = new FileFilter();
  828. fileChooser.Filter.AddPattern("*.zip");
  829. fileChooser.Filter.AddPattern("*.xci");
  830. HandleInstallerDialog(fileChooser);
  831. }
  832. private void Installer_Directory_Pressed(object o, EventArgs args)
  833. {
  834. FileChooserDialog directoryChooser = new FileChooserDialog("Choose the firmware directory to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  835. HandleInstallerDialog(directoryChooser);
  836. }
  837. private void HandleInstallerDialog(FileChooserDialog fileChooser)
  838. {
  839. if (fileChooser.Run() == (int)ResponseType.Accept)
  840. {
  841. try
  842. {
  843. string filename = fileChooser.Filename;
  844. fileChooser.Dispose();
  845. SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);
  846. string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}";
  847. if (firmwareVersion == null)
  848. {
  849. GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}.");
  850. return;
  851. }
  852. SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();
  853. string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
  854. if (currentVersion != null)
  855. {
  856. dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. ";
  857. }
  858. dialogMessage += "\n\nDo you want to continue?";
  859. ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run();
  860. MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware...");
  861. if (responseInstallDialog == ResponseType.Yes)
  862. {
  863. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  864. Thread thread = new Thread(() =>
  865. {
  866. Application.Invoke(delegate
  867. {
  868. waitingDialog.Run();
  869. });
  870. try
  871. {
  872. _contentManager.InstallFirmware(filename);
  873. Application.Invoke(delegate
  874. {
  875. waitingDialog.Dispose();
  876. string message = $"System version {firmwareVersion.VersionString} successfully installed.";
  877. GtkDialog.CreateInfoDialog(dialogTitle, message);
  878. Logger.Info?.Print(LogClass.Application, message);
  879. });
  880. }
  881. catch (Exception ex)
  882. {
  883. Application.Invoke(delegate
  884. {
  885. waitingDialog.Dispose();
  886. GtkDialog.CreateErrorDialog(ex.Message);
  887. });
  888. }
  889. finally
  890. {
  891. RefreshFirmwareLabel();
  892. }
  893. });
  894. thread.Name = "GUI.FirmwareInstallerThread";
  895. thread.Start();
  896. }
  897. }
  898. catch (LibHac.MissingKeyException ex)
  899. {
  900. Logger.Error?.Print(LogClass.Application, ex.ToString());
  901. UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
  902. }
  903. catch (Exception ex)
  904. {
  905. GtkDialog.CreateErrorDialog(ex.Message);
  906. }
  907. }
  908. else
  909. {
  910. fileChooser.Dispose();
  911. }
  912. }
  913. private void RefreshFirmwareLabel()
  914. {
  915. SystemVersion currentFirmware = _contentManager.GetCurrentFirmwareVersion();
  916. Application.Invoke(delegate
  917. {
  918. _firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
  919. });
  920. }
  921. private void HandleRelaunch()
  922. {
  923. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  924. {
  925. _userChannelPersistence.ShouldRestart = false;
  926. LoadApplication(_currentEmulatedGamePath);
  927. }
  928. else
  929. {
  930. // otherwise, clear state.
  931. _userChannelPersistence = new UserChannelPersistence();
  932. _currentEmulatedGamePath = null;
  933. }
  934. }
  935. private void FullScreen_Toggled(object sender, EventArgs args)
  936. {
  937. if (!Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  938. {
  939. Fullscreen();
  940. ToggleExtraWidgets(false);
  941. }
  942. else
  943. {
  944. Unfullscreen();
  945. ToggleExtraWidgets(true);
  946. }
  947. }
  948. private void StartFullScreen_Toggled(object sender, EventArgs args)
  949. {
  950. ConfigurationState.Instance.Ui.StartFullscreen.Value = _startFullScreen.Active;
  951. SaveConfig();
  952. }
  953. private void Settings_Pressed(object sender, EventArgs args)
  954. {
  955. SettingsWindow settingsWindow = new SettingsWindow(this, _virtualFileSystem, _contentManager);
  956. settingsWindow.SetSizeRequest((int)(settingsWindow.DefaultWidth * Program.WindowScaleFactor), (int)(settingsWindow.DefaultHeight * Program.WindowScaleFactor));
  957. settingsWindow.Show();
  958. }
  959. private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args)
  960. {
  961. if (_emulationContext != null)
  962. {
  963. _emulationContext.System.SimulateWakeUpMessage();
  964. }
  965. }
  966. private void ActionMenu_StateChanged(object o, StateChangedArgs args)
  967. {
  968. _scanAmiibo.Sensitive = _emulationContext != null && _emulationContext.System.SearchingForAmiibo(out int _);
  969. }
  970. private void Scan_Amiibo(object sender, EventArgs args)
  971. {
  972. if (_emulationContext.System.SearchingForAmiibo(out int deviceId))
  973. {
  974. AmiiboWindow amiiboWindow = new AmiiboWindow
  975. {
  976. LastScannedAmiiboShowAll = _lastScannedAmiiboShowAll,
  977. LastScannedAmiiboId = _lastScannedAmiiboId,
  978. DeviceId = deviceId,
  979. TitleId = _emulationContext.Application.TitleIdText.ToUpper()
  980. };
  981. amiiboWindow.DeleteEvent += AmiiboWindow_DeleteEvent;
  982. amiiboWindow.Show();
  983. }
  984. else
  985. {
  986. 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.");
  987. }
  988. }
  989. private void AmiiboWindow_DeleteEvent(object sender, DeleteEventArgs args)
  990. {
  991. if (((AmiiboWindow)sender).AmiiboId != "" && ((AmiiboWindow)sender).Response == ResponseType.Ok)
  992. {
  993. _lastScannedAmiiboId = ((AmiiboWindow)sender).AmiiboId;
  994. _lastScannedAmiiboShowAll = ((AmiiboWindow)sender).LastScannedAmiiboShowAll;
  995. _emulationContext.System.ScanAmiibo(((AmiiboWindow)sender).DeviceId, ((AmiiboWindow)sender).AmiiboId, ((AmiiboWindow)sender).UseRandomUuid);
  996. }
  997. }
  998. private void Update_Pressed(object sender, EventArgs args)
  999. {
  1000. if (Updater.CanUpdate(true))
  1001. {
  1002. Updater.BeginParse(this, true).ContinueWith(task =>
  1003. {
  1004. Logger.Error?.Print(LogClass.Application, $"Updater error: {task.Exception}");
  1005. }, TaskContinuationOptions.OnlyOnFaulted);
  1006. }
  1007. }
  1008. private void About_Pressed(object sender, EventArgs args)
  1009. {
  1010. AboutWindow aboutWindow = new AboutWindow();
  1011. aboutWindow.SetSizeRequest((int)(aboutWindow.DefaultWidth * Program.WindowScaleFactor), (int)(aboutWindow.DefaultHeight * Program.WindowScaleFactor));
  1012. aboutWindow.Show();
  1013. }
  1014. private void Fav_Toggled(object sender, EventArgs args)
  1015. {
  1016. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  1017. SaveConfig();
  1018. UpdateColumns();
  1019. }
  1020. private void Icon_Toggled(object sender, EventArgs args)
  1021. {
  1022. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  1023. SaveConfig();
  1024. UpdateColumns();
  1025. }
  1026. private void App_Toggled(object sender, EventArgs args)
  1027. {
  1028. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  1029. SaveConfig();
  1030. UpdateColumns();
  1031. }
  1032. private void Developer_Toggled(object sender, EventArgs args)
  1033. {
  1034. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  1035. SaveConfig();
  1036. UpdateColumns();
  1037. }
  1038. private void Version_Toggled(object sender, EventArgs args)
  1039. {
  1040. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  1041. SaveConfig();
  1042. UpdateColumns();
  1043. }
  1044. private void TimePlayed_Toggled(object sender, EventArgs args)
  1045. {
  1046. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  1047. SaveConfig();
  1048. UpdateColumns();
  1049. }
  1050. private void LastPlayed_Toggled(object sender, EventArgs args)
  1051. {
  1052. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  1053. SaveConfig();
  1054. UpdateColumns();
  1055. }
  1056. private void FileExt_Toggled(object sender, EventArgs args)
  1057. {
  1058. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  1059. SaveConfig();
  1060. UpdateColumns();
  1061. }
  1062. private void FileSize_Toggled(object sender, EventArgs args)
  1063. {
  1064. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  1065. SaveConfig();
  1066. UpdateColumns();
  1067. }
  1068. private void Path_Toggled(object sender, EventArgs args)
  1069. {
  1070. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  1071. SaveConfig();
  1072. UpdateColumns();
  1073. }
  1074. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  1075. {
  1076. UpdateGameTable();
  1077. }
  1078. }
  1079. }