mirror of
https://github.com/Megghy/MegghysAPI.git
synced 2025-12-06 22:26:56 +08:00
添加项目文件。
This commit is contained in:
67
Config.cs
Normal file
67
Config.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Unicode;
|
||||
|
||||
namespace MegghysAPI
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static readonly JsonSerializerOptions DefaultSerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
||||
};
|
||||
private static Config _oldInstance = new();
|
||||
private static Config? _instance;
|
||||
public static Config Instance { get { _instance ??= Load(); return _instance; } }
|
||||
public static string ConfigPath => Path.Combine(Datas.DataPath, "Config.json");
|
||||
static bool _first = true;
|
||||
public static Config Load()
|
||||
{
|
||||
if (File.Exists(ConfigPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigPath))!;
|
||||
_oldInstance = config;
|
||||
if (_first)
|
||||
config.Save();
|
||||
return _oldInstance;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"配置文件读取失败");
|
||||
return _oldInstance!;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var config = new Config();
|
||||
config.Save();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
public static void Reload()
|
||||
{
|
||||
_oldInstance = _instance;
|
||||
_instance = null;
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
if (!Directory.Exists(Datas.DataPath))
|
||||
Directory.CreateDirectory(Datas.DataPath);
|
||||
File.WriteAllText(ConfigPath, JsonSerializer.Serialize(this, DefaultSerializerOptions));
|
||||
}
|
||||
|
||||
|
||||
public bool LogDanmakuError { get; set; } = false;
|
||||
public string ListenHost { get; set; } = "*";
|
||||
public int ListenPort { get; set; } = 4050;
|
||||
public string DBConnectString { get; set; } = $"Host=localhost;Port=5432;Username=postgres;Password=!Hzy05152484; Database=MegghysAPI;";
|
||||
public string MinIOEndpoint { get; set; } = "eternalland.top:9000";
|
||||
public string MinIOAccessKey { get; set; } = "RBzbElm21lf7sy7wK7wG";
|
||||
public string MinIOSecretKey { get; set; } = "Nko5azOSUiYgOUeLsj8hLxGz4cKC8XOcH0VS7lWq";
|
||||
public string MinIORegion { get; set; } = "cn-main";
|
||||
public string MinIOBucket { get; set; } = "general";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user