MainWindowViewModel.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. using ARMeilleure.Translation.PTC;
  2. using Avalonia;
  3. using Avalonia.Controls;
  4. using Avalonia.Input;
  5. using Avalonia.Media;
  6. using Avalonia.Threading;
  7. using DynamicData;
  8. using DynamicData.Binding;
  9. using LibHac.Fs;
  10. using LibHac.FsSystem;
  11. using LibHac.Ncm;
  12. using Ryujinx.Ava.Common;
  13. using Ryujinx.Ava.Common.Locale;
  14. using Ryujinx.Ava.Input;
  15. using Ryujinx.Ava.Ui.Controls;
  16. using Ryujinx.Ava.Ui.Windows;
  17. using Ryujinx.Common;
  18. using Ryujinx.Common.Configuration;
  19. using Ryujinx.Common.Logging;
  20. using Ryujinx.HLE;
  21. using Ryujinx.HLE.FileSystem;
  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.Collections.ObjectModel;
  30. using System.Globalization;
  31. using System.IO;
  32. using System.Threading;
  33. using System.Threading.Tasks;
  34. using Path = System.IO.Path;
  35. using ShaderCacheLoadingState = Ryujinx.Graphics.Gpu.Shader.ShaderCacheState;
  36. namespace Ryujinx.Ava.Ui.ViewModels
  37. {
  38. internal class MainWindowViewModel : BaseModel
  39. {
  40. private readonly MainWindow _owner;
  41. private ObservableCollection<ApplicationData> _applications;
  42. private string _aspectStatusText;
  43. private string _loadHeading;
  44. private string _cacheLoadStatus;
  45. private string _searchText;
  46. private string _dockedStatusText;
  47. private string _fifoStatusText;
  48. private string _gameStatusText;
  49. private string _gpuStatusText;
  50. private bool _isAmiiboRequested;
  51. private bool _isGameRunning;
  52. private bool _isLoading;
  53. private int _progressMaximum;
  54. private int _progressValue;
  55. private bool _showLoadProgress;
  56. private bool _showMenuAndStatusBar = true;
  57. private bool _showStatusSeparator;
  58. private Brush _progressBarForegroundColor;
  59. private Brush _progressBarBackgroundColor;
  60. private Brush _vsyncColor;
  61. private byte[] _selectedIcon;
  62. private bool _isAppletMenuActive;
  63. private int _statusBarProgressMaximum;
  64. private int _statusBarProgressValue;
  65. private bool _isPaused;
  66. private bool _showContent = true;
  67. private bool _isLoadingIndeterminate = true;
  68. private bool _showAll;
  69. private string _lastScannedAmiiboId;
  70. private ReadOnlyObservableCollection<ApplicationData> _appsObservableList;
  71. public string TitleName { get; internal set; }
  72. public MainWindowViewModel(MainWindow owner) : this()
  73. {
  74. _owner = owner;
  75. }
  76. public MainWindowViewModel()
  77. {
  78. Applications = new ObservableCollection<ApplicationData>();
  79. Applications.ToObservableChangeSet()
  80. .Filter(Filter)
  81. .Sort(GetComparer())
  82. .Bind(out _appsObservableList).AsObservableList();
  83. if (Program.PreviewerDetached)
  84. {
  85. LoadConfigurableHotKeys();
  86. Volume = ConfigurationState.Instance.System.AudioVolume;
  87. }
  88. }
  89. public void Initialize()
  90. {
  91. _owner.ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated;
  92. _owner.ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded;
  93. Ptc.PtcStateChanged -= ProgressHandler;
  94. Ptc.PtcStateChanged += ProgressHandler;
  95. }
  96. public string SearchText
  97. {
  98. get => _searchText;
  99. set
  100. {
  101. _searchText = value;
  102. RefreshView();
  103. }
  104. }
  105. public ReadOnlyObservableCollection<ApplicationData> AppsObservableList
  106. {
  107. get => _appsObservableList;
  108. set
  109. {
  110. _appsObservableList = value;
  111. OnPropertyChanged();
  112. }
  113. }
  114. public bool IsPaused
  115. {
  116. get => _isPaused;
  117. set
  118. {
  119. _isPaused = value;
  120. OnPropertyChanged();
  121. }
  122. }
  123. public bool EnableNonGameRunningControls => !IsGameRunning;
  124. public bool ShowFirmwareStatus => !ShowLoadProgress;
  125. public bool IsGameRunning
  126. {
  127. get => _isGameRunning;
  128. set
  129. {
  130. _isGameRunning = value;
  131. if (!value)
  132. {
  133. ShowMenuAndStatusBar = false;
  134. }
  135. OnPropertyChanged();
  136. OnPropertyChanged(nameof(EnableNonGameRunningControls));
  137. OnPropertyChanged(nameof(ShowFirmwareStatus));
  138. }
  139. }
  140. public bool IsAmiiboRequested
  141. {
  142. get => _isAmiiboRequested && _isGameRunning;
  143. set
  144. {
  145. _isAmiiboRequested = value;
  146. OnPropertyChanged();
  147. }
  148. }
  149. public bool ShowLoadProgress
  150. {
  151. get => _showLoadProgress;
  152. set
  153. {
  154. _showLoadProgress = value;
  155. OnPropertyChanged();
  156. OnPropertyChanged(nameof(ShowFirmwareStatus));
  157. }
  158. }
  159. public string GameStatusText
  160. {
  161. get => _gameStatusText;
  162. set
  163. {
  164. _gameStatusText = value;
  165. OnPropertyChanged();
  166. }
  167. }
  168. private string _showUikey = "F4";
  169. private string _pauseKey = "F5";
  170. private string _screenshotkey = "F8";
  171. private float _volume;
  172. public ApplicationData SelectedApplication
  173. {
  174. get
  175. {
  176. switch (Glyph)
  177. {
  178. case Glyph.List:
  179. return _owner.GameList.SelectedApplication;
  180. case Glyph.Grid:
  181. return _owner.GameGrid.SelectedApplication;
  182. default:
  183. return null;
  184. }
  185. }
  186. }
  187. public string LoadHeading
  188. {
  189. get => _loadHeading;
  190. set
  191. {
  192. _loadHeading = value;
  193. OnPropertyChanged();
  194. }
  195. }
  196. public string CacheLoadStatus
  197. {
  198. get => _cacheLoadStatus;
  199. set
  200. {
  201. _cacheLoadStatus = value;
  202. OnPropertyChanged();
  203. }
  204. }
  205. public Brush ProgressBarBackgroundColor
  206. {
  207. get => _progressBarBackgroundColor;
  208. set
  209. {
  210. _progressBarBackgroundColor = value;
  211. OnPropertyChanged();
  212. }
  213. }
  214. public Brush ProgressBarForegroundColor
  215. {
  216. get => _progressBarForegroundColor;
  217. set
  218. {
  219. _progressBarForegroundColor = value;
  220. OnPropertyChanged();
  221. }
  222. }
  223. public Brush VsyncColor
  224. {
  225. get => _vsyncColor;
  226. set
  227. {
  228. _vsyncColor = value;
  229. OnPropertyChanged();
  230. }
  231. }
  232. public byte[] SelectedIcon
  233. {
  234. get => _selectedIcon;
  235. set
  236. {
  237. _selectedIcon = value;
  238. OnPropertyChanged();
  239. }
  240. }
  241. public int ProgressMaximum
  242. {
  243. get => _progressMaximum;
  244. set
  245. {
  246. _progressMaximum = value;
  247. OnPropertyChanged();
  248. }
  249. }
  250. public int ProgressValue
  251. {
  252. get => _progressValue;
  253. set
  254. {
  255. _progressValue = value;
  256. OnPropertyChanged();
  257. }
  258. }
  259. public int StatusBarProgressMaximum
  260. {
  261. get => _statusBarProgressMaximum;
  262. set
  263. {
  264. _statusBarProgressMaximum = value;
  265. OnPropertyChanged();
  266. }
  267. }
  268. public int StatusBarProgressValue
  269. {
  270. get => _statusBarProgressValue;
  271. set
  272. {
  273. _statusBarProgressValue = value;
  274. OnPropertyChanged();
  275. }
  276. }
  277. public string FifoStatusText
  278. {
  279. get => _fifoStatusText;
  280. set
  281. {
  282. _fifoStatusText = value;
  283. OnPropertyChanged();
  284. }
  285. }
  286. public string GpuStatusText
  287. {
  288. get => _gpuStatusText;
  289. set
  290. {
  291. _gpuStatusText = value;
  292. OnPropertyChanged();
  293. }
  294. }
  295. public string DockedStatusText
  296. {
  297. get => _dockedStatusText;
  298. set
  299. {
  300. _dockedStatusText = value;
  301. OnPropertyChanged();
  302. }
  303. }
  304. public string AspectRatioStatusText
  305. {
  306. get => _aspectStatusText;
  307. set
  308. {
  309. _aspectStatusText = value;
  310. OnPropertyChanged();
  311. }
  312. }
  313. public string VolumeStatusText
  314. {
  315. get
  316. {
  317. string icon = Volume == 0 ? "🔇" : "🔊";
  318. return $"{icon} {(int)(Volume * 100)}%";
  319. }
  320. }
  321. public bool VolumeMuted => _volume == 0;
  322. public float Volume
  323. {
  324. get => _volume;
  325. set
  326. {
  327. _volume = value;
  328. if (_isGameRunning)
  329. {
  330. _owner.AppHost.Device.SetVolume(_volume);
  331. }
  332. OnPropertyChanged(nameof(VolumeStatusText));
  333. OnPropertyChanged(nameof(VolumeMuted));
  334. OnPropertyChanged();
  335. }
  336. }
  337. public bool ShowStatusSeparator
  338. {
  339. get => _showStatusSeparator;
  340. set
  341. {
  342. _showStatusSeparator = value;
  343. OnPropertyChanged();
  344. }
  345. }
  346. public Thickness GridItemPadding => ShowNames ? new Thickness() : new Thickness(5);
  347. public bool ShowMenuAndStatusBar
  348. {
  349. get => _showMenuAndStatusBar;
  350. set
  351. {
  352. _showMenuAndStatusBar = value;
  353. OnPropertyChanged();
  354. }
  355. }
  356. public bool IsLoadingIndeterminate
  357. {
  358. get => _isLoadingIndeterminate;
  359. set
  360. {
  361. _isLoadingIndeterminate = value;
  362. OnPropertyChanged();
  363. }
  364. }
  365. public bool ShowContent
  366. {
  367. get => _showContent;
  368. set
  369. {
  370. _showContent = value;
  371. OnPropertyChanged();
  372. }
  373. }
  374. public bool IsAppletMenuActive
  375. {
  376. get => _isAppletMenuActive && EnableNonGameRunningControls;
  377. set
  378. {
  379. _isAppletMenuActive = value;
  380. OnPropertyChanged();
  381. }
  382. }
  383. public bool IsGrid => Glyph == Glyph.Grid;
  384. public bool IsList => Glyph == Glyph.List;
  385. internal void Sort(bool isAscending)
  386. {
  387. IsAscending = isAscending;
  388. RefreshView();
  389. }
  390. internal void Sort(ApplicationSort sort)
  391. {
  392. SortMode = sort;
  393. RefreshView();
  394. }
  395. private IComparer<ApplicationData> GetComparer()
  396. {
  397. switch (SortMode)
  398. {
  399. case ApplicationSort.LastPlayed:
  400. return new Models.Generic.LastPlayedSortComparer(IsAscending);
  401. case ApplicationSort.FileSize:
  402. return new Models.Generic.FileSizeSortComparer(IsAscending);
  403. case ApplicationSort.TotalTimePlayed:
  404. return new Models.Generic.TimePlayedSortComparer(IsAscending);
  405. case ApplicationSort.Title:
  406. return IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.TitleName) : SortExpressionComparer<ApplicationData>.Descending(app => app.TitleName);
  407. case ApplicationSort.Favorite:
  408. return !IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Favorite) : SortExpressionComparer<ApplicationData>.Descending(app => app.Favorite);
  409. case ApplicationSort.Developer:
  410. return IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Developer) : SortExpressionComparer<ApplicationData>.Descending(app => app.Developer);
  411. case ApplicationSort.FileType:
  412. return IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.FileExtension) : SortExpressionComparer<ApplicationData>.Descending(app => app.FileExtension);
  413. case ApplicationSort.Path:
  414. return IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Path) : SortExpressionComparer<ApplicationData>.Descending(app => app.Path);
  415. default:
  416. return null;
  417. }
  418. }
  419. private void RefreshView()
  420. {
  421. RefreshGrid();
  422. }
  423. private void RefreshGrid()
  424. {
  425. Applications.ToObservableChangeSet()
  426. .Filter(Filter)
  427. .Sort(GetComparer())
  428. .Bind(out _appsObservableList).AsObservableList();
  429. OnPropertyChanged(nameof(AppsObservableList));
  430. }
  431. public bool StartGamesInFullscreen
  432. {
  433. get => ConfigurationState.Instance.Ui.StartFullscreen;
  434. set
  435. {
  436. ConfigurationState.Instance.Ui.StartFullscreen.Value = value;
  437. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  438. OnPropertyChanged();
  439. }
  440. }
  441. public bool ShowConsole
  442. {
  443. get => ConfigurationState.Instance.Ui.ShowConsole;
  444. set
  445. {
  446. ConfigurationState.Instance.Ui.ShowConsole.Value = value;
  447. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  448. OnPropertyChanged();
  449. }
  450. }
  451. public ObservableCollection<ApplicationData> Applications
  452. {
  453. get => _applications;
  454. set
  455. {
  456. _applications = value;
  457. OnPropertyChanged();
  458. }
  459. }
  460. public Glyph Glyph
  461. {
  462. get => (Glyph)ConfigurationState.Instance.Ui.GameListViewMode.Value;
  463. set
  464. {
  465. ConfigurationState.Instance.Ui.GameListViewMode.Value = (int)value;
  466. OnPropertyChanged();
  467. OnPropertyChanged(nameof(IsGrid));
  468. OnPropertyChanged(nameof(IsList));
  469. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  470. }
  471. }
  472. public bool ShowNames
  473. {
  474. get => ConfigurationState.Instance.Ui.ShowNames && ConfigurationState.Instance.Ui.GridSize > 1; set
  475. {
  476. ConfigurationState.Instance.Ui.ShowNames.Value = value;
  477. OnPropertyChanged();
  478. OnPropertyChanged(nameof(GridItemPadding));
  479. OnPropertyChanged(nameof(GridSizeScale));
  480. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  481. }
  482. }
  483. internal ApplicationSort SortMode
  484. {
  485. get => (ApplicationSort)ConfigurationState.Instance.Ui.ApplicationSort.Value;
  486. private set
  487. {
  488. ConfigurationState.Instance.Ui.ApplicationSort.Value = (int)value;
  489. OnPropertyChanged();
  490. OnPropertyChanged(nameof(SortName));
  491. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  492. }
  493. }
  494. public bool IsSortedByFavorite => SortMode == ApplicationSort.Favorite;
  495. public bool IsSortedByTitle => SortMode == ApplicationSort.Title;
  496. public bool IsSortedByDeveloper => SortMode == ApplicationSort.Developer;
  497. public bool IsSortedByLastPlayed => SortMode == ApplicationSort.LastPlayed;
  498. public bool IsSortedByTimePlayed => SortMode == ApplicationSort.TotalTimePlayed;
  499. public bool IsSortedByType => SortMode == ApplicationSort.FileType;
  500. public bool IsSortedBySize => SortMode == ApplicationSort.FileSize;
  501. public bool IsSortedByPath => SortMode == ApplicationSort.Path;
  502. public string SortName
  503. {
  504. get
  505. {
  506. switch (SortMode)
  507. {
  508. case ApplicationSort.Title:
  509. return LocaleManager.Instance["GameListHeaderApplication"];
  510. case ApplicationSort.Developer:
  511. return LocaleManager.Instance["GameListHeaderDeveloper"];
  512. case ApplicationSort.LastPlayed:
  513. return LocaleManager.Instance["GameListHeaderLastPlayed"];
  514. case ApplicationSort.TotalTimePlayed:
  515. return LocaleManager.Instance["GameListHeaderTimePlayed"];
  516. case ApplicationSort.FileType:
  517. return LocaleManager.Instance["GameListHeaderFileExtension"];
  518. case ApplicationSort.FileSize:
  519. return LocaleManager.Instance["GameListHeaderFileSize"];
  520. case ApplicationSort.Path:
  521. return LocaleManager.Instance["GameListHeaderPath"];
  522. case ApplicationSort.Favorite:
  523. return LocaleManager.Instance["CommonFavorite"];
  524. }
  525. return string.Empty;
  526. }
  527. }
  528. public bool IsAscending
  529. {
  530. get => ConfigurationState.Instance.Ui.IsAscendingOrder;
  531. private set
  532. {
  533. ConfigurationState.Instance.Ui.IsAscendingOrder.Value = value;
  534. OnPropertyChanged();
  535. OnPropertyChanged(nameof(SortMode));
  536. OnPropertyChanged(nameof(SortName));
  537. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  538. }
  539. }
  540. public KeyGesture ShowUiKey
  541. {
  542. get => KeyGesture.Parse(_showUikey); set
  543. {
  544. _showUikey = value.ToString();
  545. OnPropertyChanged();
  546. }
  547. }
  548. public KeyGesture ScreenshotKey
  549. {
  550. get => KeyGesture.Parse(_screenshotkey); set
  551. {
  552. _screenshotkey = value.ToString();
  553. OnPropertyChanged();
  554. }
  555. }
  556. public KeyGesture PauseKey
  557. {
  558. get => KeyGesture.Parse(_pauseKey); set
  559. {
  560. _pauseKey = value.ToString();
  561. OnPropertyChanged();
  562. }
  563. }
  564. public bool IsGridSmall => ConfigurationState.Instance.Ui.GridSize == 1;
  565. public bool IsGridMedium => ConfigurationState.Instance.Ui.GridSize == 2;
  566. public bool IsGridLarge => ConfigurationState.Instance.Ui.GridSize == 3;
  567. public bool IsGridHuge => ConfigurationState.Instance.Ui.GridSize == 4;
  568. public int GridSizeScale
  569. {
  570. get => ConfigurationState.Instance.Ui.GridSize;
  571. set
  572. {
  573. ConfigurationState.Instance.Ui.GridSize.Value = value;
  574. if (value < 2)
  575. {
  576. ShowNames = false;
  577. }
  578. OnPropertyChanged();
  579. OnPropertyChanged(nameof(IsGridSmall));
  580. OnPropertyChanged(nameof(IsGridMedium));
  581. OnPropertyChanged(nameof(IsGridLarge));
  582. OnPropertyChanged(nameof(IsGridHuge));
  583. OnPropertyChanged(nameof(ShowNames));
  584. OnPropertyChanged(nameof(GridItemPadding));
  585. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  586. }
  587. }
  588. public async void OpenAmiiboWindow()
  589. {
  590. if (!_isAmiiboRequested)
  591. {
  592. return;
  593. }
  594. if (_owner.AppHost.Device.System.SearchingForAmiibo(out int deviceId))
  595. {
  596. string titleId = _owner.AppHost.Device.Application.TitleIdText.ToUpper();
  597. AmiiboWindow window = new(_showAll, _lastScannedAmiiboId, titleId);
  598. await window.ShowDialog(_owner);
  599. if (window.IsScanned)
  600. {
  601. _showAll = window.ViewModel.ShowAllAmiibo;
  602. _lastScannedAmiiboId = window.ScannedAmiibo.GetId();
  603. _owner.AppHost.Device.System.ScanAmiibo(deviceId, _lastScannedAmiiboId, window.ViewModel.UseRandomUuid);
  604. }
  605. }
  606. }
  607. public void HandleShaderProgress(Switch emulationContext)
  608. {
  609. emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
  610. emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
  611. }
  612. private bool Filter(object arg)
  613. {
  614. if (arg is ApplicationData app)
  615. {
  616. return string.IsNullOrWhiteSpace(_searchText) || app.TitleName.ToLower().Contains(_searchText.ToLower());
  617. }
  618. return false;
  619. }
  620. private void ApplicationLibrary_ApplicationAdded(object sender, ApplicationAddedEventArgs e)
  621. {
  622. AddApplication(e.AppData);
  623. }
  624. private void ApplicationLibrary_ApplicationCountUpdated(object sender, ApplicationCountUpdatedEventArgs e)
  625. {
  626. StatusBarProgressValue = e.NumAppsLoaded;
  627. StatusBarProgressMaximum = e.NumAppsFound;
  628. LocaleManager.Instance.UpdateDynamicValue("StatusBarGamesLoaded", StatusBarProgressValue, StatusBarProgressMaximum);
  629. Dispatcher.UIThread.Post(() =>
  630. {
  631. if (e.NumAppsFound == 0)
  632. {
  633. _owner.LoadProgressBar.IsVisible = false;
  634. }
  635. });
  636. }
  637. public void AddApplication(ApplicationData applicationData)
  638. {
  639. Dispatcher.UIThread.InvokeAsync(() =>
  640. {
  641. Applications.Add(applicationData);
  642. });
  643. }
  644. public async void LoadApplications()
  645. {
  646. await Dispatcher.UIThread.InvokeAsync(() =>
  647. {
  648. Applications.Clear();
  649. _owner.LoadProgressBar.IsVisible = true;
  650. StatusBarProgressMaximum = 0;
  651. StatusBarProgressValue = 0;
  652. LocaleManager.Instance.UpdateDynamicValue("StatusBarGamesLoaded", 0, 0);
  653. });
  654. ReloadGameList();
  655. }
  656. private void ReloadGameList()
  657. {
  658. if (_isLoading)
  659. {
  660. return;
  661. }
  662. _isLoading = true;
  663. Thread thread = new(() =>
  664. {
  665. _owner.ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs.Value, ConfigurationState.Instance.System.Language);
  666. _isLoading = false;
  667. })
  668. { Name = "GUI.AppListLoadThread", Priority = ThreadPriority.AboveNormal };
  669. thread.Start();
  670. }
  671. public async void OpenFile()
  672. {
  673. OpenFileDialog dialog = new()
  674. {
  675. Title = LocaleManager.Instance["OpenFileDialogTitle"]
  676. };
  677. dialog.Filters.Add(new FileDialogFilter
  678. {
  679. Name = LocaleManager.Instance["AllSupportedFormats"],
  680. Extensions =
  681. {
  682. "nsp",
  683. "pfs0",
  684. "xci",
  685. "nca",
  686. "nro",
  687. "nso"
  688. }
  689. });
  690. dialog.Filters.Add(new FileDialogFilter { Name = "NSP", Extensions = { "nsp" } });
  691. dialog.Filters.Add(new FileDialogFilter { Name = "PFS0", Extensions = { "pfs0" } });
  692. dialog.Filters.Add(new FileDialogFilter { Name = "XCI", Extensions = { "xci" } });
  693. dialog.Filters.Add(new FileDialogFilter { Name = "NCA", Extensions = { "nca" } });
  694. dialog.Filters.Add(new FileDialogFilter { Name = "NRO", Extensions = { "nro" } });
  695. dialog.Filters.Add(new FileDialogFilter { Name = "NSO", Extensions = { "nso" } });
  696. string[] files = await dialog.ShowAsync(_owner);
  697. if (files != null && files.Length > 0)
  698. {
  699. _owner.LoadApplication(files[0]);
  700. }
  701. }
  702. public async void OpenFolder()
  703. {
  704. OpenFolderDialog dialog = new()
  705. {
  706. Title = LocaleManager.Instance["OpenFolderDialogTitle"]
  707. };
  708. string folder = await dialog.ShowAsync(_owner);
  709. if (!string.IsNullOrWhiteSpace(folder) && Directory.Exists(folder))
  710. {
  711. _owner.LoadApplication(folder);
  712. }
  713. }
  714. public void LoadConfigurableHotKeys()
  715. {
  716. if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi, out var showUiKey))
  717. {
  718. ShowUiKey = new KeyGesture(showUiKey, KeyModifiers.None);
  719. }
  720. if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot, out var screenshotKey))
  721. {
  722. ScreenshotKey = new KeyGesture(screenshotKey, KeyModifiers.None);
  723. }
  724. if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause, out var pauseKey))
  725. {
  726. PauseKey = new KeyGesture(pauseKey, KeyModifiers.None);
  727. }
  728. }
  729. public void TakeScreenshot()
  730. {
  731. _owner.AppHost.ScreenshotRequested = true;
  732. }
  733. public void HideUi()
  734. {
  735. ShowMenuAndStatusBar = false;
  736. }
  737. public void SetListMode()
  738. {
  739. Glyph = Glyph.List;
  740. }
  741. public void SetGridMode()
  742. {
  743. Glyph = Glyph.Grid;
  744. }
  745. public void OpenMiiApplet()
  746. {
  747. string contentPath = _owner.ContentManager.GetInstalledContentPath(0x0100000000001009, StorageId.BuiltInSystem, NcaContentType.Program);
  748. if (!string.IsNullOrWhiteSpace(contentPath))
  749. {
  750. _owner.LoadApplication(contentPath, false, "Mii Applet");
  751. }
  752. }
  753. public static void OpenRyujinxFolder()
  754. {
  755. OpenHelper.OpenFolder(AppDataManager.BaseDirPath);
  756. }
  757. public static void OpenLogsFolder()
  758. {
  759. string logPath = Path.Combine(ReleaseInformations.GetBaseApplicationDirectory(), "Logs");
  760. new DirectoryInfo(logPath).Create();
  761. OpenHelper.OpenFolder(logPath);
  762. }
  763. public void ToggleFullscreen()
  764. {
  765. WindowState state = _owner.WindowState;
  766. if (state == WindowState.FullScreen)
  767. {
  768. _owner.WindowState = WindowState.Normal;
  769. if (IsGameRunning)
  770. {
  771. ShowMenuAndStatusBar = true;
  772. }
  773. }
  774. else
  775. {
  776. _owner.WindowState = WindowState.FullScreen;
  777. if (IsGameRunning)
  778. {
  779. ShowMenuAndStatusBar = false;
  780. }
  781. }
  782. OnPropertyChanged(nameof(IsFullScreen));
  783. }
  784. public bool IsFullScreen => _owner.WindowState == WindowState.FullScreen;
  785. public void ToggleDockMode()
  786. {
  787. if (IsGameRunning)
  788. {
  789. ConfigurationState.Instance.System.EnableDockedMode.Value =
  790. !ConfigurationState.Instance.System.EnableDockedMode.Value;
  791. }
  792. }
  793. public async void ExitCurrentState()
  794. {
  795. if (_owner.WindowState == WindowState.FullScreen)
  796. {
  797. ToggleFullscreen();
  798. }
  799. else if (IsGameRunning)
  800. {
  801. await Task.Delay(100);
  802. _owner.AppHost?.ShowExitPrompt();
  803. }
  804. }
  805. public async void OpenSettings()
  806. {
  807. _owner.SettingsWindow = new(_owner.VirtualFileSystem, _owner.ContentManager);
  808. await _owner.SettingsWindow.ShowDialog(_owner);
  809. LoadConfigurableHotKeys();
  810. }
  811. public async void ManageProfiles()
  812. {
  813. UserProfileWindow window = new(_owner.AccountManager, _owner.ContentManager, _owner.VirtualFileSystem);
  814. await window.ShowDialog(_owner);
  815. }
  816. public async void OpenAboutWindow()
  817. {
  818. AboutWindow window = new();
  819. await window.ShowDialog(_owner);
  820. }
  821. public void ChangeLanguage(object obj)
  822. {
  823. LocaleManager.Instance.LoadDefaultLanguage();
  824. LocaleManager.Instance.LoadLanguage((string)obj);
  825. }
  826. private void ProgressHandler<T>(T state, int current, int total) where T : Enum
  827. {
  828. try
  829. {
  830. ProgressMaximum = total;
  831. ProgressValue = current;
  832. switch (state)
  833. {
  834. case PtcLoadingState ptcState:
  835. CacheLoadStatus = $"{current} / {total}";
  836. switch (ptcState)
  837. {
  838. case PtcLoadingState.Start:
  839. case PtcLoadingState.Loading:
  840. LoadHeading = LocaleManager.Instance["CompilingPPTC"];
  841. IsLoadingIndeterminate = false;
  842. break;
  843. case PtcLoadingState.Loaded:
  844. LoadHeading = string.Format(LocaleManager.Instance["LoadingHeading"], TitleName);
  845. IsLoadingIndeterminate = true;
  846. CacheLoadStatus = "";
  847. break;
  848. }
  849. break;
  850. case ShaderCacheLoadingState shaderCacheState:
  851. CacheLoadStatus = $"{current} / {total}";
  852. switch (shaderCacheState)
  853. {
  854. case ShaderCacheLoadingState.Start:
  855. case ShaderCacheLoadingState.Loading:
  856. LoadHeading = LocaleManager.Instance["CompilingShaders"];
  857. IsLoadingIndeterminate = false;
  858. break;
  859. case ShaderCacheLoadingState.Loaded:
  860. LoadHeading = string.Format(LocaleManager.Instance["LoadingHeading"], TitleName);
  861. IsLoadingIndeterminate = true;
  862. CacheLoadStatus = "";
  863. break;
  864. }
  865. break;
  866. default:
  867. throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
  868. }
  869. }
  870. catch (Exception) { }
  871. }
  872. public void OpenUserSaveDirectory()
  873. {
  874. var selection = SelectedApplication;
  875. if (selection != null)
  876. {
  877. Task.Run(() =>
  878. {
  879. if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
  880. out ulong titleIdNumber))
  881. {
  882. ContentDialogHelper.CreateErrorDialog(_owner,
  883. LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
  884. return;
  885. }
  886. var userId = new LibHac.Fs.UserId((ulong)_owner.AccountManager.LastOpenedUser.UserId.High, (ulong)_owner.AccountManager.LastOpenedUser.UserId.Low);
  887. var saveDataFilter = SaveDataFilter.Make(titleIdNumber, saveType: default, userId, saveDataId: default, index: default);
  888. OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
  889. });
  890. }
  891. }
  892. public void ToggleFavorite()
  893. {
  894. var selection = SelectedApplication;
  895. if (selection != null)
  896. {
  897. selection.Favorite = !selection.Favorite;
  898. RefreshView();
  899. }
  900. }
  901. public void OpenModsDirectory()
  902. {
  903. var selection = SelectedApplication;
  904. if (selection != null)
  905. {
  906. string modsBasePath = _owner.VirtualFileSystem.ModLoader.GetModsBasePath();
  907. string titleModsPath = _owner.VirtualFileSystem.ModLoader.GetTitleDir(modsBasePath, selection.TitleId);
  908. OpenHelper.OpenFolder(titleModsPath);
  909. }
  910. }
  911. public void OpenSdModsDirectory()
  912. {
  913. var selection = SelectedApplication;
  914. if (selection != null)
  915. {
  916. string sdModsBasePath = _owner.VirtualFileSystem.ModLoader.GetSdModsBasePath();
  917. string titleModsPath = _owner.VirtualFileSystem.ModLoader.GetTitleDir(sdModsBasePath, selection.TitleId);
  918. OpenHelper.OpenFolder(titleModsPath);
  919. }
  920. }
  921. public void OpenPtcDirectory()
  922. {
  923. var selection = SelectedApplication;
  924. if (selection != null)
  925. {
  926. string ptcDir = Path.Combine(AppDataManager.GamesDirPath, selection.TitleId, "cache", "cpu");
  927. string mainPath = Path.Combine(ptcDir, "0");
  928. string backupPath = Path.Combine(ptcDir, "1");
  929. if (!Directory.Exists(ptcDir))
  930. {
  931. Directory.CreateDirectory(ptcDir);
  932. Directory.CreateDirectory(mainPath);
  933. Directory.CreateDirectory(backupPath);
  934. }
  935. OpenHelper.OpenFolder(ptcDir);
  936. }
  937. }
  938. public async void PurgePtcCache()
  939. {
  940. var selection = SelectedApplication;
  941. if (selection != null)
  942. {
  943. DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, selection.TitleId, "cache", "cpu", "0"));
  944. DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, selection.TitleId, "cache", "cpu", "1"));
  945. // FIXME: Found a way to reproduce the bold effect on the title name (fork?).
  946. UserResult result = await ContentDialogHelper.CreateConfirmationDialog(_owner, LocaleManager.Instance["DialogWarning"],
  947. string.Format(LocaleManager.Instance["DialogPPTCDeletionMessage"], selection.TitleName), LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"], LocaleManager.Instance["RyujinxConfirm"]);
  948. List<FileInfo> cacheFiles = new();
  949. if (mainDir.Exists)
  950. {
  951. cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache"));
  952. }
  953. if (backupDir.Exists)
  954. {
  955. cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache"));
  956. }
  957. if (cacheFiles.Count > 0 && result == UserResult.Yes)
  958. {
  959. foreach (FileInfo file in cacheFiles)
  960. {
  961. try
  962. {
  963. file.Delete();
  964. }
  965. catch (Exception e)
  966. {
  967. ContentDialogHelper.CreateErrorDialog(_owner, string.Format(LocaleManager.Instance["DialogPPTCDeletionErrorMessage"], file.Name, e));
  968. }
  969. }
  970. }
  971. }
  972. }
  973. public void OpenShaderCacheDirectory()
  974. {
  975. var selection = SelectedApplication;
  976. if (selection != null)
  977. {
  978. string shaderCacheDir = Path.Combine(AppDataManager.GamesDirPath, selection.TitleId, "cache", "shader");
  979. if (!Directory.Exists(shaderCacheDir))
  980. {
  981. Directory.CreateDirectory(shaderCacheDir);
  982. }
  983. OpenHelper.OpenFolder(shaderCacheDir);
  984. }
  985. }
  986. public void SimulateWakeUpMessage()
  987. {
  988. _owner.AppHost.Device.System.SimulateWakeUpMessage();
  989. }
  990. public async void PurgeShaderCache()
  991. {
  992. var selection = SelectedApplication;
  993. if (selection != null)
  994. {
  995. DirectoryInfo shaderCacheDir = new(Path.Combine(AppDataManager.GamesDirPath, selection.TitleId, "cache", "shader"));
  996. // FIXME: Found a way to reproduce the bold effect on the title name (fork?).
  997. UserResult result = await ContentDialogHelper.CreateConfirmationDialog(_owner, LocaleManager.Instance["DialogWarning"],
  998. string.Format(LocaleManager.Instance["DialogShaderDeletionMessage"], selection.TitleName), LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"], LocaleManager.Instance["RyujinxConfirm"]);
  999. List<DirectoryInfo> oldCacheDirectories = new List<DirectoryInfo>();
  1000. List<FileInfo> newCacheFiles = new List<FileInfo>();
  1001. if (shaderCacheDir.Exists)
  1002. {
  1003. oldCacheDirectories.AddRange(shaderCacheDir.EnumerateDirectories("*"));
  1004. newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.toc"));
  1005. newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.data"));
  1006. }
  1007. if ((oldCacheDirectories.Count > 0 || newCacheFiles.Count > 0) && result == UserResult.Yes)
  1008. {
  1009. foreach (DirectoryInfo directory in oldCacheDirectories)
  1010. {
  1011. try
  1012. {
  1013. directory.Delete(true);
  1014. }
  1015. catch (Exception e)
  1016. {
  1017. ContentDialogHelper.CreateErrorDialog(_owner, string.Format(LocaleManager.Instance["DialogPPTCDeletionErrorMessage"], directory.Name, e));
  1018. }
  1019. }
  1020. }
  1021. foreach (FileInfo file in newCacheFiles)
  1022. {
  1023. try
  1024. {
  1025. file.Delete();
  1026. }
  1027. catch (Exception e)
  1028. {
  1029. ContentDialogHelper.CreateErrorDialog(_owner, string.Format(LocaleManager.Instance["ShaderCachePurgeError"], file.Name, e));
  1030. }
  1031. }
  1032. }
  1033. }
  1034. public async void CheckForUpdates()
  1035. {
  1036. if (Updater.CanUpdate(true, _owner))
  1037. {
  1038. await Updater.BeginParse(_owner, true);
  1039. }
  1040. }
  1041. public async void OpenTitleUpdateManager()
  1042. {
  1043. var selection = SelectedApplication;
  1044. if (selection != null)
  1045. {
  1046. TitleUpdateWindow titleUpdateManager =
  1047. new(_owner.VirtualFileSystem, selection.TitleId, selection.TitleName);
  1048. await titleUpdateManager.ShowDialog(_owner);
  1049. }
  1050. }
  1051. public async void OpenDlcManager()
  1052. {
  1053. var selection = SelectedApplication;
  1054. if (selection != null)
  1055. {
  1056. DlcManagerWindow dlcManager = new(_owner.VirtualFileSystem, ulong.Parse(selection.TitleId, NumberStyles.HexNumber), selection.TitleName);
  1057. await dlcManager.ShowDialog(_owner);
  1058. }
  1059. }
  1060. public async void OpenCheatManager()
  1061. {
  1062. var selection = SelectedApplication;
  1063. if (selection != null)
  1064. {
  1065. CheatWindow cheatManager = new(_owner.VirtualFileSystem, selection.TitleId, selection.TitleName);
  1066. await cheatManager.ShowDialog(_owner);
  1067. }
  1068. }
  1069. public async void OpenCheatManagerForCurrentApp()
  1070. {
  1071. if (!IsGameRunning)
  1072. {
  1073. return;
  1074. }
  1075. var application = _owner.AppHost.Device.Application;
  1076. if (application != null)
  1077. {
  1078. CheatWindow cheatManager = new(_owner.VirtualFileSystem, application.TitleIdText, application.TitleName);
  1079. await cheatManager.ShowDialog(_owner);
  1080. _owner.AppHost.Device.EnableCheats();
  1081. }
  1082. }
  1083. public void OpenDeviceSaveDirectory()
  1084. {
  1085. var selection = SelectedApplication;
  1086. if (selection != null)
  1087. {
  1088. Task.Run(() =>
  1089. {
  1090. if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
  1091. out ulong titleIdNumber))
  1092. {
  1093. ContentDialogHelper.CreateErrorDialog(_owner,
  1094. LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
  1095. return;
  1096. }
  1097. var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Device, userId: default, saveDataId: default, index: default);
  1098. OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
  1099. });
  1100. }
  1101. }
  1102. public void OpenBcatSaveDirectory()
  1103. {
  1104. var selection = SelectedApplication;
  1105. if (selection != null)
  1106. {
  1107. Task.Run(() =>
  1108. {
  1109. if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
  1110. out ulong titleIdNumber))
  1111. {
  1112. ContentDialogHelper.CreateErrorDialog(_owner,
  1113. LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
  1114. return;
  1115. }
  1116. var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Bcat, userId: default, saveDataId: default, index: default);
  1117. OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
  1118. });
  1119. }
  1120. }
  1121. private void OpenSaveDirectory(in SaveDataFilter filter, ApplicationData data, ulong titleId)
  1122. {
  1123. ApplicationHelper.OpenSaveDir(in filter, titleId, data.ControlHolder, data.TitleName);
  1124. }
  1125. private void ExtractLogo()
  1126. {
  1127. var selection = SelectedApplication;
  1128. if (selection != null)
  1129. {
  1130. ApplicationHelper.ExtractSection(NcaSectionType.Logo, selection.Path);
  1131. }
  1132. }
  1133. private void ExtractRomFs()
  1134. {
  1135. var selection = SelectedApplication;
  1136. if (selection != null)
  1137. {
  1138. ApplicationHelper.ExtractSection(NcaSectionType.Data, selection.Path);
  1139. }
  1140. }
  1141. private void ExtractExeFs()
  1142. {
  1143. var selection = SelectedApplication;
  1144. if (selection != null)
  1145. {
  1146. ApplicationHelper.ExtractSection(NcaSectionType.Code, selection.Path);
  1147. }
  1148. }
  1149. public void CloseWindow()
  1150. {
  1151. _owner.Close();
  1152. }
  1153. private async void HandleFirmwareInstallation(string path)
  1154. {
  1155. try
  1156. {
  1157. string filename = path;
  1158. SystemVersion firmwareVersion = _owner.ContentManager.VerifyFirmwarePackage(filename);
  1159. if (firmwareVersion == null)
  1160. {
  1161. ContentDialogHelper.CreateErrorDialog(_owner, string.Format(LocaleManager.Instance["DialogFirmwareInstallerFirmwareNotFoundErrorMessage"], filename));
  1162. return;
  1163. }
  1164. string dialogTitle = string.Format(LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallTitle"], firmwareVersion.VersionString);
  1165. SystemVersion currentVersion = _owner.ContentManager.GetCurrentFirmwareVersion();
  1166. string dialogMessage = string.Format(LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallMessage"], firmwareVersion.VersionString);
  1167. if (currentVersion != null)
  1168. {
  1169. dialogMessage += string.Format(LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallSubMessage"], currentVersion.VersionString);
  1170. }
  1171. dialogMessage += LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallConfirmMessage"];
  1172. UserResult result = await ContentDialogHelper.CreateConfirmationDialog(
  1173. _owner,
  1174. dialogTitle,
  1175. dialogMessage,
  1176. LocaleManager.Instance["InputDialogYes"],
  1177. LocaleManager.Instance["InputDialogNo"],
  1178. LocaleManager.Instance["RyujinxConfirm"]);
  1179. UpdateWaitWindow waitingDialog = ContentDialogHelper.CreateWaitingDialog(dialogTitle, LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallWaitMessage"]);
  1180. if (result == UserResult.Yes)
  1181. {
  1182. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  1183. Thread thread = new(() =>
  1184. {
  1185. Dispatcher.UIThread.InvokeAsync(delegate
  1186. {
  1187. waitingDialog.Show();
  1188. });
  1189. try
  1190. {
  1191. _owner.ContentManager.InstallFirmware(filename);
  1192. Dispatcher.UIThread.InvokeAsync(async delegate
  1193. {
  1194. waitingDialog.Close();
  1195. string message = string.Format(LocaleManager.Instance["DialogFirmwareInstallerFirmwareInstallSuccessMessage"], firmwareVersion.VersionString);
  1196. await ContentDialogHelper.CreateInfoDialog(_owner, dialogTitle, message, LocaleManager.Instance["InputDialogOk"], "", LocaleManager.Instance["RyujinxInfo"]);
  1197. Logger.Info?.Print(LogClass.Application, message);
  1198. // Purge Applet Cache.
  1199. DirectoryInfo miiEditorCacheFolder = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, "0100000000001009", "cache"));
  1200. if (miiEditorCacheFolder.Exists)
  1201. {
  1202. miiEditorCacheFolder.Delete(true);
  1203. }
  1204. });
  1205. }
  1206. catch (Exception ex)
  1207. {
  1208. Dispatcher.UIThread.InvokeAsync(() =>
  1209. {
  1210. waitingDialog.Close();
  1211. ContentDialogHelper.CreateErrorDialog(_owner, ex.Message);
  1212. });
  1213. }
  1214. finally
  1215. {
  1216. _owner.RefreshFirmwareStatus();
  1217. }
  1218. });
  1219. thread.Name = "GUI.FirmwareInstallerThread";
  1220. thread.Start();
  1221. }
  1222. }
  1223. catch (LibHac.Common.Keys.MissingKeyException ex)
  1224. {
  1225. Logger.Error?.Print(LogClass.Application, ex.ToString());
  1226. Dispatcher.UIThread.Post(async () => await
  1227. UserErrorDialog.ShowUserErrorDialog(UserError.NoKeys, _owner));
  1228. }
  1229. catch (Exception ex)
  1230. {
  1231. ContentDialogHelper.CreateErrorDialog(_owner, ex.Message);
  1232. }
  1233. }
  1234. public async void InstallFirmwareFromFile()
  1235. {
  1236. OpenFileDialog dialog = new() { AllowMultiple = false };
  1237. dialog.Filters.Add(new FileDialogFilter { Name = LocaleManager.Instance["FileDialogAllTypes"], Extensions = { "xci", "zip" } });
  1238. dialog.Filters.Add(new FileDialogFilter { Name = "XCI", Extensions = { "xci" } });
  1239. dialog.Filters.Add(new FileDialogFilter { Name = "ZIP", Extensions = { "zip" } });
  1240. string[] file = await dialog.ShowAsync(_owner);
  1241. if (file != null && file.Length > 0)
  1242. {
  1243. HandleFirmwareInstallation(file[0]);
  1244. }
  1245. }
  1246. public async void InstallFirmwareFromFolder()
  1247. {
  1248. OpenFolderDialog dialog = new();
  1249. string folder = await dialog.ShowAsync(_owner);
  1250. if (!string.IsNullOrWhiteSpace(folder))
  1251. {
  1252. HandleFirmwareInstallation(folder);
  1253. }
  1254. }
  1255. }
  1256. }