From 55ef06e48404b4920ad91e27efff5d07eea2b33e Mon Sep 17 00:00:00 2001 From: timerix Date: Mon, 26 Sep 2022 01:45:56 +0600 Subject: [PATCH] UpdateByDefault improvements --- DTLib.Dtsod/DtsodConverter.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/DTLib.Dtsod/DtsodConverter.cs b/DTLib.Dtsod/DtsodConverter.cs index 63552f5..c45cf56 100644 --- a/DTLib.Dtsod/DtsodConverter.cs +++ b/DTLib.Dtsod/DtsodConverter.cs @@ -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 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 updated.Add(p.Key,oldValue); + 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 + { + Log("y", $"<{keyWithContext}> new: {p.Value}"); + updated.Add(p.Key,p.Value); } - else updated.Add(p.Key,p.Value); } return updated;