public Task <Stream> LoadAsset(IAssetObject assetObject, CancellationToken cancellationToken, Action <double, string> progress) { // Natural path string filePath = assetObject.AssetPath; // Is relative asset path only, no directory if (Path.GetDirectoryName(filePath) == "") { filePath = Path.Combine(Object3D.AssetsPath, filePath); // Prime cache if (!File.Exists(filePath)) { AcquireAsset(assetObject.AssetPath, cancellationToken, progress); } } if (!File.Exists(filePath)) { // Not at natural path, not in local assets, not in remote assets return(Task.FromResult <Stream>(null)); } return(Task.FromResult <Stream>(File.OpenRead(filePath))); }
public async Task StoreAsset(IAssetObject assetObject, bool publishAfterSave, CancellationToken cancellationToken, Action <double, string> progress) { // Natural path string filePath = assetObject.AssetPath; // Is full path and file exists, import as Asset if (Path.GetDirectoryName(filePath) != "" && File.Exists(filePath)) { using (var sourceStream = File.OpenRead(assetObject.AssetPath)) { // ComputeSha1 -> Save asset //string assetName = await this.StoreStream(sourceStream, Path.GetExtension(assetObject.AssetPath), cancellationToken, progress); string sha1PlusExtension = await this.StoreFile(assetObject.AssetPath, publishAfterSave, cancellationToken, progress); // Update AssetID assetObject.AssetID = Path.GetFileNameWithoutExtension(sha1PlusExtension); assetObject.AssetPath = sha1PlusExtension; } } await ConditionalPublish( assetObject.AssetPath, publishAfterSave, cancellationToken, progress); }
public Task <Stream> LoadAsset(IAssetObject assetObject, CancellationToken cancellationToken, Action <double, string> progress) { // Natural path string filePath = assetObject.AssetPath; // Is relative asset path only, no directory if (Path.GetDirectoryName(filePath) == "") { filePath = Path.Combine(Object3D.AssetsPath, filePath); if (!assetLocks.ContainsKey(filePath)) { assetLocks[filePath] = new object(); } // make sure we are only loading a give asset one at a time (in case we need to aquire it before getting) lock (assetLocks[filePath]) { // Prime cache if (!File.Exists(filePath)) { AcquireAsset(assetObject.AssetPath, cancellationToken, progress); } } } if (!File.Exists(filePath)) { // Not at natural path, not in local assets, not in remote assets return(Task.FromResult <Stream>(null)); } return(Task.FromResult <Stream>(File.OpenRead(filePath))); }