MainWindow.cs 56 KB

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