this took soo long, but here you are wells

This commit is contained in:
rfi
2024-02-22 16:11:23 +07:00
parent 5d39e1c6be
commit db93c8f49d
18 changed files with 1210 additions and 17 deletions

View File

@@ -1,12 +1,14 @@
using System.Text.Json;
using System.Text.RegularExpressions;
namespace BLHX.Server.Common.Data;
public static class JSON
public static partial class JSON
{
public static JsonSerializerOptions serializerOptions = new() { IncludeFields = true, WriteIndented = true };
public static string ConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
public static string ShareConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\sharecfgdata\\");
public static string ShareCfgDataPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/sharecfgdata/");
public static string ShareCfgPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/ShareCfg/");
public static T Load<T>(string path, bool create = true) where T : new()
{
@@ -16,7 +18,13 @@ public static class JSON
Save(path, obj);
}
return JsonSerializer.Deserialize<T>(File.ReadAllText(path), serializerOptions) ?? new T();
string text = File.ReadAllText(path);
if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Dictionary<,>) && typeof(T).GetGenericArguments()[0] == typeof(int))
{
text = DictKeyAll().Replace(text, "");
}
return JsonSerializer.Deserialize<T>(text, serializerOptions) ?? new T();
}
public static void Save<T>(string path, T obj)
@@ -28,4 +36,7 @@ public static class JSON
{
return JsonSerializer.Serialize(obj, serializerOptions);
}
[GeneratedRegex(@",[\n\s\t]+?""all"":[\s\S]+?]", RegexOptions.Multiline)]
public static partial Regex DictKeyAll();
}