MainWindow.cs 52 KB

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