更新框架
This commit is contained in:
1 parent
ef50fa0620
commit
84b28f9672
72 files changed
+2222
-282
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using MAX.Framework.Interfaces;
|
||||
using System.IO;
|
||||
|
||||
namespace Store.Management.Framework.Configs;
|
||||
|
||||
/// <summary>应用目录约定。路径读取不创建目录,保存配置时自动创建所需目录。</summary>
|
||||
public sealed class FolderConfig : IFolderConfig
|
||||
{
|
||||
/// <summary>供启动配置使用;容器也可通过 IFolderConfig 解析目录配置。</summary>
|
||||
public static FolderConfig Instance { get; } = new();
|
||||
|
||||
public FolderConfig() { }
|
||||
|
||||
string IFolderConfig.ConfigFolder => ConfigFolder;
|
||||
string IFolderConfig.DataFolder => DataFolder;
|
||||
string IFolderConfig.LoggingFolder => LoggingFolder;
|
||||
string IFolderConfig.CacheFolder => CacheFolder;
|
||||
|
||||
public const string AppName = "Store.Management";
|
||||
|
||||
/// <summary>安装目录,用于读取随程序分发的资源。</summary>
|
||||
public static string ExeFolder => AppContext.BaseDirectory;
|
||||
|
||||
/// <summary>当前用户的数据根目录:%LOCALAPPDATA%\Store.Management。</summary>
|
||||
public static string AppFolder => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName);
|
||||
|
||||
public static string ConfigFolder => Path.Combine(AppFolder, "Config");
|
||||
public static string DataFolder => Path.Combine(AppFolder, "Data");
|
||||
public static string LoggingFolder => Path.Combine(AppFolder, "Logs");
|
||||
public static string DatabaseFolder => Path.Combine(AppFolder, "Db");
|
||||
public static string CacheFolder => Path.Combine(AppFolder, "Cache");
|
||||
public static string AppSettingsFilePath => GetSettingsFilePath("AppSettings.json");
|
||||
|
||||
/// <summary>获取配置文件路径,仅接受文件名,防止写出配置目录。</summary>
|
||||
public static string GetSettingsFilePath(string fileName)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(fileName);
|
||||
if (fileName is "." or ".." || fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0
|
||||
|| fileName.EndsWith('.') || fileName.EndsWith(' '))
|
||||
throw new ArgumentException("配置文件名不能包含路径、非法字符或以点、空格结尾。", nameof(fileName));
|
||||
return Path.Combine(ConfigFolder, fileName);
|
||||
}
|
||||
|
||||
/// <summary>按需在宿主启动时创建应用目录;创建失败向调用者报告。</summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
foreach (string path in new[] { ConfigFolder, DataFolder, LoggingFolder, DatabaseFolder, CacheFolder })
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user