Пример #1
0
        public bool UseSSC = true; // |Enabling grants legacy functionality, disabling uses the safer drop method

        #endregion Fields

        #region Methods

        public static Config Read(string savepath = "")
        {
            // Default to tshock path if no path is given
            if (String.IsNullOrWhiteSpace(savepath))
            {
                savepath = TShock.SavePath;
            }

            // Append the file name to the given path
            savepath = Path.Combine(savepath, "KeyChangerConfig.json");

            // Creates any missing folders
            Directory.CreateDirectory(Path.GetDirectoryName(savepath));

            try
            {
                Config file = new Config();
                if (File.Exists(savepath))
                {
                    // Get data from the file
                    file = JsonConvert.DeserializeObject<Config>(File.ReadAllText(savepath));
                }
                else
                {
                    TShock.Log.ConsoleInfo("Creating config file for KeyChangerSSC...");
                }

                // Create or update the file to fix missing options
                File.WriteAllText(savepath, JsonConvert.SerializeObject(file, Formatting.Indented));
                return file;
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError(ex.ToString());
                return new Config();
            }
        }