迁移部分常用路径
This commit is contained in:
1 parent
e9cd356f2b
commit
966b2db312
5 files changed
+27
-11
No files matched your search
@@ -291,7 +291,7 @@ public class BaseLogger {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileLogger : BaseLogger, IDisposable {
|
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 fileNamePrefix = "Log";
|
||||||
public string fileNameSuffix = ".txt";
|
public string fileNameSuffix = ".txt";
|
||||||
private StreamWriter? writer;
|
private StreamWriter? writer;
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
namespace MeloongCore;
|
namespace MeloongCore;
|
||||||
public static class Main {
|
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));
|
AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(5));
|
||||||
if (logger != null) Logger.Instance = logger;
|
if (logger != null) Logger.Instance = logger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public static class DirectoryUtils {
|
|||||||
throw new UnauthorizedAccessException($"不应操作文件夹:{folder}");
|
throw new UnauthorizedAccessException($"不应操作文件夹:{folder}");
|
||||||
}
|
}
|
||||||
private static readonly Lazy<HashSet<string>> criticalFolders = new(() => new(new[] {
|
private static readonly Lazy<HashSet<string>> criticalFolders = new(() => new(new[] {
|
||||||
PathUtils.CurrentFolder,
|
Paths.Base,
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
||||||
|
|||||||
@@ -173,13 +173,27 @@ public static class PathUtils {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 常用路径
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 常用路径合集。
|
||||||
|
/// 所有路径均以分隔符结尾。
|
||||||
|
/// </summary>
|
||||||
|
public static class Paths {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 程序可执行文件的所在文件夹,以 \ 结尾。
|
/// 可执行文件所在的文件夹。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string CurrentFolder => PathUtils.AddSlashSuffix(AppDomain.CurrentDomain.BaseDirectory);
|
public static string Base => PathUtils.AddSlashSuffix(AppContext.BaseDirectory);
|
||||||
|
/// <summary>
|
||||||
#endregion
|
/// 可执行文件所在的文件夹中,名为 <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
@@ -7,7 +7,7 @@
|
|||||||
public abstract class TestBase {
|
public abstract class TestBase {
|
||||||
|
|
||||||
public TestBase() {
|
public TestBase() {
|
||||||
MeloongCore.Main.Init(new TestLogger());
|
MeloongCore.Main.Init("MeloongCoreTest", new TestLogger());
|
||||||
}
|
}
|
||||||
private class TestLogger : BaseLogger {
|
private class TestLogger : BaseLogger {
|
||||||
public override void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex)
|
public override void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex)
|
||||||
@@ -40,7 +40,7 @@ public abstract class TestWithFolder : TestBase {
|
|||||||
/// 输出指定的测试用文件,返回文件路径。
|
/// 输出指定的测试用文件,返回文件路径。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetTestFile(string fileName) {
|
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));
|
var distPath = Path.Combine(tempFolder, PathUtils.GetLastPart(sourceFilePath));
|
||||||
FileUtils.Copy(sourceFilePath, distPath);
|
FileUtils.Copy(sourceFilePath, distPath);
|
||||||
return distPath;
|
return distPath;
|
||||||
|
|||||||
Reference in new issue
Block a user