public void Save() { if (this.ProjectSettings == null) { return; } this.BlueprintManagerViewModel.UpdateLocalizationKeys(); // Save blueprint files. for (int index = 0; index < this.ProjectSettings.BlueprintFiles.Count; index++) { var blueprintFile = this.ProjectSettings.BlueprintFiles[index]; // Set generic blueprint file path if not set. if (blueprintFile.Path == null) { var absolutePath = GenerateBlueprintFilePath(this.SerializationPath, index); blueprintFile.Path = GetRelativePath(absolutePath, this.ProjectPath); } // Write text. var absoluteBlueprintFilePath = string.Format("{0}\\{1}", this.ProjectPath, blueprintFile.Path); var blueprintFileStream = new FileStream(absoluteBlueprintFilePath, FileMode.Create); this.blueprintManagerSerializer.Serialize(blueprintFileStream, blueprintFile.BlueprintManager); blueprintFileStream.Close(); if (this.WriteBlueprintsAsBinary) { // Write binary. var blueprintFilePath = string.Format( "{0}\\{1}", this.ProjectPath, Path.ChangeExtension(blueprintFile.Path, "bytes")); blueprintFileStream = new FileStream(blueprintFilePath, FileMode.Create); var binarySerializer = new BinarySerializer(blueprintFileStream); binarySerializer.Serialize(blueprintFile.BlueprintManager); blueprintFileStream.Close(); } } // Save project. var fileStream = new FileStream(this.SerializationPath, FileMode.Create); // Convert file paths. this.ProjectSettings.ProjectAssembliesSerialized = this.ProjectSettings.ProjectAssemblies.Select( projectAssembly => GetRelativePath(projectAssembly.CodeBase, this.SerializationPath)).ToArray(); this.ProjectSettings.LanguageFilesSerialized = this.ProjectSettings.LanguageFiles.Select( languageFile => GetRelativePath(languageFile.Path, this.SerializationPath)).ToArray(); this.ProjectSettings.LanguageNamesSerialized = this.ProjectSettings.LanguageFiles.Select( languageFile => languageFile.LanguageTag).ToArray(); this.projectSettingsSerializer.Serialize(fileStream, this.ProjectSettings); this.localizationContext.SaveLanguages(); fileStream.Close(); }
/// <summary> /// Converts this object to its binary representation. /// </summary> /// <param name="serializer">Serializer to writer this object with.</param> public void Serialize(BinarySerializer serializer) { serializer.Serialize(this.AttributeTableSerialized); serializer.Serialize(this.ComponentTypesSerialized); serializer.Serialize(string.IsNullOrEmpty(this.ParentId) ? string.Empty : this.ParentId); }
/// <summary> /// Converts this object to its binary representation. /// </summary> /// <param name="serializer">Serializer to writer this object with.</param> public void Serialize(BinarySerializer serializer) { serializer.Serialize( this.AdditionalComponentTypes.Select(componentType => componentType.FullName).ToArray()); serializer.Serialize(string.IsNullOrEmpty(this.BlueprintId) ? string.Empty : this.BlueprintId); serializer.Serialize(this.Configuration); }
public static void SwitchToBinaryBlueprints() { // Remove old backup files if xml file also exists. // Keeping it if not, as this may be the second time the "SwitchToBinaryBlueprints" method was called. foreach (var filename in Directory.GetFiles(AbsoluteBlueprintsFolderPath)) { var file = new FileInfo(filename); if (!file.Extension.Equals(BlueprintFileExtensionTemp)) { continue; } if (!File.Exists(Path.ChangeExtension(filename, null))) { continue; } Debug.Log(String.Format("Deleting temp file {0}", file)); FileUtil.DeleteFileOrDirectory(file.FullName); } // Collect XML blueprint files. foreach (var filename in Directory.GetFiles(AbsoluteBlueprintsFolderPath)) { var file = new FileInfo(filename); if (file.Extension.Equals(BlueprintFileExtensionXml)) { BlueprintManager blueprintManager; // Deserialize blueprints from XML. using (var fileStream = file.OpenRead()) { Debug.Log(String.Format("Deserializing blueprints from {0}", file.FullName)); var blueprintManagerSerializer = new XmlSerializer(typeof(BlueprintManager)); blueprintManager = (BlueprintManager)blueprintManagerSerializer.Deserialize(fileStream); } // Rename to temporary files. Debug.Log( String.Format("Moving {0} to {1}", file.FullName, file.FullName + BlueprintFileExtensionTemp)); FileUtil.MoveFileOrDirectory(file.FullName, file.FullName + BlueprintFileExtensionTemp); Debug.Log( String.Format( "Moving {0} to {1}", file.FullName + ".meta", file.FullName + ".meta" + BlueprintFileExtensionTemp)); FileUtil.MoveFileOrDirectory( file.FullName + ".meta", file.FullName + ".meta" + BlueprintFileExtensionTemp); // Serialize blueprints to binary. var binaryBlueprintFile = new FileInfo(Path.ChangeExtension(file.FullName, BlueprintFileExtensionBinary)); using (var fileStream = binaryBlueprintFile.Create()) { Debug.Log(String.Format("Serializing blueprints to {0}", binaryBlueprintFile.FullName)); var binarySerializer = new BinarySerializer(fileStream); binarySerializer.Serialize(blueprintManager); } } } AssetDatabase.Refresh(); }