/// <summary> /// Populates the root directory from embedded resources. /// </summary> public void PopulateFromEmbeddedResources() { _root = new InMemoryVirtualDirectory(this) { FlattenFileEnumeration = false }; foreach (var assembly in _assemblies) { string baseName = assembly.GetName().Name + "."; foreach (var resource in assembly.GetManifestResourceNames()) { // Most embedded resources will start with the assembly name (e.g. Foo.txt in Bar.dll will be named Bar.Foo.txt by default) // Strip that assembly name off if it's set string relativeName = resource; if (relativeName.StartsWith(baseName)) { relativeName = relativeName.Remove(0, baseName.Length); } string fileName; string[] directoryStructure; // Figure out which portion of the path represents the file name, and what directory structure it's in (if any) InferFileNameAndDirectoryPath(relativeName, out fileName, out directoryStructure); // Loop over the directory structure to figure out which directory this file is supposed to go in InMemoryVirtualDirectory destinationDirectory = _root; foreach (var directory in directoryStructure) { var nextLevel = (InMemoryVirtualDirectory)destinationDirectory.GetDirectory(directory); // If our expected directory doesn't exist, add it if (nextLevel == null) { nextLevel = new InMemoryVirtualDirectory(this, destinationDirectory) { FlattenFileEnumeration = false, DirName = directory }; destinationDirectory.dirs.Add(nextLevel); } destinationDirectory = nextLevel; } var file = new StreamBasedVirtualFile(this, destinationDirectory, assembly.GetManifestResourceStream(resource), fileName, DateTime.Now); // Give people the opportunity to exclude this file if (FileExcluder != null && FileExcluder(file)) { continue; } destinationDirectory.files.Add(file); } } }
/// <summary> /// Populates the root directory from embedded resources. /// </summary> public void PopulateFromEmbeddedResources() { _root = new InMemoryVirtualDirectory(this) { FlattenFileEnumeration = false }; foreach (var assembly in _assemblies) { string baseName = assembly.GetName().Name + "."; foreach (var resource in assembly.GetManifestResourceNames()) { // Most embedded resources will start with the assembly name (e.g. Foo.txt in Bar.dll will be named Bar.Foo.txt by default) // Strip that assembly name off if it's set string relativeName = resource; if (relativeName.StartsWith(baseName)) { relativeName = relativeName.Remove(0, baseName.Length); } string fileName; string[] directoryStructure; // Figure out which portion of the path represents the file name, and what directory structure it's in (if any) InferFileNameAndDirectoryPath(relativeName, out fileName, out directoryStructure); // Loop over the directory structure to figure out which directory this file is supposed to go in InMemoryVirtualDirectory destinationDirectory = _root; foreach (var directory in directoryStructure) { var nextLevel = (InMemoryVirtualDirectory) destinationDirectory.GetDirectory(directory); // If our expected directory doesn't exist, add it if (nextLevel == null) { nextLevel = new InMemoryVirtualDirectory(this, destinationDirectory) {FlattenFileEnumeration = false, DirName = directory}; destinationDirectory.dirs.Add(nextLevel); } destinationDirectory = nextLevel; } var file = new StreamBasedVirtualFile(this, destinationDirectory, assembly.GetManifestResourceStream(resource), fileName, DateTime.Now); // Give people the opportunity to exclude this file if (FileExcluder != null && FileExcluder(file)) { continue; } destinationDirectory.files.Add(file); } } }