UpdateByDefault improvements

This commit is contained in:
timerix 2022-09-26 01:45:56 +06:00
parent 8fb9137d40
commit 55ef06e484

View File

@ -18,21 +18,40 @@ public static class DtsodConverter
};
// заменяет дефолтные значения на пользовательские
public static DtsodV23 UpdateByDefault(DtsodV23 old, DtsodV23 updatedDefault)
public static DtsodV23 UpdateByDefault(DtsodV23 old, DtsodV23 updatedDefault, string contextName="")
{
DtsodV23 updated = new();
foreach (KeyValuePair<string,dynamic> p in updatedDefault)
{
string keyWithContext=contextName+"."+p.Key;
if (old.TryGetValue(p.Key, out var oldValue))
{
if (oldValue.GetType() != p.Value.GetType())
throw new Exception(
"uncompatible config value type\n " +
$"launcher.dtsod: {p.Key}:{oldValue} is {oldValue.GetType()}, " +
$"<{keyWithContext}>: {oldValue} is {oldValue.GetType()}, " +
$"must be {p.Value.GetType()}");
else
{
if(oldValue!=p.Value)
Log("y", $"<{keyWithContext}> old: {oldValue} new: {p.Value}");
if(oldValue is DtsodV23){
var subdtsod=UpdateByDefault(oldValue, p.Value, keyWithContext);
updated.Add(p.Key,subdtsod);
}
else if(oldValue is IList)
{
Log("y", $"can't automatically update list <{keyWithContext}>, do it manually");
updated.Add(p.Key,oldValue);
}
else updated.Add(p.Key,oldValue);
}
else updated.Add(p.Key,p.Value);
}
else
{
Log("y", $"<{keyWithContext}> new: {p.Value}");
updated.Add(p.Key,p.Value);
}
}
return updated;