/// <summary> /// Harvest a directory. /// </summary> /// <param name="path">The path of the directory.</param> /// <param name="relativePath">The relative path that will be used when harvesting.</param> /// <param name="harvestChildren">The option to harvest child directories and files.</param> /// <returns>The harvested directory.</returns> public Wix.Directory HarvestDirectory(string path, string relativePath, bool harvestChildren) { if (null == path) { throw new ArgumentNullException("path"); } if (File.Exists(path)) { throw new WixException(WixErrors.ExpectedDirectoryGotFile("dir", path)); } if (null == this.rootedDirectoryRef) { this.rootedDirectoryRef = "TARGETDIR"; } // use absolute paths path = Path.GetFullPath(path); // Remove any trailing separator to ensure Path.GetFileName() will return the directory name. path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); Wix.Directory directory = new Wix.Directory(); directory.Name = Path.GetFileName(path); directory.FileSource = path; if (this.setUniqueIdentifiers) { if (this.suppressRootDirectory) { directory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, this.rootedDirectoryRef); } else { directory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, this.rootedDirectoryRef, directory.Name); } } if (harvestChildren) { try { int fileCount = this.HarvestDirectory(path, relativePath, directory); // its an error to not harvest anything with the option to keep empty directories off if (0 == fileCount && !this.keepEmptyDirectories) { throw new WixException(UtilErrors.EmptyDirectory(path)); } } catch (DirectoryNotFoundException) { throw new WixException(UtilErrors.DirectoryNotFound(path)); } } return(directory); }
/// <summary> /// Harvest a directory. /// </summary> /// <param name="path">The path of the directory.</param> /// <param name="harvestChildren">The option to harvest child directories and files.</param> /// <returns>The harvested directory.</returns> public Wix.Directory HarvestDirectory(string path, bool harvestChildren) { if (null == path) { throw new ArgumentNullException("path"); } Wix.Directory directory = new Wix.Directory(); // use absolute paths path = Path.GetFullPath(path); directory.FileSource = path; directory.Name = Path.GetFileName(path); if (harvestChildren) { try { int fileCount = this.HarvestDirectory(path, directory); // its an error to not harvest anything with the option to keep empty directories off if (0 == fileCount && !this.keepEmptyDirectories) { throw new WixException(UtilErrors.EmptyDirectory(path)); } } catch (DirectoryNotFoundException) { throw new WixException(UtilErrors.DirectoryNotFound(path)); } } return(directory); }