/ src / Ryujinx / UI / Windows / TitleUpdateWindow.axaml.cs
TitleUpdateWindow.axaml.cs
  1  using Avalonia;
  2  using Avalonia.Controls;
  3  using Avalonia.Controls.ApplicationLifetimes;
  4  using Avalonia.Interactivity;
  5  using Avalonia.Styling;
  6  using FluentAvalonia.UI.Controls;
  7  using Ryujinx.Ava.Common.Locale;
  8  using Ryujinx.Ava.UI.Models;
  9  using Ryujinx.Ava.UI.ViewModels;
 10  using Ryujinx.HLE.FileSystem;
 11  using Ryujinx.UI.App.Common;
 12  using Ryujinx.UI.Common.Helper;
 13  using System.Threading.Tasks;
 14  
 15  namespace Ryujinx.Ava.UI.Windows
 16  {
 17      public partial class TitleUpdateWindow : UserControl
 18      {
 19          public readonly TitleUpdateViewModel ViewModel;
 20  
 21          public TitleUpdateWindow()
 22          {
 23              DataContext = this;
 24  
 25              InitializeComponent();
 26          }
 27  
 28          public TitleUpdateWindow(VirtualFileSystem virtualFileSystem, ApplicationData applicationData)
 29          {
 30              DataContext = ViewModel = new TitleUpdateViewModel(virtualFileSystem, applicationData);
 31  
 32              InitializeComponent();
 33          }
 34  
 35          public static async Task Show(VirtualFileSystem virtualFileSystem, ApplicationData applicationData)
 36          {
 37              ContentDialog contentDialog = new()
 38              {
 39                  PrimaryButtonText = "",
 40                  SecondaryButtonText = "",
 41                  CloseButtonText = "",
 42                  Content = new TitleUpdateWindow(virtualFileSystem, applicationData),
 43                  Title = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.GameUpdateWindowHeading, applicationData.Name, applicationData.IdBaseString),
 44              };
 45  
 46              Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
 47              bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
 48  
 49              contentDialog.Styles.Add(bottomBorder);
 50  
 51              await contentDialog.ShowAsync();
 52          }
 53  
 54          private void Close(object sender, RoutedEventArgs e)
 55          {
 56              ((ContentDialog)Parent).Hide();
 57          }
 58  
 59          public void Save(object sender, RoutedEventArgs e)
 60          {
 61              ViewModel.Save();
 62  
 63              if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime al)
 64              {
 65                  foreach (Window window in al.Windows)
 66                  {
 67                      if (window is MainWindow mainWindow)
 68                      {
 69                          mainWindow.LoadApplications();
 70                      }
 71                  }
 72              }
 73  
 74              ((ContentDialog)Parent).Hide();
 75          }
 76  
 77          private void OpenLocation(object sender, RoutedEventArgs e)
 78          {
 79              if (sender is Button button)
 80              {
 81                  if (button.DataContext is TitleUpdateModel model)
 82                  {
 83                      OpenHelper.LocateFile(model.Path);
 84                  }
 85              }
 86          }
 87  
 88          private void RemoveUpdate(object sender, RoutedEventArgs e)
 89          {
 90              if (sender is Button button)
 91              {
 92                  ViewModel.RemoveUpdate((TitleUpdateModel)button.DataContext);
 93              }
 94          }
 95  
 96          private void RemoveAll(object sender, RoutedEventArgs e)
 97          {
 98              ViewModel.TitleUpdates.Clear();
 99  
100              ViewModel.SortUpdates();
101          }
102      }
103  }