Code Review

This commit is contained in:
龙腾猫跃 committed 2026-05-07 08:46:48 +08:00
1 parent be6336f548
commit 9158a69b62
11 files changed
+103 -65

No files matched your search

+2 -2
View File
@@ -59,7 +59,7 @@ public static class DirectoryUtils {
/// </summary>
public static void Move(string sourceDirName, string destDirName) {
if (!Exists(sourceDirName)) return;
Create(destDirName);
DirectoryUtils.Delete(destDirName); // Move 要求不存在对应文件夹
Logger.Trace($"剪切文件夹:{sourceDirName} → {destDirName}");
Directory.Move(PathUtils.WithLongPath(sourceDirName), PathUtils.WithLongPath(destDirName));
}
@@ -73,7 +73,7 @@ public static class DirectoryUtils {
if (toRecycleBin) {
FileUtils.DeleteToRecycleBin(dirPath);
} else {
Directory.Delete(PathUtils.WithLongPath(dirPath));
Directory.Delete(PathUtils.WithLongPath(dirPath), recursive:true);
}
}
}
+9 -9
View File
@@ -4,7 +4,7 @@ namespace MeloongCore;
public static class EscapeUtils {
/// <summary>
/// XML 转义。
/// WPF XML 转义。
/// </summary>
public static string? XmlEscape(string? str) {
if (str is null) return null;
@@ -34,7 +34,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="Regex.Escape"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? RegexEscape(string? value)
public static string? RegexEscape(string value)
=> Regex.Escape(value);
/// <summary>
@@ -42,7 +42,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="Regex.Unescape"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? RegexUnescape(string? value)
public static string? RegexUnescape(string value)
=> Regex.Unescape(value);
/// <summary>
@@ -50,7 +50,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="Uri.EscapeDataString"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? UrlEscape(string? value)
public static string? UrlEscape(string value)
=> Uri.EscapeDataString(value);
/// <summary>
@@ -58,7 +58,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="Uri.UnescapeDataString"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? UrlUnescape(string? value)
public static string? UrlUnescape(string value)
=> Uri.UnescapeDataString(value);
/// <summary>
@@ -66,7 +66,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="WebUtility.UrlEncode"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? FormUrlEscape(string? value)
public static string? FormUrlEscape(string value)
=> WebUtility.UrlEncode(value);
/// <summary>
@@ -74,7 +74,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="WebUtility.UrlDecode"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? FormUrlUnescape(string? value)
public static string? FormUrlUnescape(string value)
=> WebUtility.UrlDecode(value);
/// <summary>
@@ -82,7 +82,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="WebUtility.HtmlEncode"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? HtmlEscape(string? value)
public static string? HtmlEscape(string value)
=> WebUtility.HtmlEncode(value);
/// <summary>
@@ -90,7 +90,7 @@ public static class EscapeUtils {
/// 等同于 <see cref="WebUtility.HtmlDecode"/>。
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? HtmlUnescape(string? value)
public static string? HtmlUnescape(string value)
=> WebUtility.HtmlDecode(value);
}
+3 -2
View File
@@ -37,7 +37,7 @@ public static class FileUtils {
public static void Write(string filePath, Stream stream) {
using FileStream fileStream = CreateAsStream(PathUtils.WithLongPath(filePath));
if (stream.CanSeek && stream.Position != 0) stream.Seek(0, SeekOrigin.Begin);
Logger.Trace(() => $"写入文件:{filePath}({stream.GetType().Name} {stream.Length} 字节)");
Logger.Trace(() => $"写入文件:{filePath}({stream.GetType().Name}{(stream.CanSeek ? $" {stream.Length} 字节" : "")})");
stream.CopyTo(fileStream);
}
@@ -49,7 +49,7 @@ public static class FileUtils {
/// 删除文件。
/// </summary>
public static void Delete(string filePath, bool toRecycleBin = false) {
if (!Exists(filePath)) return;
if (!FileUtils.Exists(filePath)) return;
Logger.Trace($"{(toRecycleBin ? "将文件删除到回收站" : "删除文件")}:{filePath}");
if (toRecycleBin) {
DeleteToRecycleBin(filePath);
@@ -284,6 +284,7 @@ public static class FileUtils {
public static void Move(string sourceFilePath, string destFilePath) {
if (sourceFilePath == destFilePath) return; // 如果移动同一个文件则跳过
DirectoryUtils.Create(destFilePath, isFilePath: true);
FileUtils.Delete(destFilePath);
Logger.Trace($"剪切文件:{sourceFilePath} → {destFilePath}");
File.Move(PathUtils.WithLongPath(sourceFilePath), PathUtils.WithLongPath(destFilePath));
}
+1 -1
View File
@@ -7,7 +7,7 @@ public class HttpRequestCodeException(string message, HttpStatusCode statusCode,
/// <summary>
/// HTTP 请求的状态码。
/// </summary>
public HttpStatusCode StatusCode = statusCode;
public HttpStatusCode StatusCode { get; set; } = statusCode;
/// <summary>
/// 远程服务器给予的回复。
/// </summary>
+3 -1
View File
@@ -91,10 +91,12 @@ public static class MathUtils {
if (t > 0.9999999) return 1;
double a = t;
double b;
int maxIterations = 1000;
do {
b = 3 * a * ((0.33333333 + x1 - x2) * a * a + (x2 - 2 * x1) * a + x1);
a += (t - b) * 0.5;
} while (!(Math.Abs(b - t) < accuracy)); // 精度
maxIterations--;
} while (!(Math.Abs(b - t) < accuracy) && maxIterations > 0);
return 3 * a * ((0.33333333 + y1 - y2) * a * a + (y2 - 2 * y1) * a + y1);
}
+5 -2
View File
@@ -74,8 +74,11 @@ public static class PathUtils {
/// <summary>
/// 去除路径开头的 <c>\\?\</c>。
/// </summary>
public static string WithoutLongPath(string path)
=> path.AfterLast(@"\\?\");
public static string WithoutLongPath(string path) {
if (path.StartsWithF(@"\\?\UNC\")) return @"\\" + path.AfterLast(@"\\?\UNC\");
if (path.StartsWithF(@"\\?\")) return path.AfterLast(@"\\?\");
return path;
}
#endregion