public static async Task <string> GetConfigJsonAsync(string configName) { using (var store = new TextStore()) { var cfgName = configName.ToLower(); var liveFile = StorageUtils.PathCombine(AppDataPath, $"{cfgName}{LiveFileExt}"); if (!File.Exists(liveFile)) { Logger.Log(LogLevel.Fatal, $"{cfgName}{LiveFileExt} is missing from {AppDataPath}"); throw new FileNotFoundException(); } var liveJson = await store.ReadAsync(liveFile); if (!IsDebug) { return(liveJson); } var debugFile = StorageUtils.PathCombine(AppDataPath, $"{cfgName}{DebugFileExt}"); if (!File.Exists(debugFile)) { Logger.Log(LogLevel.Warn, $"{cfgName}{DebugFileExt} is missing from {AppDataPath}, using live config"); return(liveJson); } var debugJson = await store.ReadAsync(debugFile); var jObjLive = JObject.Parse(liveJson); var jObjDebug = JObject.Parse(debugJson); foreach (var prop in jObjDebug.Properties()) { var targetProperty = jObjLive.Property(prop.Name); if (targetProperty == null) { jObjDebug.Add(prop.Name, prop.Value); } else { targetProperty.Value = prop.Value; } } return(jObjLive.ToString(Formatting.None)); } }
public static async Task <string> GetConfigJson(string configName) { using (var store = new TextStore()) { var cfgName = configName.ToLower(); var pathFileExt = IsDebug && File.Exists(StorageUtils.PathCombine(AppDataPath, $"{cfgName}{DebugFileExt}")) ? DebugFileExt : LiveFileExt; var json = await store.ReadAsync(StorageUtils.PathCombine(AppDataPath, $"{cfgName}{pathFileExt}")); return(json); } }