迁移部分常用路径
This commit is contained in:
1 parent
e9cd356f2b
commit
966b2db312
5 files changed
+30
-14
No files matched your search
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -173,13 +173,27 @@ public static class PathUtils {
|
||||
|
||||
#endregion
|
||||
|
||||
#region 常用路径
|
||||
|
||||
/// <summary>
|
||||
/// 程序可执行文件的所在文件夹,以 \ 结尾。
|
||||
/// </summary>
|
||||
public static string CurrentFolder => PathUtils.AddSlashSuffix(AppDomain.CurrentDomain.BaseDirectory);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 常用路径合集。
|
||||
/// 所有路径均以分隔符结尾。
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user