public bool RenameAsset(CAsset assetToRename, string newName) { lock (m_registryMutex) { if (m_assetFileMap.TryGet(assetToRename.Guid, out string assetPath)) { string oldFullPath = ProjectDefinitions.GetAbsolutePath(assetPath); string newFullPath = Path.GetDirectoryName(oldFullPath) + "/" + newName + assetToRename.GetFileExtension(); if (File.Exists(newFullPath)) { return(false); } string newRelativePath = ProjectDefinitions.GetRelativePath(newFullPath); assetToRename.Name = newName; assetToRename.Path = newRelativePath; m_assetFileMap[assetToRename.Guid] = newRelativePath; if (File.Exists(oldFullPath)) { File.Delete(oldFullPath); SaveAsset(assetToRename); } SaveRegistry(); return(true); } } return(false); }
public override void CopyFrom(CAsset source) { base.CopyFrom(source); CModelAsset modelSource = (CModelAsset)source; MeshChildren = modelSource.MeshChildren; }
public void GetAssetInDirectoryLoaded(string directory, IList <CAsset> outAssets) { lock (m_registryMutex) { object listMutex = new object(); Parallel.ForEach(m_assetFileMap.ValueToKey, (pathGuidPair) => { string directoryName = Path.GetDirectoryName(pathGuidPair.Key); directoryName = directoryName?.Replace('\\', '/'); if (directoryName == directory) { if (m_assetMap.TryGetValue(pathGuidPair.Value, out CAsset asset)) { asset.WaitUntilLoaded(); lock (listMutex) { outAssets.Add(asset); } } else { CAsset loadedAsset = DeserializeAsset(pathGuidPair.Key); lock (listMutex) { m_assetMap.Add(pathGuidPair.Value, loadedAsset); outAssets.Add(loadedAsset); } } } }); } }
public override void CopyFrom(CAsset source) { base.CopyFrom(source); CMaterialAsset sourceMaterial = (CMaterialAsset)source; MaterialParameters = sourceMaterial.MaterialParameters; Shader = sourceMaterial.Shader; }
public override void CopyFrom(CAsset source) { base.CopyFrom(source); CTextureAsset textureSource = (CTextureAsset)source; ImageSurface = textureSource.ImageSurface; DDSImagePath = textureSource.DDSImagePath; }
public override void CopyFrom(CAsset source) { base.CopyFrom(source); CShaderAsset shaderSource = (CShaderAsset)source; ShaderName = shaderSource.ShaderName; ShaderBytecode = shaderSource.ShaderBytecode; }
public override bool Equals(object obj) { CAsset other = obj as CAsset; if (other == null) { return(false); } return(other.Guid.Equals(Guid)); }
public override void CopyFrom(CAsset source) { base.CopyFrom(source); CMeshAsset meshSource = (CMeshAsset)source; PrimitiveTopology = meshSource.PrimitiveTopology; FaceCount = meshSource.FaceCount; VertexData = meshSource.VertexData; IndexData = meshSource.IndexData; MaterialAsset = meshSource.MaterialAsset; AABBMin = meshSource.AABBMin; AABBMax = meshSource.AABBMax; }
private CAsset DeserializeAsset(string filePath) { FileStream fileStream = new FileStream(ProjectDefinitions.GetAbsolutePath(filePath), FileMode.Open); CAsset loadedAsset = (CAsset)CAssetSerializer.Instance.DeserializeFromStream(fileStream); loadedAsset.Path = filePath; if (loadedAsset.LoadCustomResources()) { loadedAsset.LoadFinished(); } return(loadedAsset); }
public bool RemoveAssetFile(CAsset assetToRemove) { if (assetToRemove == null) { return(false); } lock (m_registryMutex) { assetToRemove.RemoveCustomResources(); m_assetMap.Remove(assetToRemove.Guid); m_assetFileMap.Remove(assetToRemove.Guid); SaveRegistry(); return(true); } }
public void RegisterAsset(CAsset asset, string basePath, bool bOverride) { lock (m_registryMutex) { if (!m_assetFileMap.ContainsKey(asset.Guid)) { basePath = SanitizeAssetPath(basePath); string assetFileName = basePath + asset.Name + asset.GetFileExtension(); if (!bOverride) { if (FileUtilities.GetNextAvailableAssetFile(assetFileName, m_assetFileMap.ValueToKey, out string foundFileName)) { assetFileName = foundFileName; asset.Name = Path.GetFileNameWithoutExtension(foundFileName); } else { throw new Exception("Couldn't find a valid asset filename"); } } asset.Path = assetFileName; m_assetFileMap.Add(asset.Guid, assetFileName); m_assetMap.Add(asset.Guid, asset); // todo henning defer this until asset is loaded in case it is not loaded yet if (AutoSaveAssets > 0) { Task.Run(() => { string absoluteFilename = ProjectDefinitions.GetAbsolutePath(assetFileName); FileInfo fileInfo = new FileInfo(absoluteFilename); fileInfo.Directory?.Create(); asset.SaveCustomResources(basePath); FileStream fileStream = new FileStream(absoluteFilename, FileMode.Create); CAssetSerializer.Instance.SerializeToStream(asset, fileStream); SaveRegistry(); }); } else { m_unsavedAssets.Add(asset); } } } }
/// <summary> /// Save modifications made to the given asset, only needed if an asset is modified after registration, does not work for non registered assets use RequestRegisterAsset instead /// </summary> /// <param name="assetToSave"></param> public void SaveAsset(CAsset assetToSave) { lock (m_registryMutex) { if (m_assetFileMap.TryGet(assetToSave.Guid, out string assetFilename)) { string absoluteFilename = ProjectDefinitions.GetAbsolutePath(assetFilename); FileInfo fileInfo = new FileInfo(absoluteFilename); string relativeDirectory = ProjectDefinitions.GetRelativePath(fileInfo.DirectoryName) + '/'; assetToSave.SaveCustomResources(relativeDirectory); FileStream fileStream = new FileStream(absoluteFilename, FileMode.Create); CAssetSerializer.Instance.SerializeToStream(assetToSave, fileStream); } else { throw new Exception("Tried to save an asset that is not registered in the registry, make sure to register assets with RequestRegisterAsset"); } } }
public bool MoveAssetFile(CAsset assetToMove, string targetPath) { lock (m_registryMutex) { if (m_assetFileMap.TryGet(assetToMove.Guid, out string currentPath)) { string assetFileName = Path.GetFileName(currentPath); string targetRelativePath = SanitizeAssetPath(Path.Combine(targetPath, assetFileName)); string absoluteCurrent = ProjectDefinitions.GetAbsolutePath(currentPath); string absoluteTarget = ProjectDefinitions.GetAbsolutePath(targetRelativePath); File.Move(absoluteCurrent, absoluteTarget); m_assetFileMap[assetToMove.Guid] = targetRelativePath; assetToMove.Path = targetRelativePath; assetToMove.MoveCustomResources(targetRelativePath); SaveRegistry(); return(true); } } return(false); }
public virtual void CopyFrom(CAsset source) { Name = source.Name; }