TitleUpdateWindow.axaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.Common.Utilities;
  10. using Ryujinx.HLE.FileSystem;
  11. using Ryujinx.Ui.Common.Helper;
  12. using System.IO;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using Button = Avalonia.Controls.Button;
  16. namespace Ryujinx.Ava.UI.Windows
  17. {
  18. public partial class TitleUpdateWindow : UserControl
  19. {
  20. public TitleUpdateViewModel ViewModel;
  21. public TitleUpdateWindow()
  22. {
  23. DataContext = this;
  24. InitializeComponent();
  25. }
  26. public TitleUpdateWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  27. {
  28. DataContext = ViewModel = new TitleUpdateViewModel(virtualFileSystem, titleId, titleName);
  29. InitializeComponent();
  30. }
  31. public static async Task Show(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  32. {
  33. ContentDialog contentDialog = new()
  34. {
  35. PrimaryButtonText = "",
  36. SecondaryButtonText = "",
  37. CloseButtonText = "",
  38. Content = new TitleUpdateWindow(virtualFileSystem, titleId, titleName),
  39. Title = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.GameUpdateWindowHeading, titleName, titleId.ToString("X16"))
  40. };
  41. Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
  42. bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
  43. contentDialog.Styles.Add(bottomBorder);
  44. await ContentDialogHelper.ShowAsync(contentDialog);
  45. }
  46. private void Close(object sender, RoutedEventArgs e)
  47. {
  48. ((ContentDialog)Parent).Hide();
  49. }
  50. public void Save(object sender, RoutedEventArgs e)
  51. {
  52. ViewModel.Save();
  53. if (VisualRoot is MainWindow window)
  54. {
  55. window.ViewModel.LoadApplications();
  56. }
  57. ((ContentDialog)Parent).Hide();
  58. }
  59. private void OpenLocation(object sender, RoutedEventArgs e)
  60. {
  61. if (sender is Button button)
  62. {
  63. if (button.DataContext is TitleUpdateModel model)
  64. {
  65. OpenHelper.LocateFile(model.Path);
  66. }
  67. }
  68. }
  69. private void RemoveUpdate(object sender, RoutedEventArgs e)
  70. {
  71. if (sender is Button button)
  72. {
  73. ViewModel.RemoveUpdate((TitleUpdateModel)button.DataContext);
  74. }
  75. }
  76. private void RemoveAll(object sender, RoutedEventArgs e)
  77. {
  78. ViewModel.TitleUpdates.Clear();
  79. ViewModel.SortUpdates();
  80. }
  81. }
  82. }