mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: WpfGui清空缓存按钮 (#15582)
* feat: 清空缓存按钮 * feat: 排除asst.log和gui.log * i18n: EN * i18n: KR * i18n: zh-tw --------- Co-authored-by: Constrat <56174894+Constrat@users.noreply.github.com> Co-authored-by: HX3N <scarlet7518@gmail.com> Co-authored-by: HY <45387477+momomochi987@users.noreply.github.com>
This commit is contained in:
@@ -1288,6 +1288,10 @@ Before use, please ensure:
|
||||
<system:String x:Key="OpenDebugFolder">Open Debug Folder</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadSuccessful">Support payload generated successfully</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadException">An error occurred while generating the support payload:</system:String>
|
||||
<system:String x:Key="ClearCache">Clear Cache</system:String>
|
||||
<system:String x:Key="ClearCacheSuccessful">Cache cleared successfully</system:String>
|
||||
<system:String x:Key="ClearCacheAlreadyEmpty">Cache directories are already empty</system:String>
|
||||
<system:String x:Key="ClearCacheException">An error occurred while clearing cache: </system:String>
|
||||
<!-- !Issues -->
|
||||
<!-- AutoRecruitSettings -->
|
||||
<system:String x:Key="AutoRefresh">Auto refresh 3★ Tags</system:String>
|
||||
|
||||
@@ -1289,6 +1289,10 @@ MAA Team の開発リソースが限られているため、PC 対応は専任
|
||||
<system:String x:Key="OpenDebugFolder">デバッグフォルダーを開く</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadSuccessful">サポート用ZIPの生成に成功しました</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadException">サポート用ZIPの生成中にエラーが発生しました:</system:String>
|
||||
<system:String x:Key="ClearCache">キャッシュをクリア</system:String>
|
||||
<system:String x:Key="ClearCacheSuccessful">キャッシュをクリアしました</system:String>
|
||||
<system:String x:Key="ClearCacheAlreadyEmpty">キャッシュディレクトリは既に空です</system:String>
|
||||
<system:String x:Key="ClearCacheException">キャッシュのクリア中にエラーが発生しました:</system:String>
|
||||
<!-- !Issues -->
|
||||
<!-- 自動募集設定 -->
|
||||
<system:String x:Key="AutoRefresh">星3タグを自動的に更新する</system:String>
|
||||
|
||||
@@ -1290,6 +1290,10 @@ MAA Team의 개발 인력이 제한되어 있어 PC 지원은 전담 관리가
|
||||
<system:String x:Key="OpenDebugFolder">로그 폴더 열기</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadSuccessful">압축 파일 생성 성공</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadException">압축 파일 생성 중 오류가 발생했습니다:</system:String>
|
||||
<system:String x:Key="ClearCache">캐시 비우기</system:String>
|
||||
<system:String x:Key="ClearCacheSuccessful">캐시 비우기 성공</system:String>
|
||||
<system:String x:Key="ClearCacheAlreadyEmpty">캐시 폴더가 이미 비어 있음</system:String>
|
||||
<system:String x:Key="ClearCacheException">캐시 비우기 중 오류가 발생했습니다:</system:String>
|
||||
<!-- !Issues -->
|
||||
<!-- AutoRecruitSettings -->
|
||||
<system:String x:Key="AutoRefresh">★3 태그 자동 새로고침</system:String>
|
||||
|
||||
@@ -1289,6 +1289,10 @@ C:\\leidian\\LDPlayer9。\n
|
||||
<system:String x:Key="OpenDebugFolder">打开日志文件夹</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadSuccessful">生成压缩包成功</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadException">生成压缩包时出现问题:</system:String>
|
||||
<system:String x:Key="ClearCache">清空缓存</system:String>
|
||||
<system:String x:Key="ClearCacheSuccessful">缓存已清空</system:String>
|
||||
<system:String x:Key="ClearCacheAlreadyEmpty">缓存目录为空</system:String>
|
||||
<system:String x:Key="ClearCacheException">清空缓存时出现问题:</system:String>
|
||||
<!-- !Issues -->
|
||||
<!-- AutoRecruitSettings -->
|
||||
<system:String x:Key="AutoRefresh">自动刷新 3 星 Tags</system:String>
|
||||
|
||||
@@ -1289,6 +1289,10 @@ C:\\leidian\\LDPlayer9\n
|
||||
<system:String x:Key="OpenDebugFolder">打開紀錄資料夾</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadSuccessful">壓縮檔產生成功</system:String>
|
||||
<system:String x:Key="GenerateSupportPayloadException">產生壓縮檔時發生問題:</system:String>
|
||||
<system:String x:Key="ClearCache">清空快取</system:String>
|
||||
<system:String x:Key="ClearCacheSuccessful">快取已清空</system:String>
|
||||
<system:String x:Key="ClearCacheAlreadyEmpty">快取內容為空</system:String>
|
||||
<system:String x:Key="ClearCacheException">清空快取時發生錯誤:</system:String>
|
||||
<!-- !Issues -->
|
||||
<!-- AutoRecruitSettings -->
|
||||
<system:String x:Key="AutoRefresh">自動刷新 3★ Tags</system:String>
|
||||
|
||||
@@ -76,6 +76,43 @@ 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>
|
||||
@@ -208,6 +245,28 @@ 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>
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -93,6 +94,13 @@
|
||||
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