MainWindowViewModel.cs 47 KB

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