From 36ecaf29b62abdf4d637b93de8535badc528f146 Mon Sep 17 00:00:00 2001 From: LTCat <1043137532@qq.com> Date: Sat, 26 Sep 2026 01:28:01 +0800 Subject: [PATCH] =?UTF-8?q?FileUtils.Move=20=E6=B7=BB=E5=8A=A0=20toRecycle?= =?UTF-8?q?Bin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Utils/FileUtils.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Shared/Utils/FileUtils.cs b/Shared/Utils/FileUtils.cs index dfd3392..38b05bc 100644 --- a/Shared/Utils/FileUtils.cs +++ b/Shared/Utils/FileUtils.cs @@ -205,8 +205,9 @@ public static class FileUtils { /// /// 剪切文件。 /// 会创建对应文件夹、覆盖已有的文件。 + /// 若指定了 ,则在覆盖前将老文件删除到回收站。 /// - public static void Move(string sourceFilePath, string destFilePath) { + public static void Move(string sourceFilePath, string destFilePath, bool toRecycleBin = false) { sourceFilePath = PathUtils.ForCompare(sourceFilePath); destFilePath = PathUtils.ForCompare(destFilePath); if (string.CompareOrdinal(sourceFilePath, destFilePath) == 0) { @@ -225,7 +226,7 @@ public static class FileUtils { } else { // 实际的剪切 DirectoryUtils.Create(PathUtils.RemoveLastPart(destFilePath)); - FileUtils.Delete(destFilePath); + FileUtils.Delete(destFilePath, toRecycleBin); Logger.Trace($"剪切文件:{sourceFilePath} → {destFilePath}"); Retrier.Attempt(delay: _ => TimeSpan.FromMilliseconds(200), isRetryAllowed: ex => ex is IOException, action: _ => { FileUtils.SetReadOnly(sourceFilePath, false); @@ -510,7 +511,8 @@ public class FileChecker { /// 是否要求为 JSON 文件。 /// public bool IsJson = false; - + + // TODO: 重构此函数,使它变成 void,并抛出异常 /// /// 检查文件。 /// 若成功则返回 null,失败则返回错误的描述文本(文本不以句号结尾)。