TitleUpdateWindow.axaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Styling;
  4. using FluentAvalonia.UI.Controls;
  5. using Ryujinx.Ava.Common.Locale;
  6. using Ryujinx.Ava.UI.Helpers;
  7. using Ryujinx.Ava.UI.Models;
  8. using Ryujinx.Ava.UI.ViewModels;
  9. using Ryujinx.HLE.FileSystem;
  10. using Ryujinx.Ui.Common.Helper;
  11. using System.Threading.Tasks;
  12. using Button = Avalonia.Controls.Button;
  13. namespace Ryujinx.Ava.UI.Windows
  14. {
  15. public partial class TitleUpdateWindow : UserControl
  16. {
  17. public TitleUpdateViewModel ViewModel;
  18. public TitleUpdateWindow()
  19. {
  20. DataContext = this;
  21. InitializeComponent();
  22. }
  23. public TitleUpdateWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  24. {
  25. DataContext = ViewModel = new TitleUpdateViewModel(virtualFileSystem, titleId, titleName);
  26. InitializeComponent();
  27. }
  28. public static async Task Show(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  29. {
  30. ContentDialog contentDialog = new()
  31. {
  32. PrimaryButtonText = "",
  33. SecondaryButtonText = "",
  34. CloseButtonText = "",
  35. Content = new TitleUpdateWindow(virtualFileSystem, titleId, titleName),
  36. Title = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.GameUpdateWindowHeading, titleName, titleId.ToString("X16"))
  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 ContentDialogHelper.ShowAsync(contentDialog);
  42. }
  43. private void Close(object sender, RoutedEventArgs e)
  44. {
  45. ((ContentDialog)Parent).Hide();
  46. }
  47. public void Save(object sender, RoutedEventArgs e)
  48. {
  49. ViewModel.Save();
  50. if (VisualRoot is MainWindow window)
  51. {
  52. window.ViewModel.LoadApplications();
  53. }
  54. ((ContentDialog)Parent).Hide();
  55. }
  56. private void OpenLocation(object sender, RoutedEventArgs e)
  57. {
  58. if (sender is Button button)
  59. {
  60. if (button.DataContext is TitleUpdateModel model)
  61. {
  62. OpenHelper.LocateFile(model.Path);
  63. }
  64. }
  65. }
  66. private void RemoveUpdate(object sender, RoutedEventArgs e)
  67. {
  68. if (sender is Button button)
  69. {
  70. ViewModel.RemoveUpdate((TitleUpdateModel)button.DataContext);
  71. }
  72. }
  73. private void RemoveAll(object sender, RoutedEventArgs e)
  74. {
  75. ViewModel.TitleUpdates.Clear();
  76. ViewModel.SortUpdates();
  77. }
  78. }
  79. }