From 81412c7dd5f35cef695d48ce2000f600dd977b5f Mon Sep 17 00:00:00 2001 From: GreemDev Date: Thu, 29 May 2025 02:09:21 -0500 Subject: [PATCH] misc: fix duplicated code (oops), reorder the commands in-code to match the UI --- .../HOS/Services/Account/Acc/Types/UserId.cs | 12 +- .../Controls/ApplicationContextMenu.axaml.cs | 364 -------------- .../UI/ViewModels/MainWindowViewModel.cs | 443 +++++++++--------- 3 files changed, 236 insertions(+), 583 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs index c9c78af9a..a6b1a47b6 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs @@ -51,14 +51,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return High.ToString("x16") + Low.ToString("x16"); } - public Uid ToLibHacUid() - { - return new Uid((ulong)High, (ulong)Low); - } - - public UInt128 ToUInt128() - { - return new UInt128((ulong)High, (ulong)Low); - } + public Uid ToLibHacUid() => new((ulong)High, (ulong)Low); + public LibHac.Fs.UserId ToLibHac() => new((ulong)High, (ulong)Low); + public UInt128 ToUInt128() => new((ulong)High, (ulong)Low); } } diff --git a/src/Ryujinx/UI/Controls/ApplicationContextMenu.axaml.cs b/src/Ryujinx/UI/Controls/ApplicationContextMenu.axaml.cs index 6f93676e2..1f9f6c691 100644 --- a/src/Ryujinx/UI/Controls/ApplicationContextMenu.axaml.cs +++ b/src/Ryujinx/UI/Controls/ApplicationContextMenu.axaml.cs @@ -35,369 +35,5 @@ namespace Ryujinx.Ava.UI.Controls { AvaloniaXamlLoader.Load(this); } - - public static RelayCommand ToggleFavorite { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - { - viewModel.SelectedApplication.Favorite = !viewModel.SelectedApplication.Favorite; - - ApplicationLibrary.LoadAndSaveMetaData(viewModel.SelectedApplication.IdString, appMetadata => - { - appMetadata.Favorite = viewModel.SelectedApplication.Favorite; - }); - - viewModel.RefreshView(); - } - ); - - public static RelayCommand OpenUserSaveDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - OpenSaveDirectory(viewModel, SaveDataType.Account, new UserId((ulong)viewModel.AccountManager.LastOpenedUser.UserId.High, (ulong)viewModel.AccountManager.LastOpenedUser.UserId.Low)) - ); - - public static RelayCommand OpenDeviceSaveDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => OpenSaveDirectory(viewModel, SaveDataType.Device, default)); - - public static RelayCommand OpenBcatSaveDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => OpenSaveDirectory(viewModel, SaveDataType.Bcat, default)); - - private static void OpenSaveDirectory(MainWindowViewModel viewModel, SaveDataType saveDataType, UserId userId) - { - SaveDataFilter saveDataFilter = SaveDataFilter.Make(viewModel.SelectedApplication.Id, saveDataType, userId, saveDataId: default, index: default); - - ApplicationHelper.OpenSaveDir(in saveDataFilter, viewModel.SelectedApplication.Id, viewModel.SelectedApplication.ControlHolder, viewModel.SelectedApplication.Name); - } - - public static AsyncRelayCommand OpenTitleUpdateManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => TitleUpdateManagerView.Show(viewModel.ApplicationLibrary, viewModel.SelectedApplication) - ); - - public static AsyncRelayCommand OpenDownloadableContentManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => DownloadableContentManagerView.Show(viewModel.ApplicationLibrary, viewModel.SelectedApplication) - ); - - public static AsyncRelayCommand OpenCheatManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => StyleableAppWindow.ShowAsync( - new CheatWindow( - viewModel.VirtualFileSystem, - viewModel.SelectedApplication.IdString, - viewModel.SelectedApplication.Name, - viewModel.SelectedApplication.Path - ) - )); - - public static RelayCommand OpenModsDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - { - string modsBasePath = ModLoader.GetModsBasePath(); - string titleModsPath = ModLoader.GetApplicationDir(modsBasePath, viewModel.SelectedApplication.IdString); - - OpenHelper.OpenFolder(titleModsPath); - }); - - public static RelayCommand OpenSdModsDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - { - string sdModsBasePath = ModLoader.GetSdModsBasePath(); - string titleModsPath = ModLoader.GetApplicationDir(sdModsBasePath, viewModel.SelectedApplication.IdString); - - OpenHelper.OpenFolder(titleModsPath); - }); - - public static AsyncRelayCommand OpenModManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await ModManagerView.Show( - viewModel.SelectedApplication.Id, - viewModel.SelectedApplication.IdBase, - viewModel.ApplicationLibrary, - viewModel.SelectedApplication.Name); - }); - - public static AsyncRelayCommand PurgePtcCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) - { - DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); - DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); - - List cacheFiles = []; - - if (mainDir.Exists) - { - cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); - } - - if (backupDir.Exists) - { - cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); - } - - if (cacheFiles.Count > 0) - { - foreach (FileInfo file in cacheFiles) - { - try - { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); - } - } - } - } - }); - - public static AsyncRelayCommand NukePtcCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCNukeMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) - { - DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); - DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); - - List cacheFiles = []; - - if (mainDir.Exists) - { - cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); - cacheFiles.AddRange(mainDir.EnumerateFiles("*.info")); - } - - if (backupDir.Exists) - { - cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); - cacheFiles.AddRange(backupDir.EnumerateFiles("*.info")); - } - - if (cacheFiles.Count > 0) - { - foreach (FileInfo file in cacheFiles) - { - try - { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); - } - } - } - } - }); - - public static AsyncRelayCommand PurgeShaderCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogShaderDeletionMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) - { - DirectoryInfo shaderCacheDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "shader")); - - List oldCacheDirectories = []; - List newCacheFiles = []; - - if (shaderCacheDir.Exists) - { - oldCacheDirectories.AddRange(shaderCacheDir.EnumerateDirectories("*")); - newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.toc")); - newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.data")); - } - - if ((oldCacheDirectories.Count > 0 || newCacheFiles.Count > 0)) - { - foreach (DirectoryInfo directory in oldCacheDirectories) - { - try - { - directory.Delete(true); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, directory.Name, ex)); - } - } - - foreach (FileInfo file in newCacheFiles) - { - try - { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.ShaderCachePurgeError, file.Name, ex)); - } - } - } - } - }); - - public static RelayCommand OpenPtcDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - { - string ptcDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu"); - string mainDir = Path.Combine(ptcDir, "0"); - string backupDir = Path.Combine(ptcDir, "1"); - - if (!Directory.Exists(ptcDir)) - { - Directory.CreateDirectory(ptcDir); - Directory.CreateDirectory(mainDir); - Directory.CreateDirectory(backupDir); - } - - OpenHelper.OpenFolder(ptcDir); - }); - - public static RelayCommand OpenShaderCacheDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - { - string shaderCacheDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString.ToLower(), "cache", "shader"); - - if (!Directory.Exists(shaderCacheDir)) - { - Directory.CreateDirectory(shaderCacheDir); - } - - OpenHelper.OpenFolder(shaderCacheDir); - }); - - public static AsyncRelayCommand ExtractApplicationExeFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await ApplicationHelper.ExtractSection( - viewModel.StorageProvider, - NcaSectionType.Code, - viewModel.SelectedApplication.Path, - viewModel.SelectedApplication.Name); - }); - - public static AsyncRelayCommand ExtractApplicationRomFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await ApplicationHelper.ExtractSection( - viewModel.StorageProvider, - NcaSectionType.Data, - viewModel.SelectedApplication.Path, - viewModel.SelectedApplication.Name); - }); - - public static AsyncRelayCommand ExtractApplicationAocRomFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - DownloadableContentModel selectedDlc = await DlcSelectView.Show(viewModel.SelectedApplication.Id, viewModel.ApplicationLibrary); - - if (selectedDlc is not null) - { - await ApplicationHelper.ExtractAoc( - viewModel.StorageProvider, - selectedDlc.ContainerPath, - selectedDlc.FileName); - } - }); - - public static AsyncRelayCommand ExtractApplicationLogo { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - IReadOnlyList result = await viewModel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions - { - Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle], - AllowMultiple = false, - }); - - if (result.Count == 0) - return; - - ApplicationHelper.ExtractSection( - result[0].Path.LocalPath, - NcaSectionType.Logo, - viewModel.SelectedApplication.Path, - viewModel.SelectedApplication.Name); - - IStorageFile iconFile = await result[0].CreateFileAsync($"{viewModel.SelectedApplication.IdString}.png"); - await using Stream fileStream = await iconFile.OpenWriteAsync(); - - using SKBitmap bitmap = SKBitmap.Decode(viewModel.SelectedApplication.Icon) - .Resize(new SKSizeI(512, 512), SKFilterQuality.High); - - using SKData png = bitmap.Encode(SKEncodedImageFormat.Png, 100); - - png.SaveTo(fileStream); - }); - - public static RelayCommand CreateApplicationShortcut { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => ShortcutHelper.CreateAppShortcut( - viewModel.SelectedApplication.Path, - viewModel.SelectedApplication.Name, - viewModel.SelectedApplication.IdString, - viewModel.SelectedApplication.Icon - )); - - public static AsyncRelayCommand EditGameConfiguration { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await StyleableAppWindow.ShowAsync(new GameSpecificSettingsWindow(viewModel)); - - // just checking for file presence - viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists(Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString,false,false)); - - viewModel.RefreshView(); - }); - - public static AsyncRelayCommand OpenApplicationCompatibility { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => CompatibilityListWindow.Show(viewModel.SelectedApplication.IdString)); - - public static AsyncRelayCommand OpenApplicationData { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => ApplicationDataView.Show(viewModel.SelectedApplication)); - - public static AsyncRelayCommand RunApplication { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => viewModel.LoadApplication(viewModel.SelectedApplication)); - - public static AsyncRelayCommand TrimXci { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => viewModel.TrimXCIFile(viewModel.SelectedApplication.Path)); } } diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index 61af0db34..020d96794 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -1963,8 +1963,12 @@ namespace Ryujinx.Ava.UI.ViewModels #endregion #region Context Menu commands + + public static AsyncRelayCommand RunApplication { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => viewModel.LoadApplication(viewModel.SelectedApplication)); - public static RelayCommand ToggleFavorite { get; } = + public static RelayCommand ToggleFavorite { get; } = Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => { @@ -1979,39 +1983,73 @@ namespace Ryujinx.Ava.UI.ViewModels } ); - public static RelayCommand OpenUserSaveDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => - OpenSaveDirectory(viewModel, SaveDataType.Account, new LibHac.Fs.UserId((ulong)viewModel.AccountManager.LastOpenedUser.UserId.High, (ulong)viewModel.AccountManager.LastOpenedUser.UserId.Low)) - ); + public static RelayCommand CreateApplicationShortcut { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => ShortcutHelper.CreateAppShortcut( + viewModel.SelectedApplication.Path, + viewModel.SelectedApplication.Name, + viewModel.SelectedApplication.IdString, + viewModel.SelectedApplication.Icon + )); + public static AsyncRelayCommand EditGameConfiguration { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + async viewModel => + { + await StyleableAppWindow.ShowAsync(new GameSpecificSettingsWindow(viewModel)); + + // just checking for file presence + viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists( + Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString, false, false)); + + viewModel.RefreshView(); + }); + + public static AsyncRelayCommand OpenApplicationCompatibility { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => CompatibilityListWindow.Show(viewModel.SelectedApplication.IdString)); + + public static AsyncRelayCommand OpenApplicationData { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => ApplicationDataView.Show(viewModel.SelectedApplication)); + + public static RelayCommand OpenUserSaveDirectory { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => + OpenSaveDirectory(viewModel, SaveDataType.Account, viewModel.AccountManager.LastOpenedUser.UserId.ToLibHac()) + ); + public static RelayCommand OpenDeviceSaveDirectory { get; } = Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => OpenSaveDirectory(viewModel, SaveDataType.Device, default)); - + public static RelayCommand OpenBcatSaveDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => OpenSaveDirectory(viewModel, SaveDataType.Bcat, default)); - private static void OpenSaveDirectory(MainWindowViewModel viewModel, SaveDataType saveDataType, LibHac.Fs.UserId userId) + private static void OpenSaveDirectory(MainWindowViewModel viewModel, SaveDataType saveDataType, + LibHac.Fs.UserId userId) { - SaveDataFilter saveDataFilter = SaveDataFilter.Make(viewModel.SelectedApplication.Id, saveDataType, userId, saveDataId: default, index: default); + SaveDataFilter saveDataFilter = SaveDataFilter.Make(viewModel.SelectedApplication.Id, saveDataType, userId, + saveDataId: default, index: default); - ApplicationHelper.OpenSaveDir(in saveDataFilter, viewModel.SelectedApplication.Id, viewModel.SelectedApplication.ControlHolder, viewModel.SelectedApplication.Name); + ApplicationHelper.OpenSaveDir(in saveDataFilter, viewModel.SelectedApplication.Id, + viewModel.SelectedApplication.ControlHolder, viewModel.SelectedApplication.Name); } - + public static AsyncRelayCommand OpenTitleUpdateManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => TitleUpdateManagerView.Show(viewModel.ApplicationLibrary, viewModel.SelectedApplication) ); - + public static AsyncRelayCommand OpenDownloadableContentManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => DownloadableContentManagerView.Show(viewModel.ApplicationLibrary, viewModel.SelectedApplication) + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => + DownloadableContentManagerView.Show(viewModel.ApplicationLibrary, viewModel.SelectedApplication) ); - + public static AsyncRelayCommand OpenCheatManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => StyleableAppWindow.ShowAsync( new CheatWindow( viewModel.VirtualFileSystem, @@ -2021,8 +2059,16 @@ namespace Ryujinx.Ava.UI.ViewModels ) )); + public static AsyncRelayCommand OpenModManager { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => ModManagerView.Show( + viewModel.SelectedApplication.Id, + viewModel.SelectedApplication.IdBase, + viewModel.ApplicationLibrary, + viewModel.SelectedApplication.Name)); + public static RelayCommand OpenModsDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => { string modsBasePath = ModLoader.GetModsBasePath(); @@ -2030,191 +2076,202 @@ namespace Ryujinx.Ava.UI.ViewModels OpenHelper.OpenFolder(titleModsPath); }); - + public static RelayCommand OpenSdModsDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => - { - string sdModsBasePath = ModLoader.GetSdModsBasePath(); - string titleModsPath = ModLoader.GetApplicationDir(sdModsBasePath, viewModel.SelectedApplication.IdString); + { + string sdModsBasePath = ModLoader.GetSdModsBasePath(); + string titleModsPath = ModLoader.GetApplicationDir(sdModsBasePath, viewModel.SelectedApplication.IdString); - OpenHelper.OpenFolder(titleModsPath); - }); - - public static AsyncRelayCommand OpenModManager { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await ModManagerView.Show( - viewModel.SelectedApplication.Id, - viewModel.SelectedApplication.IdBase, - viewModel.ApplicationLibrary, - viewModel.SelectedApplication.Name); - }); + OpenHelper.OpenFolder(titleModsPath); + }); + + public static AsyncRelayCommand TrimXci { get; } = + Commands.CreateConditional(vm => vm?.SelectedApplication != null, + viewModel => viewModel.TrimXCIFile(viewModel.SelectedApplication.Path)); public static AsyncRelayCommand PurgePtcCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) { - DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); - DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); + UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogWarning], + LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionMessage, + viewModel.SelectedApplication.Name) + ); - List cacheFiles = []; - - if (mainDir.Exists) + if (result == UserResult.Yes) { - cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); - } + DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); + DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); - if (backupDir.Exists) - { - cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); - } + List cacheFiles = []; - if (cacheFiles.Count > 0) - { - foreach (FileInfo file in cacheFiles) + if (mainDir.Exists) { - try + cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); + } + + if (backupDir.Exists) + { + cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); + } + + if (cacheFiles.Count > 0) + { + foreach (FileInfo file in cacheFiles) { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); + try + { + file.Delete(); + } + catch (Exception ex) + { + await ContentDialogHelper.CreateErrorDialog( + LocaleManager.Instance.UpdateAndGetDynamicValue( + LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); + } } } } - } - }); - + }); + public static AsyncRelayCommand NukePtcCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCNukeMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) { - DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); - DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); + UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogWarning], + LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCNukeMessage, + viewModel.SelectedApplication.Name) + ); - List cacheFiles = []; - - if (mainDir.Exists) + if (result == UserResult.Yes) { - cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); - cacheFiles.AddRange(mainDir.EnumerateFiles("*.info")); - } + DirectoryInfo mainDir = new(Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString, "cache", "cpu", "0")); + DirectoryInfo backupDir = new(Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString, "cache", "cpu", "1")); - if (backupDir.Exists) - { - cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); - cacheFiles.AddRange(backupDir.EnumerateFiles("*.info")); - } + List cacheFiles = []; - if (cacheFiles.Count > 0) - { - foreach (FileInfo file in cacheFiles) + if (mainDir.Exists) { - try + cacheFiles.AddRange(mainDir.EnumerateFiles("*.cache")); + cacheFiles.AddRange(mainDir.EnumerateFiles("*.info")); + } + + if (backupDir.Exists) + { + cacheFiles.AddRange(backupDir.EnumerateFiles("*.cache")); + cacheFiles.AddRange(backupDir.EnumerateFiles("*.info")); + } + + if (cacheFiles.Count > 0) + { + foreach (FileInfo file in cacheFiles) { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); + try + { + file.Delete(); + } + catch (Exception ex) + { + await ContentDialogHelper.CreateErrorDialog( + LocaleManager.Instance.UpdateAndGetDynamicValue( + LocaleKeys.DialogPPTCDeletionErrorMessage, file.Name, ex)); + } } } } - } - }); - + }); + public static AsyncRelayCommand PurgeShaderCache { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => - { - UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogShaderDeletionMessage, viewModel.SelectedApplication.Name) - ); - - if (result == UserResult.Yes) - { - DirectoryInfo shaderCacheDir = new(Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "shader")); - - List oldCacheDirectories = []; - List newCacheFiles = []; - - if (shaderCacheDir.Exists) { - oldCacheDirectories.AddRange(shaderCacheDir.EnumerateDirectories("*")); - newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.toc")); - newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.data")); - } + UserResult result = await ContentDialogHelper.CreateLocalizedConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogWarning], + LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogShaderDeletionMessage, + viewModel.SelectedApplication.Name) + ); - if ((oldCacheDirectories.Count > 0 || newCacheFiles.Count > 0)) - { - foreach (DirectoryInfo directory in oldCacheDirectories) + if (result == UserResult.Yes) { - try + DirectoryInfo shaderCacheDir = new(Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString, "cache", "shader")); + + List oldCacheDirectories = []; + List newCacheFiles = []; + + if (shaderCacheDir.Exists) { - directory.Delete(true); + oldCacheDirectories.AddRange(shaderCacheDir.EnumerateDirectories("*")); + newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.toc")); + newCacheFiles.AddRange(shaderCacheDir.GetFiles("*.data")); } - catch (Exception ex) + + if ((oldCacheDirectories.Count > 0 || newCacheFiles.Count > 0)) { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionErrorMessage, directory.Name, ex)); + foreach (DirectoryInfo directory in oldCacheDirectories) + { + try + { + directory.Delete(true); + } + catch (Exception ex) + { + await ContentDialogHelper.CreateErrorDialog( + LocaleManager.Instance.UpdateAndGetDynamicValue( + LocaleKeys.DialogPPTCDeletionErrorMessage, directory.Name, ex)); + } + } + + foreach (FileInfo file in newCacheFiles) + { + try + { + file.Delete(); + } + catch (Exception ex) + { + await ContentDialogHelper.CreateErrorDialog( + LocaleManager.Instance.UpdateAndGetDynamicValue( + LocaleKeys.ShaderCachePurgeError, file.Name, ex)); + } + } } } + }); - foreach (FileInfo file in newCacheFiles) - { - try - { - file.Delete(); - } - catch (Exception ex) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.ShaderCachePurgeError, file.Name, ex)); - } - } - } - } - }); - public static RelayCommand OpenPtcDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => - { - string ptcDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, "cache", "cpu"); - string mainDir = Path.Combine(ptcDir, "0"); - string backupDir = Path.Combine(ptcDir, "1"); - - if (!Directory.Exists(ptcDir)) { - Directory.CreateDirectory(ptcDir); - Directory.CreateDirectory(mainDir); - Directory.CreateDirectory(backupDir); - } + string ptcDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString, + "cache", "cpu"); + string mainDir = Path.Combine(ptcDir, "0"); + string backupDir = Path.Combine(ptcDir, "1"); + + if (!Directory.Exists(ptcDir)) + { + Directory.CreateDirectory(ptcDir); + Directory.CreateDirectory(mainDir); + Directory.CreateDirectory(backupDir); + } + + OpenHelper.OpenFolder(ptcDir); + }); - OpenHelper.OpenFolder(ptcDir); - }); - public static RelayCommand OpenShaderCacheDirectory { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, viewModel => { - string shaderCacheDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.IdString.ToLower(), "cache", "shader"); + string shaderCacheDir = Path.Combine(AppDataManager.GamesDirPath, + viewModel.SelectedApplication.IdString.ToLower(), "cache", "shader"); if (!Directory.Exists(shaderCacheDir)) { @@ -2225,7 +2282,7 @@ namespace Ryujinx.Ava.UI.ViewModels }); public static AsyncRelayCommand ExtractApplicationExeFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => { await ApplicationHelper.ExtractSection( @@ -2234,9 +2291,9 @@ namespace Ryujinx.Ava.UI.ViewModels viewModel.SelectedApplication.Path, viewModel.SelectedApplication.Name); }); - + public static AsyncRelayCommand ExtractApplicationRomFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => { await ApplicationHelper.ExtractSection( @@ -2245,13 +2302,14 @@ namespace Ryujinx.Ava.UI.ViewModels viewModel.SelectedApplication.Path, viewModel.SelectedApplication.Name); }); - + public static AsyncRelayCommand ExtractApplicationAocRomFs { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => { - DownloadableContentModel selectedDlc = await DlcSelectView.Show(viewModel.SelectedApplication.Id, viewModel.ApplicationLibrary); - + DownloadableContentModel selectedDlc = await DlcSelectView.Show(viewModel.SelectedApplication.Id, + viewModel.ApplicationLibrary); + if (selectedDlc is not null) { await ApplicationHelper.ExtractAoc( @@ -2260,16 +2318,17 @@ namespace Ryujinx.Ava.UI.ViewModels selectedDlc.FileName); } }); - + public static AsyncRelayCommand ExtractApplicationLogo { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, + Commands.CreateConditional(vm => vm?.SelectedApplication != null, async viewModel => { - IReadOnlyList result = await viewModel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions - { - Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle], - AllowMultiple = false, - }); + IReadOnlyList result = await viewModel.StorageProvider.OpenFolderPickerAsync( + new FolderPickerOpenOptions + { + Title = LocaleManager.Instance[LocaleKeys.FolderDialogExtractTitle], + AllowMultiple = false, + }); if (result.Count == 0) return; @@ -2280,7 +2339,8 @@ namespace Ryujinx.Ava.UI.ViewModels viewModel.SelectedApplication.Path, viewModel.SelectedApplication.Name); - IStorageFile iconFile = await result[0].CreateFileAsync($"{viewModel.SelectedApplication.IdString}.png"); + IStorageFile iconFile = + await result[0].CreateFileAsync($"{viewModel.SelectedApplication.IdString}.png"); await using Stream fileStream = await iconFile.OpenWriteAsync(); using SKBitmap bitmap = SKBitmap.Decode(viewModel.SelectedApplication.Icon) @@ -2291,43 +2351,6 @@ namespace Ryujinx.Ava.UI.ViewModels png.SaveTo(fileStream); }); - public static RelayCommand CreateApplicationShortcut { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => ShortcutHelper.CreateAppShortcut( - viewModel.SelectedApplication.Path, - viewModel.SelectedApplication.Name, - viewModel.SelectedApplication.IdString, - viewModel.SelectedApplication.Icon - )); - - public static AsyncRelayCommand EditGameConfiguration { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - async viewModel => - { - await StyleableAppWindow.ShowAsync(new GameSpecificSettingsWindow(viewModel)); - - // just checking for file presence - viewModel.SelectedApplication.HasIndependentConfiguration = File.Exists(Program.GetDirGameUserConfig(viewModel.SelectedApplication.IdString,false,false)); - - viewModel.RefreshView(); - }); - - public static AsyncRelayCommand OpenApplicationCompatibility { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => CompatibilityListWindow.Show(viewModel.SelectedApplication.IdString)); - - public static AsyncRelayCommand OpenApplicationData { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => ApplicationDataView.Show(viewModel.SelectedApplication)); - - public static AsyncRelayCommand RunApplication { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => viewModel.LoadApplication(viewModel.SelectedApplication)); - - public static AsyncRelayCommand TrimXci { get; } = - Commands.CreateConditional(vm => vm?.SelectedApplication != null, - viewModel => viewModel.TrimXCIFile(viewModel.SelectedApplication.Path)); - #endregion } }