public bool LoadOrCreateConfig() { Logger.Info("Loading config..."); var path = GetConfigAbsolutePath(); if (!File.Exists(path)) { Logger.Warn("Config does not exist! Creating default..."); CurrentConfig = ConfigData.CreateDefault(); SaveConfig(); } else { try { using (var reader = new StreamReader(path)) CurrentConfig = JsonConvert.DeserializeObject <ConfigData>(reader.ReadToEnd()); } catch (Exception e) { if (!(e is JsonReaderException)) { Logger.Fatal(e); } } if (CurrentConfig == null) { Logger.Fatal("Failed to load the config!"); return(false); } } return(true); }
public ConfigData LoadOrCreateConfig() { Logger.Info("Loading config..."); var path = GetConfigAbsolutePath(); if (!File.Exists(path)) { Logger.Warn("Config does not exist! Creating default config..."); CurrentConfig = ConfigData.CreateDefault(); SaveConfig(); } else { using (var reader = new StreamReader(path)) { CurrentConfig = JsonConvert.DeserializeObject <ConfigData>(reader.ReadToEnd()) ?? ConfigData.CreateDefault(); } } Logger.Info("Loading done..."); return(CurrentConfig); }