private string FindParent(string DirectoryName, MSIDirectory directory) { if (DirectoryName == directory.name && directory is MSIRootDirectory) { return ((MSIRootDirectory)directory).root; } else { if (directory.directory != null) { foreach (MSIDirectory directory2 in directory.directory) { if (directory2.name == DirectoryName) { return directory.name; } else { string parent = FindParent(DirectoryName, directory2); if (parent != null) { return parent; } } } } } return null; }
private MSIDirectory FindDirectory(string DirectoryName, MSIDirectory directory) { if (directory.name == DirectoryName) return directory; if (directory.directory != null) { foreach (MSIDirectory childDirectory in directory.directory) { MSIDirectory childDirectory2 = FindDirectory(DirectoryName, childDirectory); if (childDirectory2 != null) { return childDirectory2; } } } return null; }
/// <summary> /// Adds a directory record to the directories table. /// </summary> /// <param name="database">The MSI database.</param> /// <param name="directoryTable">The MSI database view.</param> /// <param name="ParentDirectory">The parent directory.</param> /// <param name="Directory">This directory's Schema object.</param> /// <param name="Depth">The tree depth of this directory.</param> private void AddDirectory(InstallerDatabase database, InstallerTable directoryTable, string ParentDirectory, MSIDirectory Directory, int Depth) { string newParent; if (Directory is MSIRootDirectory) { newParent = ((MSIRootDirectory)Directory).root; } else { newParent = ParentDirectory; } StringBuilder relativePath = new StringBuilder(); GetRelativePath(database, Directory.name, ParentDirectory, Directory.foldername, relativePath, directoryTable); if (relativePath.ToString().Length != 0) { string fullPath = Path.Combine(Path.Combine(Project.BaseDirectory, msi.sourcedir), relativePath.ToString()); bool createTemp = false; DirectoryInfo di = new DirectoryInfo(fullPath); DirectoryInfo lastExistingDir = di.Parent; if (!di.Exists) { while (!lastExistingDir.Exists) { lastExistingDir = lastExistingDir.Parent; } di.Create(); createTemp = true; } string path = GetShortPath(fullPath) + "|" + Directory.foldername; if (createTemp) { while (!di.FullName.Equals(lastExistingDir.FullName)) { di.Delete(); di = di.Parent; } } if (Directory.foldername == ".") path = Directory.foldername; Log(Level.Verbose, "\t" + relativePath.ToString()); // Insert the Directory directoryTable.InsertRecord(Directory.name, newParent, path); if (Directory.directory != null) { foreach (MSIDirectory childDirectory in Directory.directory) { int newDepth = Depth + 1; AddDirectory(database, directoryTable, Directory.name, childDirectory, newDepth); } } } }