Fixes bug with configurations (#236)
- [X] Changes brace style to enforced - [X] Fixes null source with assemblies.json - [X] Fixes bad path for missing json files Bumps release version
This commit is contained in:
parent
96465c8530
commit
c3d2740983
5 changed files with 88 additions and 27 deletions
|
|
@ -60,7 +60,9 @@ namespace Server
|
|||
public static string GetOrUpdateSetting(string key, string defaultValue)
|
||||
{
|
||||
if (m_Settings.settings.TryGetValue(key, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
SetSetting(key, value = defaultValue);
|
||||
return value;
|
||||
|
|
@ -71,9 +73,13 @@ namespace Server
|
|||
int value;
|
||||
|
||||
if (m_Settings.settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = int.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSetting(key, (value = defaultValue).ToString());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
@ -83,9 +89,13 @@ namespace Server
|
|||
bool value;
|
||||
|
||||
if (m_Settings.settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = bool.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSetting(key, (value = defaultValue).ToString());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
@ -95,9 +105,13 @@ namespace Server
|
|||
TimeSpan value;
|
||||
|
||||
if (m_Settings.settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = TimeSpan.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSetting(key, (value = defaultValue).ToString());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
@ -107,9 +121,13 @@ namespace Server
|
|||
T value;
|
||||
|
||||
if (m_Settings.settings.TryGetValue(key, out var strValue))
|
||||
{
|
||||
value = Enum.TryParse(strValue, out value) ? value : defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetSetting(key, (value = defaultValue).ToString());
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
@ -159,7 +177,9 @@ namespace Server
|
|||
}
|
||||
|
||||
if (mocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Settings.dataDirectories.Count == 0)
|
||||
{
|
||||
|
|
@ -198,7 +218,10 @@ namespace Server
|
|||
{
|
||||
Console.Write("{0}> ", directories.Count > 0 ? "[finish] " : " ");
|
||||
var directory = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(directory)) break;
|
||||
if (string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
|
|
@ -227,10 +250,15 @@ namespace Server
|
|||
// IP:Port?
|
||||
Console.Write("[{0}]> ", ips.Count > 0 ? "finish" : "0.0.0.0:2593");
|
||||
var ipStr = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(ipStr)) break;
|
||||
if (string.IsNullOrWhiteSpace(ipStr))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (ipStr.IndexOf(":", StringComparison.Ordinal) == -1)
|
||||
{
|
||||
ipStr += ":2593";
|
||||
}
|
||||
|
||||
if (IPEndPoint.TryParse(ipStr, out var ip))
|
||||
{
|
||||
|
|
@ -244,14 +272,19 @@ namespace Server
|
|||
} while (true);
|
||||
|
||||
if (ips.Count == 0)
|
||||
{
|
||||
ips.Add(new IPEndPoint(IPAddress.Any, 2593));
|
||||
}
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
if (m_Mocked) return;
|
||||
if (m_Mocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JsonConfig.Serialize(m_FilePath, m_Settings);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,21 +44,33 @@ namespace Server.Json
|
|||
options.Converters.Add(new NullableStructSerializerFactory());
|
||||
options.Converters.Add(new TypeConverterFactory());
|
||||
|
||||
for (var i = 0; i < converters.Length; i++) options.Converters.Add(converters[i]);
|
||||
for (var i = 0; i < converters.Length; i++)
|
||||
{
|
||||
options.Converters.Add(converters[i]);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(string filePath, JsonSerializerOptions options = null)
|
||||
{
|
||||
if (!File.Exists(filePath)) return default;
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
var text = File.ReadAllText(filePath, Utility.UTF8);
|
||||
return JsonSerializer.Deserialize<T>(text, options ?? DefaultOptions);
|
||||
}
|
||||
|
||||
public static void Serialize(string filePath, object value, JsonSerializerOptions options = null)
|
||||
{
|
||||
if (File.Exists(filePath)) File.Delete(filePath);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
|
||||
File.WriteAllText(filePath, JsonSerializer.Serialize(value, options ?? DefaultOptions));
|
||||
}
|
||||
|
|
@ -80,7 +92,10 @@ namespace Server.Json
|
|||
public static T ToObject<T>(this JsonDocument document, JsonSerializerOptions options = null)
|
||||
{
|
||||
if (document == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(document));
|
||||
}
|
||||
|
||||
return document.RootElement.ToObject<T>(options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace Server
|
|||
public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || IsFreeBSD;
|
||||
public static readonly bool Unix = IsDarwin || IsFreeBSD || IsLinux;
|
||||
|
||||
private static readonly string assembliesConfiguration = "Configuration/assemblies.json";
|
||||
private const string assembliesConfiguration = "Data/assemblies.json";
|
||||
|
||||
public static bool IsRunningFromXUnit =>
|
||||
m_IsRunningFromXUnit ??= AppDomain.CurrentDomain.GetAssemblies()
|
||||
|
|
@ -444,12 +444,13 @@ namespace Server
|
|||
|
||||
ServerConfiguration.Load();
|
||||
|
||||
var assemblyPath = Path.Join(BaseDirectory, assembliesConfiguration);
|
||||
|
||||
// Load UOContent.dll
|
||||
var assemblyFiles = JsonConfig.Deserialize<List<string>>(
|
||||
Path.Join(BaseDirectory, assembliesConfiguration)
|
||||
)
|
||||
var assemblyFiles = JsonConfig.Deserialize<List<string>>(assemblyPath)
|
||||
.Select(t => Path.Join(BaseDirectory, "Assemblies", t))
|
||||
.ToArray();
|
||||
|
||||
AssemblyHandler.LoadScripts(assemblyFiles);
|
||||
|
||||
VerifySerialization();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue