MainWindow.axaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Primitives;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Platform;
  6. using Avalonia.Threading;
  7. using FluentAvalonia.UI.Controls;
  8. using LibHac.Tools.FsSystem;
  9. using Ryujinx.Ava.Common;
  10. using Ryujinx.Ava.Common.Locale;
  11. using Ryujinx.Ava.Input;
  12. using Ryujinx.Ava.UI.Applet;
  13. using Ryujinx.Ava.UI.Helpers;
  14. using Ryujinx.Ava.UI.ViewModels;
  15. using Ryujinx.Common.Logging;
  16. using Ryujinx.Graphics.Gpu;
  17. using Ryujinx.HLE.FileSystem;
  18. using Ryujinx.HLE.HOS;
  19. using Ryujinx.HLE.HOS.Services.Account.Acc;
  20. using Ryujinx.Input.HLE;
  21. using Ryujinx.Input.SDL2;
  22. using Ryujinx.Modules;
  23. using Ryujinx.UI.App.Common;
  24. using Ryujinx.UI.Common;
  25. using Ryujinx.UI.Common.Configuration;
  26. using Ryujinx.UI.Common.Helper;
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Runtime.Versioning;
  30. using System.Threading;
  31. using System.Threading.Tasks;
  32. namespace Ryujinx.Ava.UI.Windows
  33. {
  34. public partial class MainWindow : StyleableWindow
  35. {
  36. internal static MainWindowViewModel MainWindowViewModel { get; private set; }
  37. private bool _isLoading;
  38. private bool _applicationsLoadedOnce;
  39. private UserChannelPersistence _userChannelPersistence;
  40. private static bool _deferLoad;
  41. private static string _launchPath;
  42. private static string _launchApplicationId;
  43. private static bool _startFullscreen;
  44. internal readonly AvaHostUIHandler UiHandler;
  45. public VirtualFileSystem VirtualFileSystem { get; private set; }
  46. public ContentManager ContentManager { get; private set; }
  47. public AccountManager AccountManager { get; private set; }
  48. public LibHacHorizonManager LibHacHorizonManager { get; private set; }
  49. public InputManager InputManager { get; private set; }
  50. internal MainWindowViewModel ViewModel { get; private set; }
  51. public SettingsWindow SettingsWindow { get; set; }
  52. public static bool ShowKeyErrorOnLoad { get; set; }
  53. public ApplicationLibrary ApplicationLibrary { get; set; }
  54. public readonly double StatusBarHeight;
  55. public readonly double MenuBarHeight;
  56. public MainWindow()
  57. {
  58. ViewModel = new MainWindowViewModel();
  59. MainWindowViewModel = ViewModel;
  60. DataContext = ViewModel;
  61. InitializeComponent();
  62. Load();
  63. UiHandler = new AvaHostUIHandler(this);
  64. ViewModel.Title = $"Ryujinx {Program.Version}";
  65. // NOTE: Height of MenuBar and StatusBar is not usable here, since it would still be 0 at this point.
  66. StatusBarHeight = StatusBarView.StatusBar.MinHeight;
  67. MenuBarHeight = MenuBar.MinHeight;
  68. double barHeight = MenuBarHeight + StatusBarHeight;
  69. Height = ((Height - barHeight) / Program.WindowScaleFactor) + barHeight;
  70. Width /= Program.WindowScaleFactor;
  71. SetWindowSizePosition();
  72. if (Program.PreviewerDetached)
  73. {
  74. InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL2GamepadDriver());
  75. this.GetObservable(IsActiveProperty).Subscribe(IsActiveChanged);
  76. this.ScalingChanged += OnScalingChanged;
  77. }
  78. }
  79. /// <summary>
  80. /// Event handler for detecting OS theme change when using "Follow OS theme" option
  81. /// </summary>
  82. private void OnPlatformColorValuesChanged(object sender, PlatformColorValues e)
  83. {
  84. if (Application.Current is App app)
  85. {
  86. app.ApplyConfiguredTheme();
  87. }
  88. }
  89. protected override void OnClosed(EventArgs e)
  90. {
  91. base.OnClosed(e);
  92. if (PlatformSettings != null)
  93. {
  94. /// <summary>
  95. /// Unsubscribe to the ColorValuesChanged event
  96. /// </summary>
  97. PlatformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged;
  98. }
  99. }
  100. protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
  101. {
  102. base.OnApplyTemplate(e);
  103. NotificationHelper.SetNotificationManager(this);
  104. }
  105. private void IsActiveChanged(bool obj)
  106. {
  107. ViewModel.IsActive = obj;
  108. }
  109. private void OnScalingChanged(object sender, EventArgs e)
  110. {
  111. Program.DesktopScaleFactor = this.RenderScaling;
  112. }
  113. private void ApplicationLibrary_ApplicationAdded(object sender, ApplicationAddedEventArgs e)
  114. {
  115. Dispatcher.UIThread.Post(() =>
  116. {
  117. ViewModel.Applications.Add(e.AppData);
  118. });
  119. }
  120. private void ApplicationLibrary_ApplicationCountUpdated(object sender, ApplicationCountUpdatedEventArgs e)
  121. {
  122. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.StatusBarGamesLoaded, e.NumAppsLoaded, e.NumAppsFound);
  123. Dispatcher.UIThread.Post(() =>
  124. {
  125. ViewModel.StatusBarProgressValue = e.NumAppsLoaded;
  126. ViewModel.StatusBarProgressMaximum = e.NumAppsFound;
  127. if (e.NumAppsFound == 0)
  128. {
  129. StatusBarView.LoadProgressBar.IsVisible = false;
  130. }
  131. if (e.NumAppsLoaded == e.NumAppsFound)
  132. {
  133. StatusBarView.LoadProgressBar.IsVisible = false;
  134. }
  135. });
  136. }
  137. public void Application_Opened(object sender, ApplicationOpenedEventArgs args)
  138. {
  139. if (args.Application != null)
  140. {
  141. ViewModel.SelectedIcon = args.Application.Icon;
  142. ViewModel.LoadApplication(args.Application).Wait();
  143. }
  144. args.Handled = true;
  145. }
  146. internal static void DeferLoadApplication(string launchPathArg, string launchApplicationId, bool startFullscreenArg)
  147. {
  148. _deferLoad = true;
  149. _launchPath = launchPathArg;
  150. _launchApplicationId = launchApplicationId;
  151. _startFullscreen = startFullscreenArg;
  152. }
  153. public void SwitchToGameControl(bool startFullscreen = false)
  154. {
  155. ViewModel.ShowLoadProgress = false;
  156. ViewModel.ShowContent = true;
  157. ViewModel.IsLoadingIndeterminate = false;
  158. if (startFullscreen && ViewModel.WindowState != WindowState.FullScreen)
  159. {
  160. ViewModel.ToggleFullscreen();
  161. }
  162. }
  163. public void ShowLoading(bool startFullscreen = false)
  164. {
  165. ViewModel.ShowContent = false;
  166. ViewModel.ShowLoadProgress = true;
  167. ViewModel.IsLoadingIndeterminate = true;
  168. if (startFullscreen && ViewModel.WindowState != WindowState.FullScreen)
  169. {
  170. ViewModel.ToggleFullscreen();
  171. }
  172. }
  173. private void Initialize()
  174. {
  175. _userChannelPersistence = new UserChannelPersistence();
  176. VirtualFileSystem = VirtualFileSystem.CreateInstance();
  177. LibHacHorizonManager = new LibHacHorizonManager();
  178. ContentManager = new ContentManager(VirtualFileSystem);
  179. LibHacHorizonManager.InitializeFsServer(VirtualFileSystem);
  180. LibHacHorizonManager.InitializeArpServer();
  181. LibHacHorizonManager.InitializeBcatServer();
  182. LibHacHorizonManager.InitializeSystemClients();
  183. IntegrityCheckLevel checkLevel = ConfigurationState.Instance.System.EnableFsIntegrityChecks
  184. ? IntegrityCheckLevel.ErrorOnInvalid
  185. : IntegrityCheckLevel.None;
  186. ApplicationLibrary = new ApplicationLibrary(VirtualFileSystem, checkLevel)
  187. {
  188. DesiredLanguage = ConfigurationState.Instance.System.Language,
  189. };
  190. // Save data created before we supported extra data in directory save data will not work properly if
  191. // given empty extra data. Luckily some of that extra data can be created using the data from the
  192. // save data indexer, which should be enough to check access permissions for user saves.
  193. // Every single save data's extra data will be checked and fixed if needed each time the emulator is opened.
  194. // Consider removing this at some point in the future when we don't need to worry about old saves.
  195. VirtualFileSystem.FixExtraData(LibHacHorizonManager.RyujinxClient);
  196. AccountManager = new AccountManager(LibHacHorizonManager.RyujinxClient, CommandLineState.Profile);
  197. VirtualFileSystem.ReloadKeySet();
  198. ApplicationHelper.Initialize(VirtualFileSystem, AccountManager, LibHacHorizonManager.RyujinxClient);
  199. }
  200. [SupportedOSPlatform("linux")]
  201. private static async Task ShowVmMaxMapCountWarning()
  202. {
  203. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.LinuxVmMaxMapCountWarningTextSecondary,
  204. LinuxHelper.VmMaxMapCount, LinuxHelper.RecommendedVmMaxMapCount);
  205. await ContentDialogHelper.CreateWarningDialog(
  206. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountWarningTextPrimary],
  207. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountWarningTextSecondary]
  208. );
  209. }
  210. [SupportedOSPlatform("linux")]
  211. private static async Task ShowVmMaxMapCountDialog()
  212. {
  213. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.LinuxVmMaxMapCountDialogTextPrimary,
  214. LinuxHelper.RecommendedVmMaxMapCount);
  215. UserResult response = await ContentDialogHelper.ShowTextDialog(
  216. $"Ryujinx - {LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountDialogTitle]}",
  217. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountDialogTextPrimary],
  218. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountDialogTextSecondary],
  219. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountDialogButtonUntilRestart],
  220. LocaleManager.Instance[LocaleKeys.LinuxVmMaxMapCountDialogButtonPersistent],
  221. LocaleManager.Instance[LocaleKeys.InputDialogNo],
  222. (int)Symbol.Help
  223. );
  224. int rc;
  225. switch (response)
  226. {
  227. case UserResult.Ok:
  228. rc = LinuxHelper.RunPkExec($"echo {LinuxHelper.RecommendedVmMaxMapCount} > {LinuxHelper.VmMaxMapCountPath}");
  229. if (rc == 0)
  230. {
  231. Logger.Info?.Print(LogClass.Application, $"vm.max_map_count set to {LinuxHelper.VmMaxMapCount} until the next restart.");
  232. }
  233. else
  234. {
  235. Logger.Error?.Print(LogClass.Application, $"Unable to change vm.max_map_count. Process exited with code: {rc}");
  236. }
  237. break;
  238. case UserResult.No:
  239. rc = LinuxHelper.RunPkExec($"echo \"vm.max_map_count = {LinuxHelper.RecommendedVmMaxMapCount}\" > {LinuxHelper.SysCtlConfigPath} && sysctl -p {LinuxHelper.SysCtlConfigPath}");
  240. if (rc == 0)
  241. {
  242. Logger.Info?.Print(LogClass.Application, $"vm.max_map_count set to {LinuxHelper.VmMaxMapCount}. Written to config: {LinuxHelper.SysCtlConfigPath}");
  243. }
  244. else
  245. {
  246. Logger.Error?.Print(LogClass.Application, $"Unable to write new value for vm.max_map_count to config. Process exited with code: {rc}");
  247. }
  248. break;
  249. }
  250. }
  251. private async Task CheckLaunchState()
  252. {
  253. if (OperatingSystem.IsLinux() && LinuxHelper.VmMaxMapCount < LinuxHelper.RecommendedVmMaxMapCount)
  254. {
  255. Logger.Warning?.Print(LogClass.Application, $"The value of vm.max_map_count is lower than {LinuxHelper.RecommendedVmMaxMapCount}. ({LinuxHelper.VmMaxMapCount})");
  256. if (LinuxHelper.PkExecPath is not null)
  257. {
  258. await Dispatcher.UIThread.InvokeAsync(ShowVmMaxMapCountDialog);
  259. }
  260. else
  261. {
  262. await Dispatcher.UIThread.InvokeAsync(ShowVmMaxMapCountWarning);
  263. }
  264. }
  265. if (!ShowKeyErrorOnLoad)
  266. {
  267. if (_deferLoad)
  268. {
  269. _deferLoad = false;
  270. if (ApplicationLibrary.TryGetApplicationsFromFile(_launchPath, out List<ApplicationData> applications))
  271. {
  272. ApplicationData applicationData;
  273. if (_launchApplicationId != null)
  274. {
  275. applicationData = applications.Find(application => application.IdString == _launchApplicationId);
  276. if (applicationData != null)
  277. {
  278. await ViewModel.LoadApplication(applicationData, _startFullscreen);
  279. }
  280. else
  281. {
  282. Logger.Error?.Print(LogClass.Application, $"Couldn't find requested application id '{_launchApplicationId}' in '{_launchPath}'.");
  283. await Dispatcher.UIThread.InvokeAsync(async () => await UserErrorDialog.ShowUserErrorDialog(UserError.ApplicationNotFound));
  284. }
  285. }
  286. else
  287. {
  288. applicationData = applications[0];
  289. await ViewModel.LoadApplication(applicationData, _startFullscreen);
  290. }
  291. }
  292. else
  293. {
  294. Logger.Error?.Print(LogClass.Application, $"Couldn't find any application in '{_launchPath}'.");
  295. await Dispatcher.UIThread.InvokeAsync(async () => await UserErrorDialog.ShowUserErrorDialog(UserError.ApplicationNotFound));
  296. }
  297. }
  298. }
  299. else
  300. {
  301. ShowKeyErrorOnLoad = false;
  302. await Dispatcher.UIThread.InvokeAsync(async () => await UserErrorDialog.ShowUserErrorDialog(UserError.NoKeys));
  303. }
  304. if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false))
  305. {
  306. await Updater.BeginParse(this, false).ContinueWith(task =>
  307. {
  308. Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}");
  309. }, TaskContinuationOptions.OnlyOnFaulted);
  310. }
  311. }
  312. private void Load()
  313. {
  314. StatusBarView.VolumeStatus.Click += VolumeStatus_CheckedChanged;
  315. ApplicationGrid.ApplicationOpened += Application_Opened;
  316. ApplicationGrid.DataContext = ViewModel;
  317. ApplicationList.ApplicationOpened += Application_Opened;
  318. ApplicationList.DataContext = ViewModel;
  319. }
  320. private void SetWindowSizePosition()
  321. {
  322. if (!ConfigurationState.Instance.RememberWindowState)
  323. {
  324. ViewModel.WindowHeight = (720 + StatusBarHeight + MenuBarHeight) * Program.WindowScaleFactor;
  325. ViewModel.WindowWidth = 1280 * Program.WindowScaleFactor;
  326. WindowState = WindowState.Normal;
  327. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  328. return;
  329. }
  330. PixelPoint savedPoint = new(ConfigurationState.Instance.UI.WindowStartup.WindowPositionX,
  331. ConfigurationState.Instance.UI.WindowStartup.WindowPositionY);
  332. ViewModel.WindowHeight = ConfigurationState.Instance.UI.WindowStartup.WindowSizeHeight * Program.WindowScaleFactor;
  333. ViewModel.WindowWidth = ConfigurationState.Instance.UI.WindowStartup.WindowSizeWidth * Program.WindowScaleFactor;
  334. ViewModel.WindowState = ConfigurationState.Instance.UI.WindowStartup.WindowMaximized.Value ? WindowState.Maximized : WindowState.Normal;
  335. if (CheckScreenBounds(savedPoint))
  336. {
  337. Position = savedPoint;
  338. }
  339. else
  340. {
  341. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  342. }
  343. }
  344. private bool CheckScreenBounds(PixelPoint configPoint)
  345. {
  346. for (int i = 0; i < Screens.ScreenCount; i++)
  347. {
  348. if (Screens.All[i].Bounds.Contains(configPoint))
  349. {
  350. return true;
  351. }
  352. }
  353. Logger.Warning?.Print(LogClass.Application, "Failed to find valid start-up coordinates. Defaulting to primary monitor center.");
  354. return false;
  355. }
  356. private void SaveWindowSizePosition()
  357. {
  358. ConfigurationState.Instance.UI.WindowStartup.WindowMaximized.Value = WindowState == WindowState.Maximized;
  359. // Only save rectangle properties if the window is not in a maximized state.
  360. if (WindowState != WindowState.Maximized)
  361. {
  362. ConfigurationState.Instance.UI.WindowStartup.WindowSizeHeight.Value = (int)Height;
  363. ConfigurationState.Instance.UI.WindowStartup.WindowSizeWidth.Value = (int)Width;
  364. ConfigurationState.Instance.UI.WindowStartup.WindowPositionX.Value = Position.X;
  365. ConfigurationState.Instance.UI.WindowStartup.WindowPositionY.Value = Position.Y;
  366. }
  367. MainWindowViewModel.SaveConfig();
  368. }
  369. protected override void OnOpened(EventArgs e)
  370. {
  371. base.OnOpened(e);
  372. Initialize();
  373. /// <summary>
  374. /// Subscribe to the ColorValuesChanged event
  375. /// </summary>
  376. PlatformSettings.ColorValuesChanged += OnPlatformColorValuesChanged;
  377. ViewModel.Initialize(
  378. ContentManager,
  379. StorageProvider,
  380. ApplicationLibrary,
  381. VirtualFileSystem,
  382. AccountManager,
  383. InputManager,
  384. _userChannelPersistence,
  385. LibHacHorizonManager,
  386. UiHandler,
  387. ShowLoading,
  388. SwitchToGameControl,
  389. SetMainContent,
  390. this);
  391. ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated;
  392. ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded;
  393. ViewModel.RefreshFirmwareStatus();
  394. // Load applications if no application was requested by the command line
  395. if (!_deferLoad)
  396. {
  397. LoadApplications();
  398. }
  399. #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
  400. CheckLaunchState();
  401. #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
  402. }
  403. private void SetMainContent(Control content = null)
  404. {
  405. content ??= GameLibrary;
  406. if (MainContent.Content != content)
  407. {
  408. // Load applications while switching to the GameLibrary if we haven't done that yet
  409. if (!_applicationsLoadedOnce && content == GameLibrary)
  410. {
  411. LoadApplications();
  412. }
  413. MainContent.Content = content;
  414. }
  415. }
  416. public static void UpdateGraphicsConfig()
  417. {
  418. #pragma warning disable IDE0055 // Disable formatting
  419. GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.ResScale == -1 ? ConfigurationState.Instance.Graphics.ResScaleCustom : ConfigurationState.Instance.Graphics.ResScale;
  420. GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  421. GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  422. GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  423. GraphicsConfig.EnableTextureRecompression = ConfigurationState.Instance.Graphics.EnableTextureRecompression;
  424. GraphicsConfig.EnableMacroHLE = ConfigurationState.Instance.Graphics.EnableMacroHLE;
  425. #pragma warning restore IDE0055
  426. }
  427. private void VolumeStatus_CheckedChanged(object sender, RoutedEventArgs e)
  428. {
  429. var volumeSplitButton = sender as ToggleSplitButton;
  430. if (ViewModel.IsGameRunning)
  431. {
  432. if (!volumeSplitButton.IsChecked)
  433. {
  434. ViewModel.AppHost.Device.SetVolume(ViewModel.VolumeBeforeMute);
  435. }
  436. else
  437. {
  438. ViewModel.VolumeBeforeMute = ViewModel.AppHost.Device.GetVolume();
  439. ViewModel.AppHost.Device.SetVolume(0);
  440. }
  441. ViewModel.Volume = ViewModel.AppHost.Device.GetVolume();
  442. }
  443. }
  444. protected override void OnClosing(WindowClosingEventArgs e)
  445. {
  446. if (!ViewModel.IsClosing && ViewModel.AppHost != null && ConfigurationState.Instance.ShowConfirmExit)
  447. {
  448. e.Cancel = true;
  449. ConfirmExit();
  450. return;
  451. }
  452. ViewModel.IsClosing = true;
  453. if (ViewModel.AppHost != null)
  454. {
  455. ViewModel.AppHost.AppExit -= ViewModel.AppHost_AppExit;
  456. ViewModel.AppHost.AppExit += (sender, e) =>
  457. {
  458. ViewModel.AppHost = null;
  459. Dispatcher.UIThread.Post(() =>
  460. {
  461. MainContent = null;
  462. Close();
  463. });
  464. };
  465. ViewModel.AppHost?.Stop();
  466. e.Cancel = true;
  467. return;
  468. }
  469. if (ConfigurationState.Instance.RememberWindowState)
  470. {
  471. SaveWindowSizePosition();
  472. }
  473. ApplicationLibrary.CancelLoading();
  474. InputManager.Dispose();
  475. Program.Exit();
  476. base.OnClosing(e);
  477. }
  478. private void ConfirmExit()
  479. {
  480. Dispatcher.UIThread.InvokeAsync(async () =>
  481. {
  482. ViewModel.IsClosing = await ContentDialogHelper.CreateExitDialog();
  483. if (ViewModel.IsClosing)
  484. {
  485. Close();
  486. }
  487. });
  488. }
  489. public void LoadApplications()
  490. {
  491. _applicationsLoadedOnce = true;
  492. ViewModel.Applications.Clear();
  493. StatusBarView.LoadProgressBar.IsVisible = true;
  494. ViewModel.StatusBarProgressMaximum = 0;
  495. ViewModel.StatusBarProgressValue = 0;
  496. LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.StatusBarGamesLoaded, 0, 0);
  497. ReloadGameList();
  498. }
  499. public void ToggleFileType(string fileType)
  500. {
  501. _ = fileType switch
  502. {
  503. #pragma warning disable IDE0055 // Disable formatting
  504. "NSP" => ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSP,
  505. "PFS0" => ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Value = !ConfigurationState.Instance.UI.ShownFileTypes.PFS0,
  506. "XCI" => ConfigurationState.Instance.UI.ShownFileTypes.XCI.Value = !ConfigurationState.Instance.UI.ShownFileTypes.XCI,
  507. "NCA" => ConfigurationState.Instance.UI.ShownFileTypes.NCA.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NCA,
  508. "NRO" => ConfigurationState.Instance.UI.ShownFileTypes.NRO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NRO,
  509. "NSO" => ConfigurationState.Instance.UI.ShownFileTypes.NSO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSO,
  510. _ => throw new ArgumentOutOfRangeException(fileType),
  511. #pragma warning restore IDE0055
  512. };
  513. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  514. LoadApplications();
  515. }
  516. private void ReloadGameList()
  517. {
  518. if (_isLoading)
  519. {
  520. return;
  521. }
  522. _isLoading = true;
  523. Thread applicationLibraryThread = new(() =>
  524. {
  525. ApplicationLibrary.DesiredLanguage = ConfigurationState.Instance.System.Language;
  526. ApplicationLibrary.LoadApplications(ConfigurationState.Instance.UI.GameDirs);
  527. _isLoading = false;
  528. })
  529. {
  530. Name = "GUI.ApplicationLibraryThread",
  531. IsBackground = true,
  532. };
  533. applicationLibraryThread.Start();
  534. }
  535. }
  536. }