迁移部分常用路径

This commit is contained in:
龙腾猫跃 committed 2026-06-18 21:43:27 +08:00
1 parent e9cd356f2b
commit 966b2db312
5 files changed
+27 -11

No files matched your search

+1 -1
View File
@@ -291,7 +291,7 @@ public class BaseLogger {
/// </summary>
public class FileLogger : BaseLogger, IDisposable {
public string logFolder = Path.Combine(PathUtils.CurrentFolder, "logs");
public string logFolder = Path.Combine(Paths.Base, "logs");
public string fileNamePrefix = "Log";
public string fileNameSuffix = ".txt";
private StreamWriter? writer;
+3 -1
View File
@@ -1,7 +1,9 @@
namespace MeloongCore;
public static class Main {
public static void Init(BaseLogger? logger = null) {
public static string AppName = "Meloong";
public static void Init(string appName, BaseLogger? logger = null) {
AppName = appName;
AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(5));
if (logger != null) Logger.Instance = logger;
}
+1 -1
View File
@@ -173,7 +173,7 @@ public static class DirectoryUtils {
throw new UnauthorizedAccessException($"不应操作文件夹:{folder}");
}
private static readonly Lazy<HashSet<string>> criticalFolders = new(() => new(new[] {
PathUtils.CurrentFolder,
Paths.Base,
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
+20 -6
View File
@@ -173,13 +173,27 @@ public static class PathUtils {
#endregion
#region 常用路径
}
/// <summary>
/// 程序可执行文件的所在文件夹,以 \ 结尾。
/// 常用路径合集。
/// 所有路径均以分隔符结尾。
/// </summary>
public static string CurrentFolder => PathUtils.AddSlashSuffix(AppDomain.CurrentDomain.BaseDirectory);
#endregion
public static class Paths {
/// <summary>
/// 可执行文件所在的文件夹。
/// </summary>
public static string Base => PathUtils.AddSlashSuffix(AppContext.BaseDirectory);
/// <summary>
/// 可执行文件所在的文件夹中,名为 <see cref="Main.AppName"/> 的子文件夹。
/// </summary>
public static string BaseThenName => PathUtils.AddSlashSuffix(Base + Main.AppName);
/// <summary>
/// %AppData% 文件夹。
/// </summary>
public static string AppData => PathUtils.AddSlashSuffix(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
/// <summary>
/// %AppData% 文件夹中,名为 <see cref="Main.AppName"/> 的子文件夹。
/// </summary>
public static string AppDataThenName => PathUtils.AddSlashSuffix(AppData + Main.AppName);
}
+2 -2
View File
@@ -7,7 +7,7 @@
public abstract class TestBase {
public TestBase() {
MeloongCore.Main.Init(new TestLogger());
MeloongCore.Main.Init("MeloongCoreTest", new TestLogger());
}
private class TestLogger : BaseLogger {
public override void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex)
@@ -40,7 +40,7 @@ public abstract class TestWithFolder : TestBase {
/// 输出指定的测试用文件,返回文件路径。
/// </summary>
public string GetTestFile(string fileName) {
var sourceFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", GetType().Name.Replace("Test", ""), fileName);
var sourceFilePath = Path.Combine(Paths.Base, "TestFiles", GetType().Name.Replace("Test", ""), fileName);
var distPath = Path.Combine(tempFolder, PathUtils.GetLastPart(sourceFilePath));
FileUtils.Copy(sourceFilePath, distPath);
return distPath;