/// <summary> /// Adds a new directory to the specified element. /// </summary> WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement) { WixDirectoryElement directoryElement = AddDirectory(parentElement, String.Empty); directoryElement.Id = "NewDirectory"; return(directoryElement); }
/// <summary> /// Works out any differences betweent the files specified in /// the Wix document and the files on the file system and /// shows the differences. /// </summary> public void ShowDiff() { WixPackageFilesDiff diff = new WixPackageFilesDiff(directoryReader); diff.ExcludedFileNames.Add(excludedNames); WixDirectoryElementBase directoryElement = view.SelectedElement as WixDirectoryElementBase; if (directoryElement == null) { directoryElement = RootDirectoryElement; } // Directory element selected? if (directoryElement == null) { view.ShowNoDifferenceFoundMessage(); return; } // Show diff results WixPackageFilesDiffResult[] diffResults = diff.Compare(directoryElement); if (diffResults.Length > 0) { view.ShowDiffResults(diffResults); } else { view.ShowNoDifferenceFoundMessage(); } }
/// <summary> /// Compares the files defined in the WixDirectoryElement against those /// on the file system and returns any differences. /// </summary> public WixPackageFilesDiffResult[] Compare(WixDirectoryElementBase directoryElement) { List<string> wixPackageFiles = GetAllFiles(directoryElement); List<string> files = new List<string>(); // Find all files on the file system based on the directories // used in the Wix document. searchedDirectories = new List<string>(); foreach (string fileName in wixPackageFiles) { string directory = Path.GetDirectoryName(fileName); if (!HasDirectoryBeenSearched(directory)) { if (directoryReader.DirectoryExists(directory)) { foreach (string directoryFileName in directoryReader.GetFiles(directory)) { if (!excludedFileNames.IsExcluded(directoryFileName)) { files.Add(Path.Combine(directory, directoryFileName)); } } } } } // Look for new files. List<string> missingFiles = new List<string>(); List<string> removedFiles = new List<string>(); foreach (string fileName in wixPackageFiles) { int index = GetFileNameIndex(files, fileName); if (index >= 0) { removedFiles.Add(files[index]); files.RemoveAt(index); } else { // Check that this file has not already been removed. index = GetFileNameIndex(removedFiles, fileName); if (index == -1) { missingFiles.Add(fileName); } } } // Add new files. List<WixPackageFilesDiffResult> results = new List<WixPackageFilesDiffResult>(); foreach (string fileName in files) { results.Add(new WixPackageFilesDiffResult(fileName, WixPackageFilesDiffResultType.NewFile)); } // Add missing files. foreach (string fileName in missingFiles) { results.Add(new WixPackageFilesDiffResult(fileName, WixPackageFilesDiffResultType.MissingFile)); } // Add new directories. results.AddRange(GetNewDirectories()); return results.ToArray(); }
/// <summary> /// Adds a new directory with the specified name. /// </summary> WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name) { if (parentElement == null) { parentElement = RootDirectoryElement; if (parentElement == null) { parentElement = document.AddRootDirectory(); } } return(parentElement.AddDirectory(name)); }
List <string> GetAllFiles(WixDirectoryElementBase directoryElement) { List <string> files = new List <string>(); // Get all the child directory elements. foreach (WixDirectoryElement childDirectoryElement in directoryElement.GetDirectories()) { files.AddRange(GetAllFiles(childDirectoryElement)); } // Get all the files from any child components. foreach (WixComponentElement componentElement in directoryElement.GetComponents()) { files.AddRange(GetFileNames(componentElement.GetFiles())); } return(files); }
List<string> GetAllFiles(WixDirectoryElementBase directoryElement) { List<string> files = new List<string>(); // Get all the child directory elements. foreach (WixDirectoryElement childDirectoryElement in directoryElement.GetDirectories()) { files.AddRange(GetAllFiles(childDirectoryElement)); } // Get all the files from any child components. foreach (WixComponentElement componentElement in directoryElement.GetComponents()) { files.AddRange(GetFileNames(componentElement.GetFiles())); } return files; }
/// <summary> /// Adds a new directory with the specified name. /// </summary> WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name) { if (parentElement == null) { parentElement = GetRootDirectoryElement(); if (parentElement == null) { parentElement = document.AddRootDirectory(); } } return parentElement.AddDirectory(name); }
/// <summary> /// Adds a new directory to the specified element. /// </summary> WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement) { WixDirectoryElement directoryElement = AddDirectory(parentElement, String.Empty); directoryElement.Id = "NewDirectory"; return directoryElement; }
/// <summary> /// Compares the files defined in the WixDirectoryElement against those /// on the file system and returns any differences. /// </summary> public WixPackageFilesDiffResult[] Compare(WixDirectoryElementBase directoryElement) { List <string> wixPackageFiles = GetAllFiles(directoryElement); List <string> files = new List <string>(); // Find all files on the file system based on the directories // used in the Wix document. searchedDirectories = new List <string>(); foreach (string fileName in wixPackageFiles) { string directory = Path.GetDirectoryName(fileName); if (!HasDirectoryBeenSearched(directory)) { if (directoryReader.DirectoryExists(directory)) { foreach (string directoryFileName in directoryReader.GetFiles(directory)) { if (!excludedFileNames.IsExcluded(directoryFileName)) { files.Add(Path.Combine(directory, directoryFileName)); } } } } } // Look for new files. List <string> missingFiles = new List <string>(); List <string> removedFiles = new List <string>(); foreach (string fileName in wixPackageFiles) { int index = GetFileNameIndex(files, fileName); if (index >= 0) { removedFiles.Add(files[index]); files.RemoveAt(index); } else { // Check that this file has not already been removed. index = GetFileNameIndex(removedFiles, fileName); if (index == -1) { missingFiles.Add(fileName); } } } // Add new files. List <WixPackageFilesDiffResult> results = new List <WixPackageFilesDiffResult>(); foreach (string fileName in files) { results.Add(new WixPackageFilesDiffResult(fileName, WixPackageFilesDiffResultType.NewFile)); } // Add missing files. foreach (string fileName in missingFiles) { results.Add(new WixPackageFilesDiffResult(fileName, WixPackageFilesDiffResultType.MissingFile)); } // Add new directories. results.AddRange(GetNewDirectories()); return(results.ToArray()); }