diff --git a/assets/locales.json b/assets/locales.json index 45914a6d1..afb2ecf11 100644 --- a/assets/locales.json +++ b/assets/locales.json @@ -24292,6 +24292,56 @@ "zh_TW": "" } }, + { + "ID": "SettingsTabDebugPurgeAllCachesSuccessTitle", + "Translations": { + "ar_SA": "", + "de_DE": "", + "el_GR": "", + "en_US": "All Shader & CPU caches deleted", + "es_ES": "", + "fr_FR": "", + "he_IL": "", + "it_IT": "", + "ja_JP": "", + "ko_KR": "", + "no_NO": "", + "pl_PL": "", + "pt_BR": "", + "ru_RU": "", + "sv_SE": "", + "th_TH": "", + "tr_TR": "", + "uk_UA": "", + "zh_CN": "", + "zh_TW": "" + } + }, + { + "ID": "SettingsTabDebugPurgeAllCachesSuccessText", + "Translations": { + "ar_SA": "", + "de_DE": "", + "el_GR": "", + "en_US": "Destroyed the caches of {0} applications.", + "es_ES": "", + "fr_FR": "", + "he_IL": "", + "it_IT": "", + "ja_JP": "", + "ko_KR": "", + "no_NO": "", + "pl_PL": "", + "pt_BR": "", + "ru_RU": "", + "sv_SE": "", + "th_TH": "", + "tr_TR": "", + "uk_UA": "", + "zh_CN": "", + "zh_TW": "" + } + }, { "ID": "LdnGameListOpen", "Translations": { @@ -24918,4 +24968,4 @@ } } ] -} \ No newline at end of file +} diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index 233c30bad..071d83f86 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -4,11 +4,13 @@ using Avalonia.Media.Imaging; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using DynamicData.Binding; using LibHac.Tools.FsSystem; using Ryujinx.Audio.Backends.OpenAL; using Ryujinx.Audio.Backends.SDL3; using Ryujinx.Audio.Backends.SoundIo; using Ryujinx.Ava.Common.Locale; +using Ryujinx.Ava.Systems.AppLibrary; using Ryujinx.Ava.Systems.Configuration; using Ryujinx.Ava.Systems.Configuration.System; using Ryujinx.Ava.Systems.Configuration.UI; @@ -19,6 +21,7 @@ using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration.Multiplayer; using Ryujinx.Common.GraphicsDriver; using Ryujinx.Common.Helper; +using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Vulkan; using Ryujinx.HLE; @@ -912,7 +915,13 @@ namespace Ryujinx.Ava.UI.ViewModels CloseWindow?.Invoke(); } - [ObservableProperty] private bool _wantsToReset; + public void CancelButton() + { + RevertIfNotSaved(); + CloseWindow?.Invoke(); + } + + [ObservableProperty] public partial bool WantsToReset { get; set; } public AsyncRelayCommand ResetButton => Commands.Create(async () => { @@ -932,10 +941,62 @@ namespace Ryujinx.Ava.UI.ViewModels "Configuration Reset"); }); - public void CancelButton() + public AsyncRelayCommand PurgeAllCaches => Commands.Create(async () => { - RevertIfNotSaved(); - CloseWindow?.Invoke(); - } + ObservableCollectionExtended appList = RyujinxApp.MainWindow.ViewModel.Applications; + + if (appList.Count == 0) + { + return; + } + + UserResult result = await ContentDialogHelper.CreateConfirmationDialog( + LocaleManager.Instance[LocaleKeys.DialogWarning], + LocaleManager.Instance[LocaleKeys.DialogDeleteAllCaches], + LocaleManager.Instance[LocaleKeys.InputDialogYes], + LocaleManager.Instance[LocaleKeys.InputDialogNo], + LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); + + bool hasErrors = false; + + if (result != UserResult.Yes) + { + return; + } + + foreach (ApplicationData application in appList) + { + DirectoryInfo cacheDir = new(Path.Combine(AppDataManager.GamesDirPath, application.IdString, "cache")); + + if (!cacheDir.Exists) + { + continue; + } + + foreach (DirectoryInfo dInfo in cacheDir.EnumerateDirectories()) + { + try + { + dInfo.Delete(recursive: true); + } + catch (Exception ex) + { + Logger.Error?.PrintMsg(LogClass.Application, $"Failed to purge shader cache for {application.Name} ({application.IdString}): {ex}"); + hasErrors = true; + } + } + } + + if (hasErrors) + { + await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogDeleteAllCachesErrorMessage]); + } + else + { + NotificationHelper.ShowSuccess( + title: LocaleManager.Instance[LocaleKeys.SettingsTabDebugPurgeAllCachesSuccessTitle], + text: LocaleManager.GetFormatted(LocaleKeys.SettingsTabDebugPurgeAllCachesSuccessText, appList.Count)); + } + }); } } diff --git a/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml index f1ff9c5ea..56a049d46 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml @@ -60,9 +60,7 @@ - diff --git a/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml.cs index d7924ab52..d68a2444c 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsDebugView.axaml.cs @@ -1,11 +1,4 @@ using Avalonia.Controls; -using Avalonia.Interactivity; -using Ryujinx.Ava.Common.Locale; -using Ryujinx.Ava.UI.Helpers; -using Ryujinx.Common.Configuration; -using Ryujinx.Common.Logging; -using System; -using System.IO; namespace Ryujinx.Ava.UI.Views.Settings { @@ -15,57 +8,5 @@ namespace Ryujinx.Ava.UI.Views.Settings { InitializeComponent(); } - - private async void PurgeAllSharedCaches_OnClick(object sender, RoutedEventArgs routedEventArgs) - { - var appList = RyujinxApp.MainWindow.ViewModel.Applications; - - if (appList.Count == 0) - { - return; - } - - UserResult result = await ContentDialogHelper.CreateConfirmationDialog( - LocaleManager.Instance[LocaleKeys.DialogWarning], - LocaleManager.Instance[LocaleKeys.DialogDeleteAllCaches], - LocaleManager.Instance[LocaleKeys.InputDialogYes], - LocaleManager.Instance[LocaleKeys.InputDialogNo], - LocaleManager.Instance[LocaleKeys.RyujinxConfirm]); - bool hasErrors = false; - - if (result != UserResult.Yes) - { - return; - } - - foreach (var application in appList) - { - DirectoryInfo cacheDir = new(Path.Combine(AppDataManager.GamesDirPath, application.IdString, "cache")); - - if (!cacheDir.Exists) - { - continue; - } - - foreach (var finfo in cacheDir.EnumerateDirectories()) - { - try - { - finfo.Delete(true); - - } - catch (Exception ex) - { - Logger.Error?.Print(LogClass.Application, $"Failed to purge shader cache for {application.Name}({application.IdString}): {ex}"); - hasErrors = true; - } - } - } - - if (hasErrors) - { - await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogDeleteAllCachesErrorMessage]); - } - } } }