MainWindow.cs 51 KB

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