MainWindow.cs 53 KB

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