public static T LoadConfig <T>(this IJsonConfiguration <T> module) // Load config file { string path = Module.GetPath(module.GetType().Name + ".json"); try { if (!File.Exists(path)) { File.WriteAllText(path, JsonConvert.SerializeObject(module.DefaultConfig, typeof(T), Formatting.Indented, null)); return(module.DefaultConfig); } return(JsonConvert.DeserializeObject <T>(File.ReadAllText(path))); } catch (Exception e) { if (module is IModule log) { log.LogError("Error while loading " + path + "."); log.LogError(e.Message); } Modules.Log.SendLog(e.StackTrace, true); return(module.DefaultConfig); } }
public static bool SaveConfig <T>(this IJsonConfiguration <T> module, T value) // Save config file { string path = Module.GetPath(module.GetType().Name + ".json"); try { File.WriteAllText(path, JsonConvert.SerializeObject(value, typeof(T), Formatting.Indented, null)); return(true); } catch (Exception e) { if (module is IModule log) { log.LogError("Error while loading " + path + "."); log.LogError(e.Message); } Modules.Log.SendLog(e.StackTrace, true); return(false); } }