2022-07-08 11:47:11 -07:00
|
|
|
using Avalonia.Controls;
|
2023-01-15 03:11:52 -08:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Styling;
|
|
|
|
using FluentAvalonia.UI.Controls;
|
2022-07-08 11:47:11 -07:00
|
|
|
using Ryujinx.Ava.Common.Locale;
|
2022-12-29 06:24:05 -08:00
|
|
|
using Ryujinx.Ava.UI.Helpers;
|
|
|
|
using Ryujinx.Ava.UI.Models;
|
2023-01-15 03:11:52 -08:00
|
|
|
using Ryujinx.Ava.UI.ViewModels;
|
2022-07-08 11:47:11 -07:00
|
|
|
using Ryujinx.Common.Utilities;
|
|
|
|
using Ryujinx.HLE.FileSystem;
|
2023-01-15 03:11:52 -08:00
|
|
|
using Ryujinx.Ui.Common.Helper;
|
2022-07-08 11:47:11 -07:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
2023-01-15 03:11:52 -08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Button = Avalonia.Controls.Button;
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2022-12-29 06:24:05 -08:00
|
|
|
namespace Ryujinx.Ava.UI.Windows
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
public partial class TitleUpdateWindow : UserControl
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
public TitleUpdateViewModel ViewModel;
|
2022-07-08 11:47:11 -07:00
|
|
|
|
|
|
|
public TitleUpdateWindow()
|
|
|
|
{
|
|
|
|
DataContext = this;
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2022-11-25 08:55:08 -08:00
|
|
|
public TitleUpdateWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
DataContext = ViewModel = new TitleUpdateViewModel(virtualFileSystem, titleId, titleName);
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
public static async Task Show(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
|
|
|
|
{
|
|
|
|
ContentDialog contentDialog = new()
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
PrimaryButtonText = "",
|
|
|
|
SecondaryButtonText = "",
|
|
|
|
CloseButtonText = "",
|
|
|
|
Content = new TitleUpdateWindow(virtualFileSystem, titleId, titleName),
|
|
|
|
Title = string.Format(LocaleManager.Instance[LocaleKeys.GameUpdateWindowHeading], titleName, titleId.ToString("X16"))
|
|
|
|
};
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
|
|
|
|
bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
contentDialog.Styles.Add(bottomBorder);
|
2022-07-28 15:41:34 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
await ContentDialogHelper.ShowAsync(contentDialog);
|
2022-11-25 08:55:08 -08:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
private void Close(object sender, RoutedEventArgs e)
|
2022-11-25 08:55:08 -08:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
((ContentDialog)Parent).Hide();
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
public void Save(object sender, RoutedEventArgs e)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel._titleUpdateWindowData.Paths.Clear();
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel._titleUpdateWindowData.Selected = "";
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
foreach (TitleUpdateModel update in ViewModel.TitleUpdates)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel._titleUpdateWindowData.Paths.Add(update.Path);
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
if (update == ViewModel.SelectedUpdate)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel._titleUpdateWindowData.Selected = update.Path;
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
using (FileStream titleUpdateJsonStream = File.Create(ViewModel._titleUpdateJsonPath, 4096, FileOptions.WriteThrough))
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
titleUpdateJsonStream.Write(Encoding.UTF8.GetBytes(JsonHelper.Serialize(ViewModel._titleUpdateWindowData, true)));
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
if (VisualRoot is MainWindow window)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
window.ViewModel.LoadApplications();
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
((ContentDialog)Parent).Hide();
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
private void OpenLocation(object sender, RoutedEventArgs e)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
if (sender is Button button)
|
2022-07-28 15:41:34 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
if (button.DataContext is TitleUpdateModel model)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
OpenHelper.LocateFile(model.Path);
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
private void RemoveUpdate(object sender, RoutedEventArgs e)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
if (sender is Button button)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel.RemoveUpdate((TitleUpdateModel)button.DataContext);
|
|
|
|
}
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
private void RemoveAll(object sender, RoutedEventArgs e)
|
2022-07-08 11:47:11 -07:00
|
|
|
{
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel.TitleUpdates.Clear();
|
2022-07-08 11:47:11 -07:00
|
|
|
|
2023-01-15 03:11:52 -08:00
|
|
|
ViewModel.SortUpdates();
|
2022-07-08 11:47:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|