private void SavePrefabData() { if (!this._saveToXml) { return; } try { string str = "IptVehicleData"; if (!Directory.Exists(str)) { Directory.CreateDirectory(str); } string path2 = Utils.RemoveInvalidFileNameChars(this.ObjectName + ".xml"); string path = System.IO.Path.Combine(str, path2); PrefabData.DefaultPrefabData defaultPrefabData = new PrefabData.DefaultPrefabData(); defaultPrefabData.Capacity = this.Capacity; defaultPrefabData.MaintenanceCost = this.MaintenanceCost; defaultPrefabData.MaxSpeed = this.MaxSpeed; defaultPrefabData.EngineOnBothEnds = this.EngineOnBothEnds; using (StreamWriter streamWriter = new StreamWriter(path)) new XmlSerializer(typeof(PrefabData.DefaultPrefabData)).Serialize((TextWriter)streamWriter, (object)defaultPrefabData); } catch (Exception ex) { Utils.LogError((object)(ex.Message + System.Environment.NewLine + ex.StackTrace)); } }
private void LoadPrefabData() { try { string str = "IptVehicleData"; if (!Directory.Exists(str)) { Directory.CreateDirectory(str); } string path2 = Utils.RemoveInvalidFileNameChars(this.ObjectName + ".xml"); string path = System.IO.Path.Combine(str, path2); if (!File.Exists(path)) { Utils.Log((object)("No stored data found for " + this.ObjectName)); } else { Utils.Log((object)("Found stored data for " + this.ObjectName)); using (StreamReader streamReader = new StreamReader(path)) { PrefabData.DefaultPrefabData defaultPrefabData = (PrefabData.DefaultPrefabData) new XmlSerializer(typeof(PrefabData.DefaultPrefabData)).Deserialize((TextReader)streamReader); this.Capacity = defaultPrefabData.Capacity; this.MaintenanceCost = defaultPrefabData.MaintenanceCost; this.MaxSpeed = defaultPrefabData.MaxSpeed; this.EngineOnBothEnds = defaultPrefabData.EngineOnBothEnds; this._changeFlag = false; } } } catch (Exception ex) { Utils.LogError((object)(ex.Message + System.Environment.NewLine + ex.StackTrace)); } }
private void CacheDefaults() { this.Defaults = new PrefabData.DefaultPrefabData(); this.Defaults.Capacity = this.Capacity; this.Defaults.MaxSpeed = this.MaxSpeed; this.Defaults.MaintenanceCost = 800; this.Defaults.EngineOnBothEnds = this.EngineOnBothEnds; }