public AppConfig( string configFile ) { this.saveFile = configFile; this.configState = ConfigState.Loading; this.currencies = new List<Currency>(24); try { config = Configuration.LoadFromFile(configFile, Encoding.UTF8); foreach (Section sec in config) { Currency c = sec.CreateObject<Currency>(); if (sec["Name"].StringValue.Contains("Chaos")) { c.Value = 1; } this.currencies.Add(c); } } catch (Exception) { InitializeCurrency(); config = new Configuration(); byte id = 0; var currencyData = currencies.OfType<Currency>().OrderBy(item => item.Name).GetEnumerator(); while (currencyData.MoveNext()) { config.Add(Section.FromObject(SECTION_CURRENCY + id, currencyData.Current)); id++; } config.SaveToFile(configFile, Encoding.UTF8); } configState = ConfigState.Clean; }
private static Configuration DeserializeBinary(BinaryReader reader, Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } bool ownReader = false; if (reader == null) { reader = new BinaryReader(stream); ownReader = true; } try { var config = new Configuration(); int sectionCount = reader.ReadInt32(); for (int i = 0; i < sectionCount; i++) { string sectionName = reader.ReadString(); int settingCount = reader.ReadInt32(); Section section = new Section(sectionName); DeserializeComments(reader, section); for (int j = 0; j < settingCount; j++) { Setting setting = new Setting( reader.ReadString(), reader.ReadString()); DeserializeComments(reader, setting); section.Add(setting); } config.Add(section); } return(config); } finally { if (ownReader) { reader.Close(); } } }
public Configuration(string path) { this.Path = path; if (!File.Exists(path)) { SharpConfig.Configuration settings = new SharpConfig.Configuration(); settings.Add("Server"); settings["Server"].Add("IP", "127.0.0.1"); settings["Server"].Add("Port", 31651); settings.SaveToFile(this.Path); } this.Settings = SharpConfig.Configuration.LoadFromFile(this.Path); }
private static Configuration DeserializeBinary(BinaryReader reader, Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); bool ownReader = false; if (reader == null) { reader = new BinaryReader(stream); ownReader = true; } try { var config = new Configuration(); int sectionCount = reader.ReadInt32(); for (int i = 0; i < sectionCount; ++i) { string sectionName = reader.ReadString(); int settingCount = reader.ReadInt32(); Section section = new Section(sectionName); DeserializeComments(reader, section); for (int j = 0; j < settingCount; j++) { Setting setting = new Setting( reader.ReadString(), reader.ReadString()); DeserializeComments(reader, setting); section.Add(setting); } config.Add(section); } return config; } finally { if (ownReader) reader.Close(); } }
private void InitializeGameConfiguration() { if (File.Exists(PathGameConfigFile)) GameConfiguration = SharpConfig.Configuration.LoadFromFile(PathGameConfigFile); else { GameConfiguration = new Configuration(); GameConfigurationItem _item = new GameConfigurationItem(); _item.CurrentVersion = new Version(0, 1); Section _currentSection = Section.FromObject("Game", _item); GameConfiguration.Add(_currentSection); GameConfiguration.SaveToFile(PathGameConfigFile); } }
internal static Configuration ReadFromBinaryStream(Stream stream, BinaryReader reader) { if (stream == null) { throw new ArgumentNullException("stream"); } if (reader == null) { reader = new BinaryReader(stream); } var config = new Configuration(); int sectionCount = reader.ReadInt32(); for (int i = 0; i < sectionCount; ++i) { string sectionName = reader.ReadString(); int settingCount = reader.ReadInt32(); var section = new Section(sectionName); ReadCommentsBinary(reader, section); for (int j = 0; j < settingCount; j++) { var setting = new Setting(reader.ReadString()) { RawValue = reader.ReadString() }; ReadCommentsBinary(reader, setting); section.Add(setting); } config.Add(section); } return(config); }
private void InitializeProjectileConfiguration() { if (File.Exists(PathProjectileConfigFile)) ProjectileConfiguration = SharpConfig.Configuration.LoadFromFile(PathProjectileConfigFile); else { ProjectileConfiguration = new Configuration(); for (int i = 1; i <= 4; i++) { ProjectileConfigItem _item = new ProjectileConfigItem(); _item.ID = i; switch (i) { case 1: _item.PrefabPath = "Prefab/Projectile/Prototype_Pistol_Projectile"; break; case 2: _item.PrefabPath = "Prefab/Projectile/Prototype_Rifle_Projectile"; break; case 3: _item.PrefabPath = "Prefab/Projectile/Prototype_Shotgun_Projectile"; break; case 4: _item.PrefabPath = "Prefab/Projectile/Prototype_SniperRifle_Projectile"; break; } Section _newSection = Section.FromObject(i.ToString(), _item); ProjectileConfiguration.Add(_newSection); } ProjectileConfiguration.SaveToFile(PathProjectileConfigFile); } }
private void InitializeWeaponConfiguration() { if (File.Exists(PathWeaponConfigFile)) WeaponConfiguration = SharpConfig.Configuration.LoadFromFile(PathWeaponConfigFile); else { WeaponConfiguration = new Configuration(); for (int i = 1; i <= 4; i++) { string _sectionName = string.Empty; WeaponConfigurationItem _item = new WeaponConfigurationItem(); _item.ID = i; switch (i) { case 1: _sectionName = "Prototype_Rifle"; _item.WeaponName = "Prototype Rifle"; _item.WeaponType = 0; // TODO: ALTERAR PARA ENUMERADOR!!! _item.Automatic = true; _item.ProjectileID = 2; _item.AmmoMax = 30; _item.Damage = 15; _item.FirePerSecond = 12.5f; _item.ReloadTimeInSeconds = 1.25f; _item.PrefabPath = "Resources/Prefab/Weapon/Prototype_Rifle"; break; case 2: _sectionName = "Prototype_Shotgun"; _item.WeaponName = "Prototype Shotgun"; _item.WeaponType = 1; // TODO: ALTERAR PARA ENUMERADOR!!! _item.Automatic = false; _item.ProjectileID = 3; _item.AmmoMax = 8; _item.Damage = 50; _item.FirePerSecond = 1.5f; _item.ReloadTimeInSeconds = 3f; _item.PrefabPath = "Resources/Prefab/Weapon/Prototype_Shotgun"; break; case 3: _sectionName = "Prototype_SniperRifle"; _item.WeaponName = "Prototype SniperRifle"; _item.WeaponType = 0; // TODO: ALTERAR PARA ENUMERADOR!!! _item.Automatic = false; _item.ProjectileID = 4; _item.AmmoMax = 12; _item.Damage = 40; _item.FirePerSecond = 3.5f; _item.ReloadTimeInSeconds = 2.16f; _item.PrefabPath = "Resources/Prefab/Weapon/Prototype_SniperRifle"; break; case 4: _sectionName = "Prototype_Pistol"; _item.WeaponName = "Prototype Pistol"; _item.WeaponType = 2; // TODO: ALTERAR PARA ENUMERADOR!!! _item.Automatic = false; _item.ProjectileID = 1; _item.AmmoMax = 16; _item.Damage = 15; _item.FirePerSecond = 12f; _item.ReloadTimeInSeconds = 0.7f; _item.PrefabPath = "Resources/Prefab/Weapon/Prototype_Pistol"; break; } Section _newSection = Section.FromObject(_sectionName, _item); WeaponConfiguration.Add(_newSection); } WeaponConfiguration.SaveToFile(PathWeaponConfigFile); } }