/// <summary> /// Attempts to read the configuration file from the given path. /// If the file does not exist a new one will be generated. /// </summary> /// <param name="path">The path to read from.</param> /// <returns>A <see cref="Config"/> object.</returns> public static Config TryRead(string path) { if (!File.Exists(path)) { Config config = new Config(); File.WriteAllText(path, JsonConvert.SerializeObject(config, Formatting.Indented)); return config; } return JsonConvert.DeserializeObject<Config>(File.ReadAllText(path)); }
private void OnReload(ReloadEventArgs args) { loadDatabase(); if (File.Exists(Path.Combine(TShock.SavePath, "USF.json"))) Config = Config.Read(Path.Combine(TShock.SavePath, "USF.json")); Config.Write(Path.Combine(TShock.SavePath, "USF.json")); }
private void OnInitialize(EventArgs args) { SetupDb(); loadDatabase(); if (File.Exists(Path.Combine(TShock.SavePath, "USF.json"))) Config = Config.Read(Path.Combine(TShock.SavePath, "USF.json")); Config.Write(Path.Combine(TShock.SavePath, "USF.json")); Commands.ChatCommands.Add(new Command("usf.set", USFCommand, "us")); }
/// <summary> /// Internal method, reloads the configuration file. /// </summary> internal void LoadConfig() { string configPath = Path.Combine(TShock.SavePath, "UserSpecificFunctions.json"); USFConfig = Config.TryRead(configPath); }