From 67d73e8e2e6bcce679f854b30edbf27df55bae1a Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 9 Feb 2026 23:43:26 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"perf:=20=E6=B8=85=E7=A9=BA=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=A7=BB=E5=8A=A8=E5=88=B0=E7=95=8C=E9=9D=A2=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit bfa2ab4e93bad22ba5f08a5d0559b2b5fc58524a. --- .../Settings/GuiSettingsUserControlModel.cs | 74 ------------------- .../Settings/IssueReportUserControlModel.cs | 59 +++++++++++++++ .../Settings/GuiSettingsUserControl.xaml | 7 +- .../Settings/IssueReportUserControl.xaml | 8 ++ 4 files changed, 68 insertions(+), 80 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs index ad3db4212b..390b44d53f 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs @@ -14,18 +14,14 @@ #nullable enable using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Windows; -using HandyControl.Controls; -using HandyControl.Data; using MaaWpfGui.Configuration.Factory; using MaaWpfGui.Constants; using MaaWpfGui.Helper; using MaaWpfGui.Main; using MaaWpfGui.Utilities.ValueType; using MaaWpfGui.ViewModels.UI; -using Serilog; using Stylet; using DarkModeType = MaaWpfGui.Configuration.Global.GUI.DarkModeType; @@ -527,74 +523,4 @@ public class GuiSettingsUserControlModel : PropertyChangedBase } } } - - /// - /// 清空缓存 包括cache目录和debug目录 - /// - public static void ClearCache() - { - try - { - var clearedDirs = new List(); - - if (Directory.Exists(PathsHelper.CacheDir)) - { - Directory.Delete(PathsHelper.CacheDir, recursive: true); - clearedDirs.Add("cache"); - } - - if (Directory.Exists(PathsHelper.DebugDir)) - { - DeleteDirectoryContentsExcept(PathsHelper.DebugDir, ["asst.log", "asst.bak.log", "gui.log", "gui.bak.log"]); - clearedDirs.Add("debug"); - } - - if (clearedDirs.Count > 0) - { - ShowGrowl(LocalizationHelper.GetString("ClearCacheSuccessful")); - } - else - { - ShowGrowl(LocalizationHelper.GetString("ClearCacheAlreadyEmpty")); - } - } - catch (Exception ex) - { - ShowGrowl($"{LocalizationHelper.GetString("ClearCacheException")}\n{ex.Message}"); - Log.Error(ex, "Failed to clear cache"); - } - - void ShowGrowl(string message) - { - var growlInfo = new GrowlInfo { - IsCustom = true, - Message = message, - IconKey = "HangoverGeometry", - IconBrushKey = "PallasBrush", - }; - Growl.Info(growlInfo); - } - } - - /// - /// 删除目录下的所有文件和子目录,排除指定的文件名。 - /// - private static void DeleteDirectoryContentsExcept(string dir, IEnumerable excludeFileNames) - { - var excludeSet = excludeFileNames.ToHashSet(StringComparer.OrdinalIgnoreCase); - foreach (var file in Directory.EnumerateFiles(dir)) - { - if (excludeSet.Contains(Path.GetFileName(file))) - { - continue; - } - - File.Delete(file); - } - - foreach (var subDir in Directory.EnumerateDirectories(dir)) - { - Directory.Delete(subDir, recursive: true); - } - } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs index 63761016b3..a16519b5af 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs @@ -76,6 +76,43 @@ public class IssueReportUserControlModel : PropertyChangedBase } } + /// + /// 清空缓存 包括cache目录和debug目录 + /// + public void ClearCache() + { + try + { + var clearedDirs = new List(); + + if (Directory.Exists(PathsHelper.CacheDir)) + { + Directory.Delete(PathsHelper.CacheDir, recursive: true); + clearedDirs.Add("cache"); + } + + if (Directory.Exists(PathsHelper.DebugDir)) + { + DeleteDirectoryContentsExcept(PathsHelper.DebugDir, ["asst.log", "gui.log"]); + clearedDirs.Add("debug"); + } + + if (clearedDirs.Count > 0) + { + ShowGrowl(LocalizationHelper.GetString("ClearCacheSuccessful")); + } + else + { + ShowGrowl(LocalizationHelper.GetString("ClearCacheAlreadyEmpty")); + } + } + catch (Exception ex) + { + ShowGrowl($"{LocalizationHelper.GetString("ClearCacheException")}\n{ex.Message}"); + Log.Error(ex, "Failed to clear cache"); + } + } + /// /// 生成日志压缩包 /// @@ -208,6 +245,28 @@ public class IssueReportUserControlModel : PropertyChangedBase } } + /// + /// 删除目录下的所有文件和子目录,排除指定的文件名。 + /// + private static void DeleteDirectoryContentsExcept(string dir, IEnumerable excludeFileNames) + { + var excludeSet = excludeFileNames.ToHashSet(StringComparer.OrdinalIgnoreCase); + foreach (var file in Directory.EnumerateFiles(dir)) + { + if (excludeSet.Contains(Path.GetFileName(file))) + { + continue; + } + + File.Delete(file); + } + + foreach (var subDir in Directory.EnumerateDirectories(dir)) + { + Directory.Delete(subDir, recursive: true); + } + } + /// /// 从 sourceDir 复制文件到 targetDir,支持过滤。 /// diff --git a/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml index b5cf8581df..ac76ef908e 100644 --- a/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml @@ -13,6 +13,7 @@ xmlns:settings_vms="clr-namespace:MaaWpfGui.ViewModels.UserControl.Settings" d:Background="White" d:DataContext="{d:DesignInstance {x:Type settings_vms:GuiSettingsUserControlModel}}" + d:DesignHeight="350" d:DesignWidth="550" s:View.ActionTarget="{Binding}" mc:Ignorable="d"> @@ -151,12 +152,6 @@ DisplayMemberPath="Value" ItemsSource="{Binding WindowTitleAllShowDict}" /> -