From 76671d63d4f3ea18f8ad99e9ce9f0b2ec9a2599d Mon Sep 17 00:00:00 2001
From: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>
Date: Thu, 29 Dec 2022 14:24:05 +0000
Subject: Ava GUI: Restructure `Ryujinx.Ava` (#4165)
* Restructure `Ryujinx.Ava`
* Stylistic consistency
* Update Ryujinx.Ava/UI/Controls/UserEditor.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Controls/UserEditor.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Controls/UserSelector.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Controls/SaveManager.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Controls/SaveManager.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/ViewModels/UserProfileViewModel.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/ViewModels/UserProfileViewModel.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Ava/UI/Helpers/EmbeddedWindow.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Fix redundancies
* Remove redunancies
* Add back elses
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
---
Ryujinx.Ava/UI/Windows/AboutWindow.axaml | 282 +++++
Ryujinx.Ava/UI/Windows/AboutWindow.axaml.cs | 78 ++
Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml | 74 ++
Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml.cs | 59 +
Ryujinx.Ava/UI/Windows/AvatarWindow.axaml | 54 +
Ryujinx.Ava/UI/Windows/AvatarWindow.axaml.cs | 77 ++
Ryujinx.Ava/UI/Windows/CheatWindow.axaml | 106 ++
Ryujinx.Ava/UI/Windows/CheatWindow.axaml.cs | 119 ++
.../UI/Windows/ContentDialogOverlayWindow.axaml | 29 +
.../UI/Windows/ContentDialogOverlayWindow.axaml.cs | 25 +
.../UI/Windows/ControllerSettingsWindow.axaml | 1169 ++++++++++++++++++++
.../UI/Windows/ControllerSettingsWindow.axaml.cs | 181 +++
.../Windows/DownloadableContentManagerWindow.axaml | 172 +++
.../DownloadableContentManagerWindow.axaml.cs | 314 ++++++
Ryujinx.Ava/UI/Windows/IconColorPicker.cs | 192 ++++
Ryujinx.Ava/UI/Windows/MainWindow.axaml | 770 +++++++++++++
Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs | 721 ++++++++++++
Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml | 141 +++
.../UI/Windows/MotionSettingsWindow.axaml.cs | 71 ++
Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml | 57 +
.../UI/Windows/RumbleSettingsWindow.axaml.cs | 57 +
Ryujinx.Ava/UI/Windows/SettingsWindow.axaml | 980 ++++++++++++++++
Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs | 213 ++++
Ryujinx.Ava/UI/Windows/StyleableWindow.cs | 39 +
Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml | 115 ++
Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml.cs | 271 +++++
26 files changed, 6366 insertions(+)
create mode 100644 Ryujinx.Ava/UI/Windows/AboutWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/AboutWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/AvatarWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/AvatarWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/CheatWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/CheatWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/IconColorPicker.cs
create mode 100644 Ryujinx.Ava/UI/Windows/MainWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/SettingsWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs
create mode 100644 Ryujinx.Ava/UI/Windows/StyleableWindow.cs
create mode 100644 Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml
create mode 100644 Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml.cs
(limited to 'Ryujinx.Ava/UI/Windows')
diff --git a/Ryujinx.Ava/UI/Windows/AboutWindow.axaml b/Ryujinx.Ava/UI/Windows/AboutWindow.axaml
new file mode 100644
index 00000000..08d28740
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AboutWindow.axaml
@@ -0,0 +1,282 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ryujinx.Ava/UI/Windows/AboutWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/AboutWindow.axaml.cs
new file mode 100644
index 00000000..2fb17e3a
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AboutWindow.axaml.cs
@@ -0,0 +1,78 @@
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.Threading;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Common.Utilities;
+using Ryujinx.Ui.Common.Helper;
+using System.Net.Http;
+using System.Net.NetworkInformation;
+using System.Threading.Tasks;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class AboutWindow : StyleableWindow
+ {
+ public AboutWindow()
+ {
+ if (Program.PreviewerDetached)
+ {
+ Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["MenuBarHelpAbout"];
+ }
+
+ Version = Program.Version;
+
+ DataContext = this;
+
+ InitializeComponent();
+
+ _ = DownloadPatronsJson();
+ }
+
+ public string Supporters { get; set; }
+ public string Version { get; set; }
+
+ public string Developers => string.Format(LocaleManager.Instance["AboutPageDeveloperListMore"], "gdkchan, Ac_K, Thog, rip in peri peri, LDj3SNuD, emmaus, Thealexbarney, Xpl0itR, GoffyDude, »jD«");
+
+ private void Button_OnClick(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button button)
+ {
+ OpenHelper.OpenUrl(button.Tag.ToString());
+ }
+ }
+
+ private async Task DownloadPatronsJson()
+ {
+ if (!NetworkInterface.GetIsNetworkAvailable())
+ {
+ Supporters = LocaleManager.Instance["ConnectionError"];
+
+ return;
+ }
+
+ HttpClient httpClient = new();
+
+ try
+ {
+ string patreonJsonString = await httpClient.GetStringAsync("https://patreon.ryujinx.org/");
+
+ Supporters = string.Join(", ", JsonHelper.Deserialize(patreonJsonString));
+ }
+ catch
+ {
+ Supporters = LocaleManager.Instance["ApiError"];
+ }
+
+ await Dispatcher.UIThread.InvokeAsync(() => SupportersTextBlock.Text = Supporters);
+ }
+
+ private void AmiiboLabel_OnPointerPressed(object sender, PointerPressedEventArgs e)
+ {
+ if (sender is TextBlock)
+ {
+ OpenHelper.OpenUrl("https://amiiboapi.com");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml b/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml
new file mode 100644
index 00000000..90d47b8e
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml.cs
new file mode 100644
index 00000000..68d16f35
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AmiiboWindow.axaml.cs
@@ -0,0 +1,59 @@
+using Avalonia.Interactivity;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class AmiiboWindow : StyleableWindow
+ {
+ public AmiiboWindow(bool showAll, string lastScannedAmiiboId, string titleId)
+ {
+ ViewModel = new AmiiboWindowViewModel(this, lastScannedAmiiboId, titleId);
+
+ ViewModel.ShowAllAmiibo = showAll;
+
+ DataContext = ViewModel;
+
+ InitializeComponent();
+
+ Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["Amiibo"];
+ }
+
+ public AmiiboWindow()
+ {
+ ViewModel = new AmiiboWindowViewModel(this, string.Empty, string.Empty);
+
+ DataContext = ViewModel;
+
+ InitializeComponent();
+
+ if (Program.PreviewerDetached)
+ {
+ Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["Amiibo"];
+ }
+ }
+
+ public bool IsScanned { get; set; }
+ public Amiibo.AmiiboApi ScannedAmiibo { get; set; }
+ public AmiiboWindowViewModel ViewModel { get; set; }
+
+ private void ScanButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (ViewModel.AmiiboSelectedIndex > -1)
+ {
+ Amiibo.AmiiboApi amiibo = ViewModel.AmiiboList[ViewModel.AmiiboSelectedIndex];
+ ScannedAmiibo = amiibo;
+ IsScanned = true;
+ Close();
+ }
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ IsScanned = false;
+
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml b/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml
new file mode 100644
index 00000000..c90ce022
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml.cs
new file mode 100644
index 00000000..e060d65e
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/AvatarWindow.axaml.cs
@@ -0,0 +1,77 @@
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using FluentAvalonia.UI.Controls;
+using FluentAvalonia.UI.Navigation;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.HLE.FileSystem;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class AvatarWindow : UserControl
+ {
+ private NavigationDialogHost _parent;
+ private TempProfile _profile;
+
+ public AvatarWindow(ContentManager contentManager)
+ {
+ ContentManager = contentManager;
+
+ DataContext = ViewModel;
+
+ InitializeComponent();
+ }
+
+ public AvatarWindow()
+ {
+ InitializeComponent();
+
+ AddHandler(Frame.NavigatedToEvent, (s, e) =>
+ {
+ NavigatedTo(e);
+ }, RoutingStrategies.Direct);
+ }
+
+ private void NavigatedTo(NavigationEventArgs arg)
+ {
+ if (Program.PreviewerDetached)
+ {
+ if (arg.NavigationMode == NavigationMode.New)
+ {
+ (_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
+ ContentManager = _parent.ContentManager;
+ if (Program.PreviewerDetached)
+ {
+ ViewModel = new AvatarProfileViewModel(() => ViewModel.ReloadImages());
+ }
+
+ DataContext = ViewModel;
+ }
+ }
+ }
+
+ public ContentManager ContentManager { get; private set; }
+
+ internal AvatarProfileViewModel ViewModel { get; set; }
+
+ private void CloseButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ ViewModel.Dispose();
+
+ _parent.GoBack();
+ }
+
+ private void ChooseButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ if (ViewModel.SelectedIndex > -1)
+ {
+ _profile.Image = ViewModel.SelectedImage;
+
+ ViewModel.Dispose();
+
+ _parent.GoBack();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/CheatWindow.axaml b/Ryujinx.Ava/UI/Windows/CheatWindow.axaml
new file mode 100644
index 00000000..3557ed69
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/CheatWindow.axaml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/CheatWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/CheatWindow.axaml.cs
new file mode 100644
index 00000000..d31212c1
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/CheatWindow.axaml.cs
@@ -0,0 +1,119 @@
+using Avalonia.Collections;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.HLE.FileSystem;
+using Ryujinx.HLE.HOS;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class CheatWindow : StyleableWindow
+ {
+ private readonly string _enabledCheatsPath;
+ public bool NoCheatsFound { get; }
+
+ private AvaloniaList LoadedCheats { get; }
+
+ public string Heading { get; }
+
+ public CheatWindow()
+ {
+ DataContext = this;
+
+ InitializeComponent();
+
+ Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["CheatWindowTitle"];
+ }
+
+ public CheatWindow(VirtualFileSystem virtualFileSystem, string titleId, string titleName)
+ {
+ LoadedCheats = new AvaloniaList();
+
+ Heading = string.Format(LocaleManager.Instance["CheatWindowHeading"], titleName, titleId.ToUpper());
+
+ InitializeComponent();
+
+ string modsBasePath = virtualFileSystem.ModLoader.GetModsBasePath();
+ string titleModsPath = virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, titleId);
+ ulong titleIdValue = ulong.Parse(titleId, System.Globalization.NumberStyles.HexNumber);
+
+ _enabledCheatsPath = Path.Combine(titleModsPath, "cheats", "enabled.txt");
+
+ string[] enabled = { };
+
+ if (File.Exists(_enabledCheatsPath))
+ {
+ enabled = File.ReadAllLines(_enabledCheatsPath);
+ }
+
+ int cheatAdded = 0;
+
+ var mods = new ModLoader.ModCache();
+
+ ModLoader.QueryContentsDir(mods, new DirectoryInfo(Path.Combine(modsBasePath, "contents")), titleIdValue);
+
+ string currentCheatFile = string.Empty;
+ string buildId = string.Empty;
+ string parentPath = string.Empty;
+
+ CheatsList currentGroup = null;
+
+ foreach (var cheat in mods.Cheats)
+ {
+ if (cheat.Path.FullName != currentCheatFile)
+ {
+ currentCheatFile = cheat.Path.FullName;
+ parentPath = currentCheatFile.Replace(titleModsPath, "");
+
+ buildId = Path.GetFileNameWithoutExtension(currentCheatFile).ToUpper();
+ currentGroup = new CheatsList(buildId, parentPath);
+
+ LoadedCheats.Add(currentGroup);
+ }
+
+ var model = new CheatModel(cheat.Name, buildId, enabled.Contains($"{buildId}-{cheat.Name}"));
+ currentGroup?.Add(model);
+
+ cheatAdded++;
+ }
+
+ if (cheatAdded == 0)
+ {
+ NoCheatsFound = true;
+ }
+
+ DataContext = this;
+
+ Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["CheatWindowTitle"];
+ }
+
+ public void Save()
+ {
+ if (NoCheatsFound)
+ {
+ return;
+ }
+
+ List enabledCheats = new List();
+
+ foreach (var cheats in LoadedCheats)
+ {
+ foreach (var cheat in cheats)
+ {
+ if (cheat.IsEnabled)
+ {
+ enabledCheats.Add(cheat.BuildIdKey);
+ }
+ }
+ }
+
+ Directory.CreateDirectory(Path.GetDirectoryName(_enabledCheatsPath));
+
+ File.WriteAllLines(_enabledCheatsPath, enabledCheats);
+
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml b/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml
new file mode 100644
index 00000000..6cdcae2b
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
diff --git a/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml.cs
new file mode 100644
index 00000000..3f77124d
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml.cs
@@ -0,0 +1,25 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Avalonia.Media;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class ContentDialogOverlayWindow : StyleableWindow
+ {
+ public ContentDialogOverlayWindow()
+ {
+ InitializeComponent();
+#if DEBUG
+ this.AttachDevTools();
+#endif
+ ExtendClientAreaToDecorationsHint = true;
+ TransparencyLevelHint = WindowTransparencyLevel.Transparent;
+ WindowStartupLocation = WindowStartupLocation.Manual;
+ SystemDecorations = SystemDecorations.None;
+ ExtendClientAreaTitleBarHeightHint = 0;
+ Background = Brushes.Transparent;
+ CanResize = false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml b/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml
new file mode 100644
index 00000000..f6bb1aa4
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml
@@ -0,0 +1,1169 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml.cs
new file mode 100644
index 00000000..df083085
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/ControllerSettingsWindow.axaml.cs
@@ -0,0 +1,181 @@
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.LogicalTree;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Helpers;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.Common.Configuration.Hid.Controller;
+using Ryujinx.Input;
+using Ryujinx.Input.Assigner;
+using System;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class ControllerSettingsWindow : UserControl
+ {
+ private bool _dialogOpen;
+
+ private ButtonKeyAssigner _currentAssigner;
+ internal ControllerSettingsViewModel ViewModel { get; set; }
+
+ public ControllerSettingsWindow()
+ {
+ DataContext = ViewModel = new ControllerSettingsViewModel(this);
+
+ InitializeComponent();
+
+ foreach (ILogical visual in SettingButtons.GetLogicalDescendants())
+ {
+ if (visual is ToggleButton button && !(visual is CheckBox))
+ {
+ button.Checked += Button_Checked;
+ button.Unchecked += Button_Unchecked;
+ }
+ }
+ }
+
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+
+ if (_currentAssigner != null && _currentAssigner.ToggledButton != null && !_currentAssigner.ToggledButton.IsPointerOver)
+ {
+ _currentAssigner.Cancel();
+ }
+ }
+
+ private void Button_Checked(object sender, RoutedEventArgs e)
+ {
+ if (sender is ToggleButton button)
+ {
+ if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
+ {
+ return;
+ }
+
+ bool isStick = button.Tag != null && button.Tag.ToString() == "stick";
+
+ if (_currentAssigner == null && (bool)button.IsChecked)
+ {
+ _currentAssigner = new ButtonKeyAssigner(button);
+
+ FocusManager.Instance.Focus(this, NavigationMethod.Pointer);
+
+ PointerPressed += MouseClick;
+
+ IKeyboard keyboard = (IKeyboard)ViewModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
+ IButtonAssigner assigner = CreateButtonAssigner(isStick);
+
+ _currentAssigner.ButtonAssigned += (sender, e) =>
+ {
+ if (e.IsAssigned)
+ {
+ ViewModel.IsModified = true;
+ }
+ };
+
+ _currentAssigner.GetInputAndAssign(assigner, keyboard);
+ }
+ else
+ {
+ if (_currentAssigner != null)
+ {
+ ToggleButton oldButton = _currentAssigner.ToggledButton;
+
+ _currentAssigner.Cancel();
+ _currentAssigner = null;
+ button.IsChecked = false;
+ }
+ }
+ }
+ }
+
+ public void SaveCurrentProfile()
+ {
+ ViewModel.Save();
+ }
+
+ private IButtonAssigner CreateButtonAssigner(bool forStick)
+ {
+ IButtonAssigner assigner;
+
+ var device = ViewModel.Devices[ViewModel.Device];
+
+ if (device.Type == DeviceType.Keyboard)
+ {
+ assigner = new KeyboardKeyAssigner((IKeyboard)ViewModel.SelectedGamepad);
+ }
+ else if (device.Type == DeviceType.Controller)
+ {
+ assigner = new GamepadButtonAssigner(ViewModel.SelectedGamepad, (ViewModel.Config as StandardControllerInputConfig).TriggerThreshold, forStick);
+ }
+ else
+ {
+ throw new Exception("Controller not supported");
+ }
+
+ return assigner;
+ }
+
+ private void Button_Unchecked(object sender, RoutedEventArgs e)
+ {
+ _currentAssigner?.Cancel();
+ _currentAssigner = null;
+ }
+
+ private void MouseClick(object sender, PointerPressedEventArgs e)
+ {
+ bool shouldUnbind = false;
+
+ if (e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed)
+ {
+ shouldUnbind = true;
+ }
+
+ _currentAssigner?.Cancel(shouldUnbind);
+
+ PointerPressed -= MouseClick;
+ }
+
+ private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (ViewModel.IsModified && !_dialogOpen)
+ {
+ _dialogOpen = true;
+
+ var result = await ContentDialogHelper.CreateConfirmationDialog(
+ LocaleManager.Instance["DialogControllerSettingsModifiedConfirmMessage"],
+ LocaleManager.Instance["DialogControllerSettingsModifiedConfirmSubMessage"],
+ LocaleManager.Instance["InputDialogYes"],
+ LocaleManager.Instance["InputDialogNo"],
+ LocaleManager.Instance["RyujinxConfirm"]);
+
+ if (result == UserResult.Yes)
+ {
+ ViewModel.Save();
+ }
+
+ _dialogOpen = false;
+
+ ViewModel.IsModified = false;
+
+ if (e.AddedItems.Count > 0)
+ {
+ var player = (PlayerModel)e.AddedItems[0];
+ ViewModel.PlayerId = player.Id;
+ }
+ }
+ }
+
+ public void Dispose()
+ {
+ _currentAssigner?.Cancel();
+ _currentAssigner = null;
+ ViewModel.Dispose();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml b/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml
new file mode 100644
index 00000000..e524d6e4
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml
@@ -0,0 +1,172 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml.cs
new file mode 100644
index 00000000..11be9383
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/DownloadableContentManagerWindow.axaml.cs
@@ -0,0 +1,314 @@
+using Avalonia.Collections;
+using Avalonia.Controls;
+using Avalonia.Threading;
+using LibHac.Common;
+using LibHac.Fs;
+using LibHac.Fs.Fsa;
+using LibHac.FsSystem;
+using LibHac.Tools.Fs;
+using LibHac.Tools.FsSystem;
+using LibHac.Tools.FsSystem.NcaUtils;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Helpers;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Common.Configuration;
+using Ryujinx.Common.Utilities;
+using Ryujinx.HLE.FileSystem;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Path = System.IO.Path;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class DownloadableContentManagerWindow : StyleableWindow
+ {
+ private readonly List _downloadableContentContainerList;
+ private readonly string _downloadableContentJsonPath;
+
+ private VirtualFileSystem _virtualFileSystem { get; }
+ private AvaloniaList _downloadableContents { get; set; }
+
+ private ulong _titleId { get; }
+ private string _titleName { get; }
+
+ public DownloadableContentManagerWindow()
+ {
+ DataContext = this;
+
+ InitializeComponent();
+
+ Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance["DlcWindowTitle"]} - {_titleName} ({_titleId:X16})";
+ }
+
+ public DownloadableContentManagerWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
+ {
+ _virtualFileSystem = virtualFileSystem;
+ _downloadableContents = new AvaloniaList();
+
+ _titleId = titleId;
+ _titleName = titleName;
+
+ _downloadableContentJsonPath = Path.Combine(AppDataManager.GamesDirPath, titleId.ToString("x16"), "dlc.json");
+
+ try
+ {
+ _downloadableContentContainerList = JsonHelper.DeserializeFromFile>(_downloadableContentJsonPath);
+ }
+ catch
+ {
+ _downloadableContentContainerList = new List();
+ }
+
+ DataContext = this;
+
+ InitializeComponent();
+
+ RemoveButton.IsEnabled = false;
+
+ DlcDataGrid.SelectionChanged += DlcDataGrid_SelectionChanged;
+
+ Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance["DlcWindowTitle"]} - {_titleName} ({_titleId:X16})";
+
+ LoadDownloadableContents();
+ PrintHeading();
+ }
+
+ private void DlcDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ RemoveButton.IsEnabled = (DlcDataGrid.SelectedItems.Count > 0);
+ }
+
+ private void PrintHeading()
+ {
+ Heading.Text = string.Format(LocaleManager.Instance["DlcWindowHeading"], _downloadableContents.Count, _titleName, _titleId.ToString("X16"));
+ }
+
+ private void LoadDownloadableContents()
+ {
+ foreach (DownloadableContentContainer downloadableContentContainer in _downloadableContentContainerList)
+ {
+ if (File.Exists(downloadableContentContainer.ContainerPath))
+ {
+ using FileStream containerFile = File.OpenRead(downloadableContentContainer.ContainerPath);
+
+ PartitionFileSystem partitionFileSystem = new(containerFile.AsStorage());
+
+ _virtualFileSystem.ImportTickets(partitionFileSystem);
+
+ foreach (DownloadableContentNca downloadableContentNca in downloadableContentContainer.DownloadableContentNcaList)
+ {
+ using UniqueRef ncaFile = new();
+
+ partitionFileSystem.OpenFile(ref ncaFile.Ref(), downloadableContentNca.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
+
+ Nca nca = TryOpenNca(ncaFile.Get.AsStorage(), downloadableContentContainer.ContainerPath);
+ if (nca != null)
+ {
+ _downloadableContents.Add(new DownloadableContentModel(nca.Header.TitleId.ToString("X16"),
+ downloadableContentContainer.ContainerPath,
+ downloadableContentNca.FullPath,
+ downloadableContentNca.Enabled));
+ }
+ }
+ }
+ }
+
+ // NOTE: Save the list again to remove leftovers.
+ Save();
+ }
+
+ private Nca TryOpenNca(IStorage ncaStorage, string containerPath)
+ {
+ try
+ {
+ return new Nca(_virtualFileSystem.KeySet, ncaStorage);
+ }
+ catch (Exception ex)
+ {
+ Dispatcher.UIThread.InvokeAsync(async () =>
+ {
+ await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance["DialogDlcLoadNcaErrorMessage"], ex.Message, containerPath));
+ });
+ }
+
+ return null;
+ }
+
+ private async Task AddDownloadableContent(string path)
+ {
+ if (!File.Exists(path) || _downloadableContents.FirstOrDefault(x => x.ContainerPath == path) != null)
+ {
+ return;
+ }
+
+ using FileStream containerFile = File.OpenRead(path);
+
+ PartitionFileSystem partitionFileSystem = new(containerFile.AsStorage());
+ bool containsDownloadableContent = false;
+
+ _virtualFileSystem.ImportTickets(partitionFileSystem);
+
+ foreach (DirectoryEntryEx fileEntry in partitionFileSystem.EnumerateEntries("/", "*.nca"))
+ {
+ using var ncaFile = new UniqueRef();
+
+ partitionFileSystem.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
+
+ Nca nca = TryOpenNca(ncaFile.Get.AsStorage(), path);
+ if (nca == null)
+ {
+ continue;
+ }
+
+ if (nca.Header.ContentType == NcaContentType.PublicData)
+ {
+ if ((nca.Header.TitleId & 0xFFFFFFFFFFFFE000) != _titleId)
+ {
+ break;
+ }
+
+ _downloadableContents.Add(new DownloadableContentModel(nca.Header.TitleId.ToString("X16"), path, fileEntry.FullPath, true));
+
+ containsDownloadableContent = true;
+ }
+ }
+
+ if (!containsDownloadableContent)
+ {
+ await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance["DialogDlcNoDlcErrorMessage"]);
+ }
+ }
+
+ private void RemoveDownloadableContents(bool removeSelectedOnly = false)
+ {
+ if (removeSelectedOnly)
+ {
+ AvaloniaList removedItems = new();
+
+ foreach (var item in DlcDataGrid.SelectedItems)
+ {
+ removedItems.Add(item as DownloadableContentModel);
+ }
+
+ DlcDataGrid.SelectedItems.Clear();
+
+ foreach (var item in removedItems)
+ {
+ _downloadableContents.RemoveAll(_downloadableContents.Where(x => x.TitleId == item.TitleId).ToList());
+ }
+ }
+ else
+ {
+ _downloadableContents.Clear();
+ }
+
+ PrintHeading();
+ }
+
+ public void RemoveSelected()
+ {
+ RemoveDownloadableContents(true);
+ }
+
+ public void RemoveAll()
+ {
+ RemoveDownloadableContents();
+ }
+
+ public void EnableAll()
+ {
+ foreach(var item in _downloadableContents)
+ {
+ item.Enabled = true;
+ }
+ }
+
+ public void DisableAll()
+ {
+ foreach (var item in _downloadableContents)
+ {
+ item.Enabled = false;
+ }
+ }
+
+ public async void Add()
+ {
+ OpenFileDialog dialog = new OpenFileDialog()
+ {
+ Title = LocaleManager.Instance["SelectDlcDialogTitle"],
+ AllowMultiple = true
+ };
+
+ dialog.Filters.Add(new FileDialogFilter
+ {
+ Name = "NSP",
+ Extensions = { "nsp" }
+ });
+
+ string[] files = await dialog.ShowAsync(this);
+
+ if (files != null)
+ {
+ foreach (string file in files)
+ {
+ await AddDownloadableContent(file);
+ }
+ }
+
+ PrintHeading();
+ }
+
+ public void Save()
+ {
+ _downloadableContentContainerList.Clear();
+
+ DownloadableContentContainer container = default;
+
+ foreach (DownloadableContentModel downloadableContent in _downloadableContents)
+ {
+ if (container.ContainerPath != downloadableContent.ContainerPath)
+ {
+ if (!string.IsNullOrWhiteSpace(container.ContainerPath))
+ {
+ _downloadableContentContainerList.Add(container);
+ }
+
+ container = new DownloadableContentContainer
+ {
+ ContainerPath = downloadableContent.ContainerPath,
+ DownloadableContentNcaList = new List()
+ };
+ }
+
+ container.DownloadableContentNcaList.Add(new DownloadableContentNca
+ {
+ Enabled = downloadableContent.Enabled,
+ TitleId = Convert.ToUInt64(downloadableContent.TitleId, 16),
+ FullPath = downloadableContent.FullPath
+ });
+ }
+
+ if (!string.IsNullOrWhiteSpace(container.ContainerPath))
+ {
+ _downloadableContentContainerList.Add(container);
+ }
+
+ using (FileStream downloadableContentJsonStream = File.Create(_downloadableContentJsonPath, 4096, FileOptions.WriteThrough))
+ {
+ downloadableContentJsonStream.Write(Encoding.UTF8.GetBytes(JsonHelper.Serialize(_downloadableContentContainerList, true)));
+ }
+ }
+
+ public void SaveAndClose()
+ {
+ Save();
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/IconColorPicker.cs b/Ryujinx.Ava/UI/Windows/IconColorPicker.cs
new file mode 100644
index 00000000..9dca83eb
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/IconColorPicker.cs
@@ -0,0 +1,192 @@
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ static class IconColorPicker
+ {
+ private const int ColorsPerLine = 64;
+ private const int TotalColors = ColorsPerLine * ColorsPerLine;
+
+ private const int UvQuantBits = 3;
+ private const int UvQuantShift = BitsPerComponent - UvQuantBits;
+
+ private const int SatQuantBits = 5;
+ private const int SatQuantShift = BitsPerComponent - SatQuantBits;
+
+ private const int BitsPerComponent = 8;
+
+ private const int CutOffLuminosity = 64;
+
+ private readonly struct PaletteColor
+ {
+ public int Qck { get; }
+ public byte R { get; }
+ public byte G { get; }
+ public byte B { get; }
+
+ public PaletteColor(int qck, byte r, byte g, byte b)
+ {
+ Qck = qck;
+ R = r;
+ G = g;
+ B = b;
+ }
+ }
+
+ public static Color GetFilteredColor(Image image)
+ {
+ var color = GetColor(image).ToPixel();
+
+ // We don't want colors that are too dark.
+ // If the color is too dark, make it brighter by reducing the range
+ // and adding a constant color.
+ int luminosity = GetColorApproximateLuminosity(color.R, color.G, color.B);
+ if (luminosity < CutOffLuminosity)
+ {
+ color = Color.FromRgb(
+ (byte)Math.Min(CutOffLuminosity + color.R, byte.MaxValue),
+ (byte)Math.Min(CutOffLuminosity + color.G, byte.MaxValue),
+ (byte)Math.Min(CutOffLuminosity + color.B, byte.MaxValue));
+ }
+
+ return color;
+ }
+
+ public static Color GetColor(Image image)
+ {
+ var colors = new PaletteColor[TotalColors];
+
+ var dominantColorBin = new Dictionary();
+
+ var buffer = GetBuffer(image);
+
+ int w = image.Width;
+
+ int w8 = w << 8;
+ int h8 = image.Height << 8;
+
+ int xStep = w8 / ColorsPerLine;
+ int yStep = h8 / ColorsPerLine;
+
+ int i = 0;
+ int maxHitCount = 0;
+
+ for (int y = 0; y < image.Height; y++)
+ {
+ int yOffset = y * image.Width;
+
+ for (int x = 0; x < image.Width && i < TotalColors; x++)
+ {
+ int offset = x + yOffset;
+
+ byte cb = buffer[offset].B;
+ byte cg = buffer[offset].G;
+ byte cr = buffer[offset].R;
+
+ var qck = GetQuantizedColorKey(cr, cg, cb);
+
+ if (dominantColorBin.TryGetValue(qck, out int hitCount))
+ {
+ dominantColorBin[qck] = hitCount + 1;
+
+ if (maxHitCount < hitCount)
+ {
+ maxHitCount = hitCount;
+ }
+ }
+ else
+ {
+ dominantColorBin.Add(qck, 1);
+ }
+
+ colors[i++] = new PaletteColor(qck, cr, cg, cb);
+ }
+ }
+
+ int highScore = -1;
+ PaletteColor bestCandidate = default;
+
+ for (i = 0; i < TotalColors; i++)
+ {
+ var score = GetColorScore(dominantColorBin, maxHitCount, colors[i]);
+
+ if (highScore < score)
+ {
+ highScore = score;
+ bestCandidate = colors[i];
+ }
+ }
+
+ return Color.FromRgb(bestCandidate.R, bestCandidate.G, bestCandidate.B);
+ }
+
+ public static Bgra32[] GetBuffer(Image image)
+ {
+ return image.TryGetSinglePixelSpan(out var data) ? data.ToArray() : new Bgra32[0];
+ }
+
+ private static int GetColorScore(Dictionary dominantColorBin, int maxHitCount, PaletteColor color)
+ {
+ var hitCount = dominantColorBin[color.Qck];
+ var balancedHitCount = BalanceHitCount(hitCount, maxHitCount);
+ var quantSat = (GetColorSaturation(color) >> SatQuantShift) << SatQuantShift;
+ var value = GetColorValue(color);
+
+ // If the color is rarely used on the image,
+ // then chances are that theres a better candidate, even if the saturation value
+ // is high. By multiplying the saturation value with a weight, we can lower
+ // it if the color is almost never used (hit count is low).
+ var satWeighted = quantSat;
+ var satWeight = balancedHitCount << 5;
+ if (satWeight < 0x100)
+ {
+ satWeighted = (satWeighted * satWeight) >> 8;
+ }
+
+ // Compute score from saturation and dominance of the color.
+ // We prefer more vivid colors over dominant ones, so give more weight to the saturation.
+ var score = ((satWeighted << 1) + balancedHitCount) * value;
+
+ return score;
+ }
+
+ private static int BalanceHitCount(int hitCount, int maxHitCount)
+ {
+ return (hitCount << 8) / maxHitCount;
+ }
+
+ private static int GetColorApproximateLuminosity(byte r, byte g, byte b)
+ {
+ return (r + g + b) / 3;
+ }
+
+ private static int GetColorSaturation(PaletteColor color)
+ {
+ int cMax = Math.Max(Math.Max(color.R, color.G), color.B);
+
+ if (cMax == 0)
+ {
+ return 0;
+ }
+
+ int cMin = Math.Min(Math.Min(color.R, color.G), color.B);
+ int delta = cMax - cMin;
+ return (delta << 8) / cMax;
+ }
+
+ private static int GetColorValue(PaletteColor color)
+ {
+ return Math.Max(Math.Max(color.R, color.G), color.B);
+ }
+
+ private static int GetQuantizedColorKey(byte r, byte g, byte b)
+ {
+ int u = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
+ int v = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
+ return (v >> UvQuantShift) | ((u >> UvQuantShift) << UvQuantBits);
+ }
+ }
+}
diff --git a/Ryujinx.Ava/UI/Windows/MainWindow.axaml b/Ryujinx.Ava/UI/Windows/MainWindow.axaml
new file mode 100644
index 00000000..1eb42279
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/MainWindow.axaml
@@ -0,0 +1,770 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs
new file mode 100644
index 00000000..08332da8
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs
@@ -0,0 +1,721 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.Media;
+using Avalonia.Threading;
+using FluentAvalonia.UI.Controls;
+using Ryujinx.Ava.Common;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.Input;
+using Ryujinx.Ava.UI.Applet;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Helpers;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.Common.Configuration;
+using Ryujinx.Common.Logging;
+using Ryujinx.Graphics.Gpu;
+using Ryujinx.HLE.FileSystem;
+using Ryujinx.HLE.HOS;
+using Ryujinx.HLE.HOS.Services.Account.Acc;
+using Ryujinx.Input.SDL2;
+using Ryujinx.Modules;
+using Ryujinx.Ui.App.Common;
+using Ryujinx.Ui.Common;
+using Ryujinx.Ui.Common.Configuration;
+using Ryujinx.Ui.Common.Helper;
+using SixLabors.ImageSharp.PixelFormats;
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+using InputManager = Ryujinx.Input.HLE.InputManager;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class MainWindow : StyleableWindow
+ {
+ internal static MainWindowViewModel MainWindowViewModel { get; private set; }
+ private bool _canUpdate;
+ private bool _isClosing;
+ private bool _isLoading;
+
+ private Control _mainViewContent;
+
+ private UserChannelPersistence _userChannelPersistence;
+ private static bool _deferLoad;
+ private static string _launchPath;
+ private static bool _startFullscreen;
+ private string _currentEmulatedGamePath;
+ internal readonly AvaHostUiHandler UiHandler;
+ private AutoResetEvent _rendererWaitEvent;
+
+ public VirtualFileSystem VirtualFileSystem { get; private set; }
+ public ContentManager ContentManager { get; private set; }
+ public AccountManager AccountManager { get; private set; }
+
+ public LibHacHorizonManager LibHacHorizonManager { get; private set; }
+
+ internal AppHost AppHost { get; private set; }
+ public InputManager InputManager { get; private set; }
+
+ internal RendererHost RendererControl { get; private set; }
+ internal MainWindowViewModel ViewModel { get; private set; }
+ public SettingsWindow SettingsWindow { get; set; }
+
+ public bool CanUpdate
+ {
+ get => _canUpdate;
+ set
+ {
+ _canUpdate = value;
+
+ Dispatcher.UIThread.InvokeAsync(() => UpdateMenuItem.IsEnabled = _canUpdate);
+ }
+ }
+
+ public static bool ShowKeyErrorOnLoad { get; set; }
+ public ApplicationLibrary ApplicationLibrary { get; set; }
+
+ public MainWindow()
+ {
+ ViewModel = new MainWindowViewModel(this);
+
+ MainWindowViewModel = ViewModel;
+
+ DataContext = ViewModel;
+
+ InitializeComponent();
+ Load();
+
+ UiHandler = new AvaHostUiHandler(this);
+
+ Title = $"Ryujinx {Program.Version}";
+
+ // NOTE: Height of MenuBar and StatusBar is not usable here, since it would still be 0 at this point.
+ double barHeight = MenuBar.MinHeight + StatusBar.MinHeight;
+ Height = ((Height - barHeight) / Program.WindowScaleFactor) + barHeight;
+ Width /= Program.WindowScaleFactor;
+
+ if (Program.PreviewerDetached)
+ {
+ Initialize();
+
+ ViewModel.Initialize();
+
+ InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL2GamepadDriver());
+
+ LoadGameList();
+ }
+
+ _rendererWaitEvent = new AutoResetEvent(false);
+ }
+
+ public void LoadGameList()
+ {
+ if (_isLoading)
+ {
+ return;
+ }
+
+ _isLoading = true;
+
+ ViewModel.LoadApplications();
+
+ _isLoading = false;
+ }
+
+ private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
+ {
+ if (ViewModel.ShowMenuAndStatusBar && !ViewModel.ShowLoadProgress)
+ {
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ if (args.VSyncEnabled)
+ {
+ ViewModel.VsyncColor = new SolidColorBrush(Color.Parse("#ff2eeac9"));
+ }
+ else
+ {
+ ViewModel.VsyncColor = new SolidColorBrush(Color.Parse("#ffff4554"));
+ }
+
+ ViewModel.DockedStatusText = args.DockedMode;
+ ViewModel.AspectRatioStatusText = args.AspectRatio;
+ ViewModel.GameStatusText = args.GameStatus;
+ ViewModel.VolumeStatusText = args.VolumeStatus;
+ ViewModel.FifoStatusText = args.FifoStatus;
+ ViewModel.GpuNameText = args.GpuName;
+ ViewModel.BackendText = args.GpuBackend;
+
+ ViewModel.ShowStatusSeparator = true;
+ });
+ }
+ }
+
+ protected override void HandleScalingChanged(double scale)
+ {
+ Program.DesktopScaleFactor = scale;
+ base.HandleScalingChanged(scale);
+ }
+
+ public void Application_Opened(object sender, ApplicationOpenedEventArgs args)
+ {
+ if (args.Application != null)
+ {
+ ViewModel.SelectedIcon = args.Application.Icon;
+
+ string path = new FileInfo(args.Application.Path).FullName;
+
+ LoadApplication(path);
+ }
+
+ args.Handled = true;
+ }
+
+ public async Task PerformanceCheck()
+ {
+ if (ConfigurationState.Instance.Logger.EnableTrace.Value)
+ {
+ string mainMessage = LocaleManager.Instance["DialogPerformanceCheckLoggingEnabledMessage"];
+ string secondaryMessage = LocaleManager.Instance["DialogPerformanceCheckLoggingEnabledConfirmMessage"];
+
+ UserResult result = await ContentDialogHelper.CreateConfirmationDialog(mainMessage, secondaryMessage,
+ LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"],
+ LocaleManager.Instance["RyujinxConfirm"]);
+
+ if (result != UserResult.Yes)
+ {
+ ConfigurationState.Instance.Logger.EnableTrace.Value = false;
+
+ SaveConfig();
+ }
+ }
+
+ if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
+ {
+ string mainMessage = LocaleManager.Instance["DialogPerformanceCheckShaderDumpEnabledMessage"];
+ string secondaryMessage =
+ LocaleManager.Instance["DialogPerformanceCheckShaderDumpEnabledConfirmMessage"];
+
+ UserResult result = await ContentDialogHelper.CreateConfirmationDialog(mainMessage, secondaryMessage,
+ LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"],
+ LocaleManager.Instance["RyujinxConfirm"]);
+
+ if (result != UserResult.Yes)
+ {
+ ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
+
+ SaveConfig();
+ }
+ }
+ }
+
+ internal static void DeferLoadApplication(string launchPathArg, bool startFullscreenArg)
+ {
+ _deferLoad = true;
+ _launchPath = launchPathArg;
+ _startFullscreen = startFullscreenArg;
+ }
+
+#pragma warning disable CS1998
+ public async void LoadApplication(string path, bool startFullscreen = false, string titleName = "")
+#pragma warning restore CS1998
+ {
+ if (AppHost != null)
+ {
+ await ContentDialogHelper.CreateInfoDialog(
+ LocaleManager.Instance["DialogLoadAppGameAlreadyLoadedMessage"],
+ LocaleManager.Instance["DialogLoadAppGameAlreadyLoadedSubMessage"],
+ LocaleManager.Instance["InputDialogOk"],
+ "",
+ LocaleManager.Instance["RyujinxInfo"]);
+
+ return;
+ }
+
+#if RELEASE
+ await PerformanceCheck();
+#endif
+
+ Logger.RestartTime();
+
+ if (ViewModel.SelectedIcon == null)
+ {
+ ViewModel.SelectedIcon = ApplicationLibrary.GetApplicationIcon(path);
+ }
+
+ PrepareLoadScreen();
+
+ _mainViewContent = MainContent.Content as Control;
+
+ RendererControl = new RendererHost(ConfigurationState.Instance.Logger.GraphicsDebugLevel);
+ if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.OpenGl)
+ {
+ RendererControl.CreateOpenGL();
+ }
+ else
+ {
+ RendererControl.CreateVulkan();
+ }
+
+ AppHost = new AppHost(RendererControl, InputManager, path, VirtualFileSystem, ContentManager, AccountManager, _userChannelPersistence, this);
+
+ Dispatcher.UIThread.Post(async () =>
+ {
+ if (!await AppHost.LoadGuestApplication())
+ {
+ AppHost.DisposeContext();
+ AppHost = null;
+
+ return;
+ }
+
+ CanUpdate = false;
+ ViewModel.LoadHeading = string.IsNullOrWhiteSpace(titleName) ? string.Format(LocaleManager.Instance["LoadingHeading"], AppHost.Device.Application.TitleName) : titleName;
+ ViewModel.TitleName = string.IsNullOrWhiteSpace(titleName) ? AppHost.Device.Application.TitleName : titleName;
+
+ SwitchToGameControl(startFullscreen);
+
+ _currentEmulatedGamePath = path;
+
+ Thread gameThread = new(InitializeGame)
+ {
+ Name = "GUI.WindowThread"
+ };
+ gameThread.Start();
+ });
+ }
+
+ private void InitializeGame()
+ {
+ RendererControl.RendererInitialized += GlRenderer_Created;
+
+ AppHost.StatusUpdatedEvent += Update_StatusBar;
+ AppHost.AppExit += AppHost_AppExit;
+
+ _rendererWaitEvent.WaitOne();
+
+ AppHost?.Start();
+
+ AppHost.DisposeContext();
+ }
+
+
+ private void HandleRelaunch()
+ {
+ if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
+ {
+ _userChannelPersistence.ShouldRestart = false;
+
+ Dispatcher.UIThread.Post(() =>
+ {
+ LoadApplication(_currentEmulatedGamePath);
+ });
+ }
+ else
+ {
+ // otherwise, clear state.
+ _userChannelPersistence = new UserChannelPersistence();
+ _currentEmulatedGamePath = null;
+ }
+ }
+
+ public void SwitchToGameControl(bool startFullscreen = false)
+ {
+ ViewModel.ShowLoadProgress = false;
+ ViewModel.ShowContent = true;
+ ViewModel.IsLoadingIndeterminate = false;
+
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ MainContent.Content = RendererControl;
+
+ if (startFullscreen && WindowState != WindowState.FullScreen)
+ {
+ ViewModel.ToggleFullscreen();
+ }
+
+ RendererControl.Focus();
+ });
+ }
+
+ public void ShowLoading(bool startFullscreen = false)
+ {
+ ViewModel.ShowContent = false;
+ ViewModel.ShowLoadProgress = true;
+ ViewModel.IsLoadingIndeterminate = true;
+
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ if (startFullscreen && WindowState != WindowState.FullScreen)
+ {
+ ViewModel.ToggleFullscreen();
+ }
+ });
+ }
+
+ private void GlRenderer_Created(object sender, EventArgs e)
+ {
+ ShowLoading();
+
+ _rendererWaitEvent.Set();
+ }
+
+ private void AppHost_AppExit(object sender, EventArgs e)
+ {
+ if (_isClosing)
+ {
+ return;
+ }
+
+ ViewModel.IsGameRunning = false;
+
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ ViewModel.ShowMenuAndStatusBar = true;
+ ViewModel.ShowContent = true;
+ ViewModel.ShowLoadProgress = false;
+ ViewModel.IsLoadingIndeterminate = false;
+ CanUpdate = true;
+ Cursor = Cursor.Default;
+
+ if (MainContent.Content != _mainViewContent)
+ {
+ MainContent.Content = _mainViewContent;
+ }
+
+ AppHost = null;
+
+ HandleRelaunch();
+ });
+
+ RendererControl.RendererInitialized -= GlRenderer_Created;
+ RendererControl = null;
+
+ ViewModel.SelectedIcon = null;
+
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ Title = $"Ryujinx {Program.Version}";
+ });
+ }
+
+ public void Sort_Checked(object sender, RoutedEventArgs args)
+ {
+ if (sender is RadioButton button)
+ {
+ var sort = Enum.Parse(button.Tag.ToString());
+ ViewModel.Sort(sort);
+ }
+ }
+
+ protected override void HandleWindowStateChanged(WindowState state)
+ {
+ WindowState = state;
+
+ if (state != WindowState.Minimized)
+ {
+ Renderer.Start();
+ }
+ }
+
+ public void Order_Checked(object sender, RoutedEventArgs args)
+ {
+ if (sender is RadioButton button)
+ {
+ var tag = button.Tag.ToString();
+ ViewModel.Sort(tag != "Descending");
+ }
+ }
+
+ private void Initialize()
+ {
+ _userChannelPersistence = new UserChannelPersistence();
+ VirtualFileSystem = VirtualFileSystem.CreateInstance();
+ LibHacHorizonManager = new LibHacHorizonManager();
+ ContentManager = new ContentManager(VirtualFileSystem);
+
+ LibHacHorizonManager.InitializeFsServer(VirtualFileSystem);
+ LibHacHorizonManager.InitializeArpServer();
+ LibHacHorizonManager.InitializeBcatServer();
+ LibHacHorizonManager.InitializeSystemClients();
+
+ ApplicationLibrary = new ApplicationLibrary(VirtualFileSystem);
+
+ // Save data created before we supported extra data in directory save data will not work properly if
+ // given empty extra data. Luckily some of that extra data can be created using the data from the
+ // save data indexer, which should be enough to check access permissions for user saves.
+ // Every single save data's extra data will be checked and fixed if needed each time the emulator is opened.
+ // Consider removing this at some point in the future when we don't need to worry about old saves.
+ VirtualFileSystem.FixExtraData(LibHacHorizonManager.RyujinxClient);
+
+ AccountManager = new AccountManager(LibHacHorizonManager.RyujinxClient, CommandLineState.Profile);
+
+ VirtualFileSystem.ReloadKeySet();
+
+ ApplicationHelper.Initialize(VirtualFileSystem, AccountManager, LibHacHorizonManager.RyujinxClient, this);
+
+ RefreshFirmwareStatus();
+ }
+
+ protected void CheckLaunchState()
+ {
+ if (ShowKeyErrorOnLoad)
+ {
+ ShowKeyErrorOnLoad = false;
+
+ Dispatcher.UIThread.Post(async () => await
+ UserErrorDialog.ShowUserErrorDialog(UserError.NoKeys, this));
+ }
+
+ if (_deferLoad)
+ {
+ _deferLoad = false;
+
+ LoadApplication(_launchPath, _startFullscreen);
+ }
+
+ if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false, this))
+ {
+ Updater.BeginParse(this, false).ContinueWith(task =>
+ {
+ Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}");
+ }, TaskContinuationOptions.OnlyOnFaulted);
+ }
+ }
+
+ public void RefreshFirmwareStatus()
+ {
+ SystemVersion version = null;
+ try
+ {
+ version = ContentManager.GetCurrentFirmwareVersion();
+ }
+ catch (Exception) { }
+
+ bool hasApplet = false;
+
+ if (version != null)
+ {
+ LocaleManager.Instance.UpdateDynamicValue("StatusBarSystemVersion",
+ version.VersionString);
+
+ hasApplet = version.Major > 3;
+ }
+ else
+ {
+ LocaleManager.Instance.UpdateDynamicValue("StatusBarSystemVersion", "0.0");
+ }
+
+ ViewModel.IsAppletMenuActive = hasApplet;
+ }
+
+ private void Load()
+ {
+ VolumeStatus.Click += VolumeStatus_CheckedChanged;
+
+ GameGrid.ApplicationOpened += Application_Opened;
+
+ GameGrid.DataContext = ViewModel;
+
+ GameList.ApplicationOpened += Application_Opened;
+
+ GameList.DataContext = ViewModel;
+
+ LoadHotKeys();
+ }
+
+ protected override void OnOpened(EventArgs e)
+ {
+ base.OnOpened(e);
+
+ CheckLaunchState();
+ }
+
+ public static void UpdateGraphicsConfig()
+ {
+ GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.ResScale == -1 ? ConfigurationState.Instance.Graphics.ResScaleCustom : ConfigurationState.Instance.Graphics.ResScale;
+ GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
+ GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
+ GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
+ GraphicsConfig.EnableTextureRecompression = ConfigurationState.Instance.Graphics.EnableTextureRecompression;
+ GraphicsConfig.EnableMacroHLE = ConfigurationState.Instance.Graphics.EnableMacroHLE;
+ }
+
+ public void LoadHotKeys()
+ {
+ HotKeyManager.SetHotKey(FullscreenHotKey, new KeyGesture(Key.Enter, KeyModifiers.Alt));
+ HotKeyManager.SetHotKey(FullscreenHotKey2, new KeyGesture(Key.F11));
+ HotKeyManager.SetHotKey(DockToggleHotKey, new KeyGesture(Key.F9));
+ HotKeyManager.SetHotKey(ExitHotKey, new KeyGesture(Key.Escape));
+ }
+
+ public static void SaveConfig()
+ {
+ ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
+ }
+
+ public void UpdateGameMetadata(string titleId)
+ {
+ ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
+ {
+ if (DateTime.TryParse(appMetadata.LastPlayed, out DateTime lastPlayedDateTime))
+ {
+ double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
+
+ appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
+ }
+ });
+ }
+
+ private void PrepareLoadScreen()
+ {
+ using MemoryStream stream = new MemoryStream(ViewModel.SelectedIcon);
+ using var gameIconBmp = SixLabors.ImageSharp.Image.Load(stream);
+
+ var dominantColor = IconColorPicker.GetFilteredColor(gameIconBmp).ToPixel();
+
+ const int ColorDivisor = 4;
+
+ Color progressFgColor = Color.FromRgb(dominantColor.R, dominantColor.G, dominantColor.B);
+ Color progressBgColor = Color.FromRgb(
+ (byte)(dominantColor.R / ColorDivisor),
+ (byte)(dominantColor.G / ColorDivisor),
+ (byte)(dominantColor.B / ColorDivisor));
+
+ ViewModel.ProgressBarForegroundColor = new SolidColorBrush(progressFgColor);
+ ViewModel.ProgressBarBackgroundColor = new SolidColorBrush(progressBgColor);
+ }
+
+ private void SearchBox_OnKeyUp(object sender, KeyEventArgs e)
+ {
+ ViewModel.SearchText = SearchBox.Text;
+ }
+
+ private async void StopEmulation_Click(object sender, RoutedEventArgs e)
+ {
+ if (AppHost != null)
+ {
+ await AppHost.ShowExitPrompt();
+ }
+ }
+
+ private async void PauseEmulation_Click(object sender, RoutedEventArgs e)
+ {
+ await Task.Run(() =>
+ {
+ AppHost?.Pause();
+ });
+ }
+
+ private async void ResumeEmulation_Click(object sender, RoutedEventArgs e)
+ {
+ await Task.Run(() =>
+ {
+ AppHost?.Resume();
+ });
+ }
+
+ private void ScanAmiiboMenuItem_AttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
+ {
+ if (sender is MenuItem)
+ {
+ ViewModel.IsAmiiboRequested = AppHost.Device.System.SearchingForAmiibo(out _);
+ }
+ }
+
+ private void VsyncStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
+ {
+ AppHost.Device.EnableDeviceVsync = !AppHost.Device.EnableDeviceVsync;
+
+ Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {AppHost.Device.EnableDeviceVsync}");
+ }
+
+ private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
+ {
+ ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
+ }
+
+ private void AspectRatioStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
+ {
+ AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
+
+ ConfigurationState.Instance.Graphics.AspectRatio.Value = (int)aspectRatio + 1 > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
+ }
+
+ private void VolumeStatus_CheckedChanged(object sender, SplitButtonClickEventArgs e)
+ {
+ var volumeSplitButton = sender as ToggleSplitButton;
+ if (ViewModel.IsGameRunning)
+ {
+ if (!volumeSplitButton.IsChecked)
+ {
+ AppHost.Device.SetVolume(ConfigurationState.Instance.System.AudioVolume);
+ }
+ else
+ {
+ AppHost.Device.SetVolume(0);
+ }
+
+ ViewModel.Volume = AppHost.Device.GetVolume();
+ }
+ }
+
+ protected override void OnClosing(CancelEventArgs e)
+ {
+ if (!_isClosing && AppHost != null && ConfigurationState.Instance.ShowConfirmExit)
+ {
+ e.Cancel = true;
+
+ ConfirmExit();
+
+ return;
+ }
+
+ _isClosing = true;
+
+ if (AppHost != null)
+ {
+ AppHost.AppExit -= AppHost_AppExit;
+ AppHost.AppExit += (sender, e) =>
+ {
+ AppHost = null;
+
+ Dispatcher.UIThread.Post(() =>
+ {
+ MainContent = null;
+
+ Close();
+ });
+ };
+ AppHost?.Stop();
+
+ e.Cancel = true;
+
+ return;
+ }
+
+ ApplicationLibrary.CancelLoading();
+ InputManager.Dispose();
+ Program.Exit();
+
+ base.OnClosing(e);
+ }
+
+ private void ConfirmExit()
+ {
+ Dispatcher.UIThread.InvokeAsync(async () =>
+ {
+ _isClosing = await ContentDialogHelper.CreateExitDialog();
+
+ if (_isClosing)
+ {
+ Close();
+ }
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml b/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml
new file mode 100644
index 00000000..862998ac
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml
@@ -0,0 +1,141 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml.cs
new file mode 100644
index 00000000..215525fc
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/MotionSettingsWindow.axaml.cs
@@ -0,0 +1,71 @@
+using Avalonia.Controls;
+using FluentAvalonia.UI.Controls;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.Common.Configuration.Hid.Controller;
+using System.Threading.Tasks;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class MotionSettingsWindow : UserControl
+ {
+ private readonly InputConfiguration _viewmodel;
+
+ public MotionSettingsWindow()
+ {
+ InitializeComponent();
+ DataContext = _viewmodel;
+ }
+
+ public MotionSettingsWindow(ControllerSettingsViewModel viewmodel)
+ {
+ var config = viewmodel.Configuration as InputConfiguration;
+
+ _viewmodel = new InputConfiguration()
+ {
+ Slot = config.Slot,
+ AltSlot = config.AltSlot,
+ DsuServerHost = config.DsuServerHost,
+ DsuServerPort = config.DsuServerPort,
+ MirrorInput = config.MirrorInput,
+ EnableMotion = config.EnableMotion,
+ Sensitivity = config.Sensitivity,
+ GyroDeadzone = config.GyroDeadzone,
+ EnableCemuHookMotion = config.EnableCemuHookMotion
+ };
+
+ InitializeComponent();
+ DataContext = _viewmodel;
+ }
+
+ public static async Task Show(ControllerSettingsViewModel viewmodel)
+ {
+ MotionSettingsWindow content = new MotionSettingsWindow(viewmodel);
+
+ ContentDialog contentDialog = new ContentDialog
+ {
+ Title = LocaleManager.Instance["ControllerMotionTitle"],
+ PrimaryButtonText = LocaleManager.Instance["ControllerSettingsSave"],
+ SecondaryButtonText = "",
+ CloseButtonText = LocaleManager.Instance["ControllerSettingsClose"],
+ Content = content
+ };
+ contentDialog.PrimaryButtonClick += (sender, args) =>
+ {
+ var config = viewmodel.Configuration as InputConfiguration;
+ config.Slot = content._viewmodel.Slot;
+ config.EnableMotion = content._viewmodel.EnableMotion;
+ config.Sensitivity = content._viewmodel.Sensitivity;
+ config.GyroDeadzone = content._viewmodel.GyroDeadzone;
+ config.AltSlot = content._viewmodel.AltSlot;
+ config.DsuServerHost = content._viewmodel.DsuServerHost;
+ config.DsuServerPort = content._viewmodel.DsuServerPort;
+ config.EnableCemuHookMotion = content._viewmodel.EnableCemuHookMotion;
+ config.MirrorInput = content._viewmodel.MirrorInput;
+ };
+
+ await contentDialog.ShowAsync();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml b/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml
new file mode 100644
index 00000000..e47cc5bd
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml.cs
new file mode 100644
index 00000000..f645ae35
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/RumbleSettingsWindow.axaml.cs
@@ -0,0 +1,57 @@
+using Avalonia.Controls;
+using FluentAvalonia.UI.Controls;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.Common.Configuration.Hid.Controller;
+using System.Threading.Tasks;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class RumbleSettingsWindow : UserControl
+ {
+ private readonly InputConfiguration _viewmodel;
+
+ public RumbleSettingsWindow()
+ {
+ InitializeComponent();
+ DataContext = _viewmodel;
+ }
+
+ public RumbleSettingsWindow(ControllerSettingsViewModel viewmodel)
+ {
+ var config = viewmodel.Configuration as InputConfiguration;
+
+ _viewmodel = new InputConfiguration()
+ {
+ StrongRumble = config.StrongRumble, WeakRumble = config.WeakRumble
+ };
+
+ InitializeComponent();
+ DataContext = _viewmodel;
+ }
+
+ public static async Task Show(ControllerSettingsViewModel viewmodel)
+ {
+ RumbleSettingsWindow content = new RumbleSettingsWindow(viewmodel);
+
+ ContentDialog contentDialog = new ContentDialog
+ {
+ Title = LocaleManager.Instance["ControllerRumbleTitle"],
+ PrimaryButtonText = LocaleManager.Instance["ControllerSettingsSave"],
+ SecondaryButtonText = "",
+ CloseButtonText = LocaleManager.Instance["ControllerSettingsClose"],
+ Content = content,
+ };
+
+ contentDialog.PrimaryButtonClick += (sender, args) =>
+ {
+ var config = viewmodel.Configuration as InputConfiguration;
+ config.StrongRumble = content._viewmodel.StrongRumble;
+ config.WeakRumble = content._viewmodel.WeakRumble;
+ };
+
+ await contentDialog.ShowAsync();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml b/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml
new file mode 100644
index 00000000..e2550082
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml
@@ -0,0 +1,980 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs
new file mode 100644
index 00000000..f3aa1d5e
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/SettingsWindow.axaml.cs
@@ -0,0 +1,213 @@
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Data;
+using Avalonia.Data.Converters;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using FluentAvalonia.Core;
+using FluentAvalonia.UI.Controls;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Helpers;
+using Ryujinx.Ava.UI.ViewModels;
+using Ryujinx.HLE.FileSystem;
+using Ryujinx.Input;
+using Ryujinx.Input.Assigner;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class SettingsWindow : StyleableWindow
+ {
+ private ButtonKeyAssigner _currentAssigner;
+
+ internal SettingsViewModel ViewModel { get; set; }
+
+ public SettingsWindow(VirtualFileSystem virtualFileSystem, ContentManager contentManager)
+ {
+ Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance["Settings"]}";
+
+ ViewModel = new SettingsViewModel(virtualFileSystem, contentManager, this);
+ DataContext = ViewModel;
+
+ InitializeComponent();
+ Load();
+
+ FuncMultiValueConverter converter = new(parts => string.Format("{0} {1} {2}", parts.ToArray()).Trim());
+ MultiBinding tzMultiBinding = new() { Converter = converter };
+ tzMultiBinding.Bindings.Add(new Binding("UtcDifference"));
+ tzMultiBinding.Bindings.Add(new Binding("Location"));
+ tzMultiBinding.Bindings.Add(new Binding("Abbreviation"));
+
+ TimeZoneBox.ValueMemberBinding = tzMultiBinding;
+ }
+
+ public SettingsWindow()
+ {
+ ViewModel = new SettingsViewModel();
+ DataContext = ViewModel;
+
+ InitializeComponent();
+ Load();
+ }
+
+ private void Load()
+ {
+ Pages.Children.Clear();
+ NavPanel.SelectionChanged += NavPanelOnSelectionChanged;
+ NavPanel.SelectedItem = NavPanel.MenuItems.ElementAt(0);
+ }
+
+ private void Button_Checked(object sender, RoutedEventArgs e)
+ {
+ if (sender is ToggleButton button)
+ {
+ if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
+ {
+ return;
+ }
+
+ if (_currentAssigner == null && (bool)button.IsChecked)
+ {
+ _currentAssigner = new ButtonKeyAssigner(button);
+
+ FocusManager.Instance.Focus(this, NavigationMethod.Pointer);
+
+ PointerPressed += MouseClick;
+
+ IKeyboard keyboard = (IKeyboard)ViewModel.AvaloniaKeyboardDriver.GetGamepad(ViewModel.AvaloniaKeyboardDriver.GamepadsIds[0]);
+ IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard);
+
+ _currentAssigner.GetInputAndAssign(assigner);
+ }
+ else
+ {
+ if (_currentAssigner != null)
+ {
+ ToggleButton oldButton = _currentAssigner.ToggledButton;
+
+ _currentAssigner.Cancel();
+ _currentAssigner = null;
+
+ button.IsChecked = false;
+ }
+ }
+ }
+ }
+
+ private void Button_Unchecked(object sender, RoutedEventArgs e)
+ {
+ _currentAssigner?.Cancel();
+ _currentAssigner = null;
+ }
+
+ private void MouseClick(object sender, PointerPressedEventArgs e)
+ {
+ bool shouldUnbind = false;
+
+ if (e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed)
+ {
+ shouldUnbind = true;
+ }
+
+ _currentAssigner?.Cancel(shouldUnbind);
+
+ PointerPressed -= MouseClick;
+ }
+
+ private void NavPanelOnSelectionChanged(object sender, NavigationViewSelectionChangedEventArgs e)
+ {
+ if (e.SelectedItem is NavigationViewItem navitem)
+ {
+ NavPanel.Content = navitem.Tag.ToString() switch
+ {
+ "UiPage" => UiPage,
+ "InputPage" => InputPage,
+ "HotkeysPage" => HotkeysPage,
+ "SystemPage" => SystemPage,
+ "CpuPage" => CpuPage,
+ "GraphicsPage" => GraphicsPage,
+ "AudioPage" => AudioPage,
+ "NetworkPage" => NetworkPage,
+ "LoggingPage" => LoggingPage,
+ _ => throw new NotImplementedException()
+ };
+ }
+ }
+
+ private async void AddButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ string path = PathBox.Text;
+
+ if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
+ {
+ ViewModel.GameDirectories.Add(path);
+ ViewModel.DirectoryChanged = true;
+ }
+ else
+ {
+ path = await new OpenFolderDialog().ShowAsync(this);
+
+ if (!string.IsNullOrWhiteSpace(path))
+ {
+ ViewModel.GameDirectories.Add(path);
+ ViewModel.DirectoryChanged = true;
+ }
+ }
+ }
+
+ private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ int oldIndex = GameList.SelectedIndex;
+
+ foreach (string path in new List(GameList.SelectedItems.Cast()))
+ {
+ ViewModel.GameDirectories.Remove(path);
+ ViewModel.DirectoryChanged = true;
+ }
+
+ if (GameList.ItemCount > 0)
+ {
+ GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
+ }
+ }
+
+ private void TimeZoneBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (e.AddedItems != null && e.AddedItems.Count > 0)
+ {
+ if (e.AddedItems[0] is TimeZone timeZone)
+ {
+ e.Handled = true;
+
+ ViewModel.ValidateAndSetTimeZone(timeZone.Location);
+ }
+ }
+ }
+
+ private void TimeZoneBox_OnTextChanged(object sender, EventArgs e)
+ {
+ if (sender is AutoCompleteBox box)
+ {
+ if (box.SelectedItem != null && box.SelectedItem is TimeZone timeZone)
+ {
+ ViewModel.ValidateAndSetTimeZone(timeZone.Location);
+ }
+ }
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ ControllerSettings.Dispose();
+
+ _currentAssigner?.Cancel();
+ _currentAssigner = null;
+
+ base.OnClosed(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/StyleableWindow.cs b/Ryujinx.Ava/UI/Windows/StyleableWindow.cs
new file mode 100644
index 00000000..a157f154
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/StyleableWindow.cs
@@ -0,0 +1,39 @@
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Media.Imaging;
+using Avalonia.Platform;
+using System;
+using System.IO;
+using System.Reflection;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public class StyleableWindow : Window
+ {
+ public IBitmap IconImage { get; set; }
+
+ public StyleableWindow()
+ {
+ WindowStartupLocation = WindowStartupLocation.CenterOwner;
+ TransparencyLevelHint = WindowTransparencyLevel.None;
+
+ using Stream stream = Assembly.GetAssembly(typeof(Ryujinx.Ui.Common.Configuration.ConfigurationState)).GetManifestResourceStream("Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
+
+ Icon = new WindowIcon(stream);
+ stream.Position = 0;
+ IconImage = new Bitmap(stream);
+ }
+
+ protected override void OnOpened(EventArgs e)
+ {
+ base.OnOpened(e);
+ }
+
+ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
+ {
+ base.OnApplyTemplate(e);
+
+ ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml b/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml
new file mode 100644
index 00000000..5a69be9b
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml
@@ -0,0 +1,115 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml.cs b/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml.cs
new file mode 100644
index 00000000..03c2b098
--- /dev/null
+++ b/Ryujinx.Ava/UI/Windows/TitleUpdateWindow.axaml.cs
@@ -0,0 +1,271 @@
+using Avalonia.Collections;
+using Avalonia.Controls;
+using Avalonia.Threading;
+using LibHac.Common;
+using LibHac.Fs;
+using LibHac.Fs.Fsa;
+using LibHac.FsSystem;
+using LibHac.Ns;
+using LibHac.Tools.FsSystem;
+using LibHac.Tools.FsSystem.NcaUtils;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.UI.Controls;
+using Ryujinx.Ava.UI.Helpers;
+using Ryujinx.Ava.UI.Models;
+using Ryujinx.Common.Configuration;
+using Ryujinx.Common.Utilities;
+using Ryujinx.HLE.FileSystem;
+using Ryujinx.HLE.HOS;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Path = System.IO.Path;
+using SpanHelpers = LibHac.Common.SpanHelpers;
+
+namespace Ryujinx.Ava.UI.Windows
+{
+ public partial class TitleUpdateWindow : StyleableWindow
+ {
+ private readonly string _titleUpdateJsonPath;
+ private TitleUpdateMetadata _titleUpdateWindowData;
+
+ private VirtualFileSystem _virtualFileSystem { get; }
+ private AvaloniaList _titleUpdates { get; set; }
+
+ private ulong _titleId { get; }
+ private string _titleName { get; }
+
+ public TitleUpdateWindow()
+ {
+ DataContext = this;
+
+ InitializeComponent();
+
+ Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance["UpdateWindowTitle"]} - {_titleName} ({_titleId:X16})";
+ }
+
+ public TitleUpdateWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
+ {
+ _virtualFileSystem = virtualFileSystem;
+ _titleUpdates = new AvaloniaList();
+
+ _titleId = titleId;
+ _titleName = titleName;
+
+ _titleUpdateJsonPath = Path.Combine(AppDataManager.GamesDirPath, titleId.ToString("x16"), "updates.json");
+
+ try
+ {
+ _titleUpdateWindowData = JsonHelper.DeserializeFromFile(_titleUpdateJsonPath);
+ }
+ catch
+ {
+ _titleUpdateWindowData = new TitleUpdateMetadata
+ {
+ Selected = "",
+ Paths = new List()
+ };
+ }
+
+ DataContext = this;
+
+ InitializeComponent();
+
+ Title = $"Ryujinx {Program.Version} - {LocaleManager.Instance["UpdateWindowTitle"]} - {_titleName} ({_titleId:X16})";
+
+ LoadUpdates();
+ PrintHeading();
+ }
+
+ private void PrintHeading()
+ {
+ Heading.Text = string.Format(LocaleManager.Instance["GameUpdateWindowHeading"], _titleUpdates.Count, _titleName, _titleId.ToString("X16"));
+ }
+
+ private void LoadUpdates()
+ {
+ _titleUpdates.Add(new TitleUpdateModel(default, string.Empty, true));
+
+ foreach (string path in _titleUpdateWindowData.Paths)
+ {
+ AddUpdate(path);
+ }
+
+ if (_titleUpdateWindowData.Selected == "")
+ {
+ _titleUpdates[0].IsEnabled = true;
+ }
+ else
+ {
+ TitleUpdateModel selected = _titleUpdates.FirstOrDefault(x => x.Path == _titleUpdateWindowData.Selected);
+ List enabled = _titleUpdates.Where(x => x.IsEnabled).ToList();
+
+ foreach (TitleUpdateModel update in enabled)
+ {
+ update.IsEnabled = false;
+ }
+
+ if (selected != null)
+ {
+ selected.IsEnabled = true;
+ }
+ }
+
+ SortUpdates();
+ }
+
+ private void AddUpdate(string path)
+ {
+ if (File.Exists(path) && !_titleUpdates.Any(x => x.Path == path))
+ {
+ using FileStream file = new(path, FileMode.Open, FileAccess.Read);
+
+ try
+ {
+ (Nca patchNca, Nca controlNca) = ApplicationLoader.GetGameUpdateDataFromPartition(_virtualFileSystem, new PartitionFileSystem(file.AsStorage()), _titleId.ToString("x16"), 0);
+
+ if (controlNca != null && patchNca != null)
+ {
+ ApplicationControlProperty controlData = new();
+
+ using UniqueRef nacpFile = new();
+
+ controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(ref nacpFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
+ nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
+
+ _titleUpdates.Add(new TitleUpdateModel(controlData, path));
+
+ foreach (var update in _titleUpdates)
+ {
+ update.IsEnabled = false;
+ }
+
+ _titleUpdates.Last().IsEnabled = true;
+ }
+ else
+ {
+ Dispatcher.UIThread.Post(async () =>
+ {
+ await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance["DialogUpdateAddUpdateErrorMessage"]);
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ Dispatcher.UIThread.Post(async () =>
+ {
+ await ContentDialogHelper.CreateErrorDialog(string.Format(LocaleManager.Instance["DialogDlcLoadNcaErrorMessage"], ex.Message, path));
+ });
+ }
+ }
+ }
+
+ private void RemoveUpdates(bool removeSelectedOnly = false)
+ {
+ if (removeSelectedOnly)
+ {
+ _titleUpdates.RemoveAll(_titleUpdates.Where(x => x.IsEnabled && !x.IsNoUpdate).ToList());
+ }
+ else
+ {
+ _titleUpdates.RemoveAll(_titleUpdates.Where(x => !x.IsNoUpdate).ToList());
+ }
+
+ _titleUpdates.FirstOrDefault(x => x.IsNoUpdate).IsEnabled = true;
+
+ SortUpdates();
+ PrintHeading();
+ }
+
+ public void RemoveSelected()
+ {
+ RemoveUpdates(true);
+ }
+
+ public void RemoveAll()
+ {
+ RemoveUpdates();
+ }
+
+ public async void Add()
+ {
+ OpenFileDialog dialog = new()
+ {
+ Title = LocaleManager.Instance["SelectUpdateDialogTitle"],
+ AllowMultiple = true
+ };
+
+ dialog.Filters.Add(new FileDialogFilter
+ {
+ Name = "NSP",
+ Extensions = { "nsp" }
+ });
+
+ string[] files = await dialog.ShowAsync(this);
+
+ if (files != null)
+ {
+ foreach (string file in files)
+ {
+ AddUpdate(file);
+ }
+ }
+
+ SortUpdates();
+ PrintHeading();
+ }
+
+ private void SortUpdates()
+ {
+ var list = _titleUpdates.ToList();
+
+ list.Sort((first, second) =>
+ {
+ if (string.IsNullOrEmpty(first.Control.DisplayVersionString.ToString()))
+ {
+ return -1;
+ }
+ else if (string.IsNullOrEmpty(second.Control.DisplayVersionString.ToString()))
+ {
+ return 1;
+ }
+
+ return Version.Parse(first.Control.DisplayVersionString.ToString()).CompareTo(Version.Parse(second.Control.DisplayVersionString.ToString())) * -1;
+ });
+
+ _titleUpdates.Clear();
+ _titleUpdates.AddRange(list);
+ }
+
+ public void Save()
+ {
+ _titleUpdateWindowData.Paths.Clear();
+
+ _titleUpdateWindowData.Selected = "";
+
+ foreach (TitleUpdateModel update in _titleUpdates)
+ {
+ _titleUpdateWindowData.Paths.Add(update.Path);
+
+ if (update.IsEnabled)
+ {
+ _titleUpdateWindowData.Selected = update.Path;
+ }
+ }
+
+ using (FileStream titleUpdateJsonStream = File.Create(_titleUpdateJsonPath, 4096, FileOptions.WriteThrough))
+ {
+ titleUpdateJsonStream.Write(Encoding.UTF8.GetBytes(JsonHelper.Serialize(_titleUpdateWindowData, true)));
+ }
+
+ if (Owner is MainWindow window)
+ {
+ window.ViewModel.LoadApplications();
+ }
+
+ Close();
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.2.3