config.tab

This commit is contained in:
rfi
2023-10-07 07:44:06 +07:00
parent 859e3fa042
commit 212d08496c
9 changed files with 206 additions and 3 deletions

View File

@@ -0,0 +1,56 @@
using AscNet.Common.Util;
namespace AscNet.SDKServer.Models
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public class RemoteConfig
{
[PropertyOrder(0)]
public string Key { get; set; }
[PropertyOrder(1)]
public string Type { get; set; }
[PropertyOrder(2)]
public string Value { get; set; }
}
public static class RemoteConfigExtension
{
public static void AddConfig<T>(this List<RemoteConfig> remoteConfigs, string key, T value)
{
if (!typeMap.TryGetValue(typeof(T), out string? typeStr) || value is null)
throw new ArgumentException("Unsupported value!", nameof(value));
RemoteConfig remoteConfig = new()
{
Key = key,
Type = typeStr
};
switch (typeStr)
{
case "int":
case "float":
case "string":
remoteConfig.Value = value.ToString() ?? "";
break;
case "bool":
remoteConfig.Value = value.ToString() == "True" ? "1" : "0";
break;
default:
break;
}
remoteConfigs.Add(remoteConfig);
}
private static Dictionary<Type, string> typeMap = new Dictionary<Type, string>
{
{ typeof(string), "string" },
{ typeof(int), "int" },
{ typeof(bool), "bool" },
{ typeof(float), "float" },
};
}
}

View File

@@ -0,0 +1,23 @@
using Newtonsoft.Json;
namespace AscNet.SDKServer.Models
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public class ServerVersionConfig
{
[JsonProperty("DocumentVersion", NullValueHandling = NullValueHandling.Ignore)]
public string DocumentVersion { get; set; }
[JsonProperty("LaunchModuleVersion", NullValueHandling = NullValueHandling.Ignore)]
public string LaunchModuleVersion { get; set; }
[JsonProperty("IndexMd5", NullValueHandling = NullValueHandling.Ignore)]
public string IndexMd5 { get; set; }
[JsonProperty("IndexSha1", NullValueHandling = NullValueHandling.Ignore)]
public string IndexSha1 { get; set; }
[JsonProperty("LaunchIndexSha1", NullValueHandling = NullValueHandling.Ignore)]
public string LaunchIndexSha1 { get; set; }
}
}