mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
perf: 清空缓存移动到界面设置
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空缓存 包括cache目录和debug目录
|
||||
/// </summary>
|
||||
public static void ClearCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
var clearedDirs = new List<string>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除目录下的所有文件和子目录,排除指定的文件名。
|
||||
/// </summary>
|
||||
private static void DeleteDirectoryContentsExcept(string dir, IEnumerable<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,43 +76,6 @@ public class IssueReportUserControlModel : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空缓存 包括cache目录和debug目录
|
||||
/// </summary>
|
||||
public void ClearCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
var clearedDirs = new List<string>();
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成日志压缩包
|
||||
/// </summary>
|
||||
@@ -245,28 +208,6 @@ public class IssueReportUserControlModel : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除目录下的所有文件和子目录,排除指定的文件名。
|
||||
/// </summary>
|
||||
private static void DeleteDirectoryContentsExcept(string dir, IEnumerable<string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 sourceDir 复制文件到 targetDir,支持过滤。
|
||||
/// </summary>
|
||||
|
||||
@@ -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}" />
|
||||
</StackPanel>
|
||||
<Button
|
||||
Width="Auto"
|
||||
Margin="5,2"
|
||||
Command="{s:Action ClearCache,
|
||||
Target={x:Type settings_vms:GuiSettingsUserControlModel}}"
|
||||
Content="{DynamicResource ClearCache}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -94,13 +93,6 @@
|
||||
Margin="5,2"
|
||||
Command="{s:Action OpenDebugFolder}"
|
||||
Content="{DynamicResource OpenDebugFolder}" />
|
||||
<Button
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Width="Auto"
|
||||
Margin="5,2"
|
||||
Command="{s:Action ClearCache}"
|
||||
Content="{DynamicResource ClearCache}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user