Пример #1
0
        /// <summary>
        /// Reloads the configuration file (path). If file is not present, it will generate a new one.
        /// </summary>
        /// <returns>A RootConfig object.</returns>
        public DefaultConfig Reload(DefaultConfig config)
        {
            if (!File.Exists(config.Path))
            {
                File.WriteAllText(config.Path, config.SerializeToJson());
            }

            config = JsonConvert.DeserializeObject <DefaultConfig>(File.ReadAllText(config.Path));

            return(config);
        }
Пример #2
0
        /// <summary>
        /// Reloads the configuration file (path). If file is not present, it will generate a new one.
        /// </summary>
        /// <returns>A RootConfig object.</returns>
        public DefaultConfig Reload(DefaultConfig config)
        {
            DefaultConfig defaultConfig = new DefaultConfig(config.Path);

            if (!File.Exists(config.Path))
            {
                File.WriteAllText(config.Path, defaultConfig.SerializeToXml());
            }

            using (var sr = new StreamReader(config.Path))
            {
                defaultConfig =
                    (DefaultConfig)
                    new XmlSerializer(typeof(DefaultConfig)).Deserialize(sr);
            }

            return(defaultConfig);
        }
Пример #3
0
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(DefaultConfig towrite)
 {
     File.WriteAllText(towrite.Path, JsonConvert.SerializeObject(towrite));
 }
Пример #4
0
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(DefaultConfig towrite)
 {
     File.WriteAllText(towrite.Path, towrite.SerializeToXml());
 }