DownloadableContentManagerWindow.axaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Styling;
  4. using FluentAvalonia.UI.Controls;
  5. using LibHac.Tools.FsSystem.NcaUtils;
  6. using Ryujinx.Ava.Common;
  7. using Ryujinx.Ava.Common.Locale;
  8. using Ryujinx.Ava.Common.Models;
  9. using Ryujinx.Ava.UI.ViewModels;
  10. using Ryujinx.Ava.Utilities.AppLibrary;
  11. using Ryujinx.Common.Helper;
  12. using System.Threading.Tasks;
  13. namespace Ryujinx.Ava.UI.Windows
  14. {
  15. public partial class DownloadableContentManagerWindow : UserControl
  16. {
  17. public DownloadableContentManagerViewModel ViewModel;
  18. public DownloadableContentManagerWindow()
  19. {
  20. DataContext = this;
  21. InitializeComponent();
  22. }
  23. public DownloadableContentManagerWindow(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
  24. {
  25. DataContext = ViewModel = new DownloadableContentManagerViewModel(applicationLibrary, applicationData);
  26. InitializeComponent();
  27. }
  28. public static async Task Show(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
  29. {
  30. ContentDialog contentDialog = new()
  31. {
  32. PrimaryButtonText = string.Empty,
  33. SecondaryButtonText = string.Empty,
  34. CloseButtonText = string.Empty,
  35. Content = new DownloadableContentManagerWindow(applicationLibrary, applicationData),
  36. Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], applicationData.Name, applicationData.IdBaseString),
  37. };
  38. Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
  39. bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
  40. contentDialog.Styles.Add(bottomBorder);
  41. await contentDialog.ShowAsync();
  42. }
  43. private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
  44. {
  45. ViewModel.Save();
  46. ((ContentDialog)Parent).Hide();
  47. }
  48. private void Close(object sender, RoutedEventArgs e)
  49. {
  50. ((ContentDialog)Parent).Hide();
  51. }
  52. private void RemoveDLC(object sender, RoutedEventArgs e)
  53. {
  54. if (sender is Button { DataContext: DownloadableContentModel dlc })
  55. {
  56. ViewModel.Remove(dlc);
  57. }
  58. }
  59. private void OpenLocation(object sender, RoutedEventArgs e)
  60. {
  61. if (sender is Button { DataContext: DownloadableContentModel dlc })
  62. {
  63. OpenHelper.LocateFile(dlc.ContainerPath);
  64. }
  65. }
  66. private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  67. {
  68. foreach (var content in e.AddedItems)
  69. {
  70. if (content is DownloadableContentModel model)
  71. {
  72. ViewModel.Enable(model);
  73. }
  74. }
  75. foreach (var content in e.RemovedItems)
  76. {
  77. if (content is DownloadableContentModel model)
  78. {
  79. ViewModel.Disable(model);
  80. }
  81. }
  82. }
  83. private async void DlcItem_DumpRomfs(object sender, RoutedEventArgs e)
  84. {
  85. if (sender is not Button { DataContext: DownloadableContentModel dlc }) return;
  86. if (RyujinxApp.MainWindow.ViewModel is not { } viewModel)
  87. return;
  88. await ApplicationHelper.ExtractAoc(
  89. viewModel.StorageProvider,
  90. NcaSectionType.Data,
  91. dlc.ContainerPath,
  92. dlc.FileName);
  93. }
  94. }
  95. }