SaveConfiguration() public method

public SaveConfiguration ( string Path ) : void
Path string
return void
Example #1
0
        /// <summary>
        /// Loads a configuration file and deserializes it from JSON
        /// </summary>
        public static WorldConfig LoadConfigurationFromFile(string Path)
        {
            WorldConfig config = null;

            try {
                string fileText = System.IO.File.ReadAllText(Path);
                config = JsonConvert.DeserializeObject <WorldConfig>(fileText);
            } catch (Exception ex) {
                if (ex is System.IO.FileNotFoundException || ex is System.IO.DirectoryNotFoundException)
                {
                    TShock.Log.ConsoleError("[SEconomy WorldConfig] Cannot find file or directory. Creating new one.");
                    config = WorldConfig.NewSampleConfiguration();
                    config.SaveConfiguration(Path);
                }
                else if (ex is System.Security.SecurityException)
                {
                    TShock.Log.ConsoleError("[SEconomy WorldConfig] Access denied reading file " + Path);
                }
                else
                {
                    TShock.Log.ConsoleError("[SEconomy WorldConfig] Error " + ex.ToString());
                }
            }

            return(config);
        }