mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-12 22:44:36 +01:00
JSON data table parsing stuff
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
namespace BLHX.Server.Common.Utils;
|
||||
|
||||
public class Config : Singleton<Config>
|
||||
{
|
||||
public string Address { get; set; } = "127.0.0.1";
|
||||
public uint Port { get; set; } = 20000;
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
Instance = JSON.Load<Config>(JSON.ConfigPath);
|
||||
|
||||
#if DEBUG
|
||||
Logger.c.Log($"Loaded Config:\n{JSON.Stringify(Instance)}");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
JSON.Save(JSON.ConfigPath, Instance);
|
||||
|
||||
#if DEBUG
|
||||
Logger.c.Log("Saved Config");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BLHX.Server.Common.Utils;
|
||||
|
||||
public static class JSON
|
||||
{
|
||||
public static string ConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
|
||||
|
||||
public static T Load<T>(string path) where T : new()
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
T obj = new T();
|
||||
Save(path, obj);
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<T>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
public static void Save<T>(string path, T obj)
|
||||
{
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(obj, new JsonSerializerOptions()
|
||||
{
|
||||
WriteIndented = true
|
||||
}));
|
||||
}
|
||||
|
||||
public static string Stringify<T>(T obj)
|
||||
{
|
||||
return JsonSerializer.Serialize(obj, new JsonSerializerOptions()
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user