public void WriteConfigFile(ConfigLayout config) { if (File.Exists(path)) //If the config file doesn't exist yet { ///Write one TextWriter tw = new StreamWriter(path); string json = JsonConvert.SerializeObject(config, Formatting.Indented); //Write a templated ConfigLayout tw.Write(json); tw.Close(); } }
//First method TShock runs when the plugin is loaded public override void Initialize() { config.WriteConfigFile(); //Write the initial config file first, in the event that it doesn't exist. configFile = config.ReadConfigFile(); //Read the configuration file and store it in our previously created stub class config.WriteConfigFile(configFile); //Write back the file. Because JsonConvert automagically forms classes, this will automatically update the config file with any new options that may have happened during release. Console.WriteLine("Welcome to TweetShock. Initial configuration read OK. Verify that you've set all app keys before continuing."); //Output some helper text /* * Map each token to each config option */ tokens.AccessToken = configFile.AccessToken; tokens.AccessTokenSecret = configFile.AccessTokenSecret; tokens.ConsumerKey = configFile.ConsumerKey; tokens.ConsumerSecret = configFile.ConsumerSecret; Hooks.ServerHooks.Join += TweetJoin; //Hook when a player joins Hooks.GameHooks.PostInitialize += TweetPostInit; //Hook when the map loads, directly after you see the console Hooks.ServerHooks.Leave += TweetLeave; //Hook when a player leaves }