From bfa2ab4e93bad22ba5f08a5d0559b2b5fc58524a Mon Sep 17 00:00:00 2001
From: status102 <102887808+status102@users.noreply.github.com>
Date: Thu, 5 Feb 2026 15:56:18 +0800
Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B8=85=E7=A9=BA=E7=BC=93=E5=AD=98?=
=?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E7=95=8C=E9=9D=A2=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Settings/GuiSettingsUserControlModel.cs | 74 +++++++++++++++++++
.../Settings/IssueReportUserControlModel.cs | 59 ---------------
.../Settings/GuiSettingsUserControl.xaml | 7 +-
.../Settings/IssueReportUserControl.xaml | 8 --
4 files changed, 80 insertions(+), 68 deletions(-)
diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs
index 390b44d53f..ad3db4212b 100644
--- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs
+++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs
@@ -14,14 +14,18 @@
#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;
@@ -523,4 +527,74 @@ 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 a16519b5af..63761016b3 100644
--- a/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs
+++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs
@@ -76,43 +76,6 @@ 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");
- }
- }
-
///
/// 生成日志压缩包
///
@@ -245,28 +208,6 @@ 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 ac76ef908e..b5cf8581df 100644
--- a/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml
+++ b/src/MaaWpfGui/Views/UserControl/Settings/GuiSettingsUserControl.xaml
@@ -13,7 +13,6 @@
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">
@@ -152,6 +151,12 @@
DisplayMemberPath="Value"
ItemsSource="{Binding WindowTitleAllShowDict}" />
+
diff --git a/src/MaaWpfGui/Views/UserControl/Settings/IssueReportUserControl.xaml b/src/MaaWpfGui/Views/UserControl/Settings/IssueReportUserControl.xaml
index bc34b49023..f07a6a4863 100644
--- a/src/MaaWpfGui/Views/UserControl/Settings/IssueReportUserControl.xaml
+++ b/src/MaaWpfGui/Views/UserControl/Settings/IssueReportUserControl.xaml
@@ -45,7 +45,6 @@
-
@@ -94,13 +93,6 @@
Margin="5,2"
Command="{s:Action OpenDebugFolder}"
Content="{DynamicResource OpenDebugFolder}" />
-