/// <inheritdoc /> public override bool TryLoad() { if (File.Exists(AbsolutePath) == false) { Log.Debug($"Configuration file for {typeof(TConfig).GetFriendlyName()} can not be found"); return(false); } try { var json = File.ReadAllText(AbsolutePath); CurrentConfig = JsonNodes.FromJson <TConfig>(json); return(true); } catch (Exception e) { Log.Error(e); return(false); } }
/// <inheritdoc /> public override bool TrySave() { var autoReload = AutoReload; var enableFileWatching = EnableFileWatching; AutoReload = false; EnableFileWatching = false; try { var json = JsonNodes.ToJson(CurrentConfig, JsonFormatterSettings.Idented); File.WriteAllText(AbsolutePath, json); HasChanged = false; return(true); } catch (Exception e) { Log.Error(e); return(false); } finally { AutoReload = autoReload; EnableFileWatching = enableFileWatching; } }