2022-07-29 00:41:34 +02:00
|
|
|
using Avalonia.Controls;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using Avalonia.Styling;
|
|
|
|
|
using FluentAvalonia.UI.Controls;
|
2025-01-20 09:28:48 -06:00
|
|
|
using LibHac.Tools.FsSystem.NcaUtils;
|
|
|
|
|
using Ryujinx.Ava.Common;
|
2022-07-29 00:41:34 +02:00
|
|
|
using Ryujinx.Ava.Common.Locale;
|
2024-12-29 19:09:28 -06:00
|
|
|
using Ryujinx.Ava.Common.Models;
|
2023-03-14 16:04:38 +00:00
|
|
|
using Ryujinx.Ava.UI.ViewModels;
|
2024-12-29 19:09:28 -06:00
|
|
|
using Ryujinx.Ava.Utilities.AppLibrary;
|
2024-12-29 19:28:27 -06:00
|
|
|
using Ryujinx.Common.Helper;
|
2022-07-29 00:41:34 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2022-12-29 14:24:05 +00:00
|
|
|
namespace Ryujinx.Ava.UI.Windows
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
public partial class DownloadableContentManagerWindow : UserControl
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
public DownloadableContentManagerViewModel ViewModel;
|
2022-07-29 00:41:34 +02:00
|
|
|
|
|
|
|
|
public DownloadableContentManagerWindow()
|
|
|
|
|
{
|
|
|
|
|
DataContext = this;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-07 21:08:41 -04:00
|
|
|
public DownloadableContentManagerWindow(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2024-10-07 21:08:41 -04:00
|
|
|
DataContext = ViewModel = new DownloadableContentManagerViewModel(applicationLibrary, applicationData);
|
2022-07-29 00:41:34 +02:00
|
|
|
|
|
|
|
|
InitializeComponent();
|
2023-03-14 16:04:38 +00:00
|
|
|
}
|
2022-07-29 00:41:34 +02:00
|
|
|
|
2024-10-07 21:08:41 -04:00
|
|
|
public static async Task Show(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
|
2023-03-14 16:04:38 +00:00
|
|
|
{
|
|
|
|
|
ContentDialog contentDialog = new()
|
|
|
|
|
{
|
2024-11-01 11:57:23 -05:00
|
|
|
PrimaryButtonText = string.Empty,
|
|
|
|
|
SecondaryButtonText = string.Empty,
|
|
|
|
|
CloseButtonText = string.Empty,
|
2024-10-07 21:08:41 -04:00
|
|
|
Content = new DownloadableContentManagerWindow(applicationLibrary, applicationData),
|
2024-07-21 19:42:23 +02:00
|
|
|
Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], applicationData.Name, applicationData.IdBaseString),
|
2023-03-14 16:04:38 +00:00
|
|
|
};
|
2022-11-25 12:41:34 +01:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
|
|
|
|
|
bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
|
2022-11-25 12:41:34 +01:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
contentDialog.Styles.Add(bottomBorder);
|
2022-07-29 00:41:34 +02:00
|
|
|
|
2024-03-16 19:34:26 +00:00
|
|
|
await contentDialog.ShowAsync();
|
2022-11-25 12:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
|
2022-11-25 12:41:34 +01:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
ViewModel.Save();
|
|
|
|
|
((ContentDialog)Parent).Hide();
|
2022-11-25 12:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void Close(object sender, RoutedEventArgs e)
|
2022-11-25 12:41:34 +01:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
((ContentDialog)Parent).Hide();
|
2022-07-29 00:41:34 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void RemoveDLC(object sender, RoutedEventArgs e)
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2024-12-07 05:48:11 -06:00
|
|
|
if (sender is Button { DataContext: DownloadableContentModel dlc })
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2024-12-07 05:48:11 -06:00
|
|
|
ViewModel.Remove(dlc);
|
2022-07-29 00:41:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void OpenLocation(object sender, RoutedEventArgs e)
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2024-12-07 05:48:11 -06:00
|
|
|
if (sender is Button { DataContext: DownloadableContentModel dlc })
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2024-12-07 05:48:11 -06:00
|
|
|
OpenHelper.LocateFile(dlc.ContainerPath);
|
2022-07-29 00:41:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
foreach (var content in e.AddedItems)
|
2022-07-29 00:41:34 +02:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (content is DownloadableContentModel model)
|
2022-11-25 12:41:34 +01:00
|
|
|
{
|
2024-10-07 21:08:41 -04:00
|
|
|
ViewModel.Enable(model);
|
2022-07-29 00:41:34 +02:00
|
|
|
}
|
2022-11-25 12:41:34 +01:00
|
|
|
}
|
2022-07-29 00:41:34 +02:00
|
|
|
|
2023-03-14 16:04:38 +00:00
|
|
|
foreach (var content in e.RemovedItems)
|
2022-11-25 12:41:34 +01:00
|
|
|
{
|
2023-03-14 16:04:38 +00:00
|
|
|
if (content is DownloadableContentModel model)
|
2022-11-25 12:41:34 +01:00
|
|
|
{
|
2024-10-07 21:08:41 -04:00
|
|
|
ViewModel.Disable(model);
|
2022-07-29 00:41:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-07 23:03:27 +02:00
|
|
|
}
|