MainWindow.cs 53 KB

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