/// <inheritdoc /> public virtual void SaveAsset(byte[] data, string name, bool backup) { string filePath = EnginePathToFilePath(name); filePath = filePath.Replace(_folderFs.ToLower(), _folderFs); if (!File.Exists(filePath)) { // If new - add to the internal manifest. InternalManifest.TryAdd(FilePathToEnginePath(filePath, FolderInPath), filePath); } else if (backup) { // Backup old - if any. File.Copy(filePath, filePath + ".backup", true); } // Create missing directories. string directoryName = Path.GetDirectoryName(filePath); if (!string.IsNullOrEmpty(directoryName)) { Directory.CreateDirectory(directoryName); } FileStream stream = File.Open(filePath, FileMode.Create); stream.Write(data, 0, data.Length); stream.Dispose(); }
/// <inheritdoc /> /// <summary> /// The folder relative to the executable where file assets will be loaded from. /// </summary> /// <param name="folder">The folder to load assets from.</param> public FileAssetSource(string folder) { Folder = folder; // Check if folder exists. if (!Directory.Exists(Folder)) { Directory.CreateDirectory(Folder); } // Populate internal manifest. string[] files = Directory.GetFiles(Folder, "*", SearchOption.AllDirectories); files.AsParallel().ForAll(x => InternalManifest.TryAdd(FilePathToCrossPlatform(x), x)); }
/// <summary> /// Create a new source which loads assets embedded into the assembly. /// </summary> /// <param name="assembly">The assembly to load assets from.</param> /// <param name="folder">The root embedded folder.</param> public EmbeddedAssetSource(Assembly assembly, string folder) { Folder = folder.Replace("/", "$").Replace("\\", "$").Replace("$", "."); Assembly = assembly; string assemblyFullName = assembly.FullName; Name = assemblyFullName.Substring(0, assemblyFullName.IndexOf(",", StringComparison.Ordinal)); // Populate internal manifest. Assembly.GetManifestResourceNames().AsParallel().ForAll(x => { string enginePath = EmbeddedPathToEnginePath(x); if (enginePath != null) { InternalManifest.TryAdd(enginePath, x); } }); }
protected void PopulateInternalManifest() { InternalManifest.Clear(); string[] files = Directory.GetFiles(Folder, "*", SearchOption.AllDirectories); files.AsParallel().ForAll(x => InternalManifest.TryAdd(FilePathToEnginePath(x), x)); }