示例#1
0
        /// <summary>
        /// Gets the file system entries of a folder and its all sub-folders with relative path.
        /// </summary>
        /// <param name="baseFolder">Base folder.</param>
        /// <param name="filter">Filter to be used. default is "*"</param>
        /// <param name="fileList">Files list containing the relative file paths.</param>
        /// <param name="folderList">Folders list containing the relative folder paths.</param>
        private static void GetRelativeFileSystemEntries(string baseFolder, string filter, IList <string> fileList, IList <string> folderList)
        {
            if (baseFolder == null)
            {
                throw new ArgumentNullException("baseFolder");
            }

            if (String.IsNullOrEmpty(filter))
            {
                filter = "*";  // include all files and folders
            }

            if (fileList != null)
            {
                string[] fileEntries = Directory.GetFiles(baseFolder, filter, SearchOption.AllDirectories);
                foreach (string file in fileEntries)
                {
                    FileInfo fileInfo = new FileInfo(file);
                    if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        continue;
                    }

                    string fileRelativePath = WixHelperMethods.GetRelativePath(baseFolder, file);
                    if (!String.IsNullOrEmpty(fileRelativePath))
                    {
                        fileList.Add(fileRelativePath);
                    }
                }
            }

            if (folderList != null)
            {
                string[] folderEntries = Directory.GetDirectories(baseFolder, filter, SearchOption.AllDirectories);
                foreach (string folder in folderEntries)
                {
                    DirectoryInfo folderInfo = new DirectoryInfo(folder);
                    if ((folderInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        continue;
                    }

                    string folderRelativePath = WixHelperMethods.GetRelativePath(baseFolder, folder);
                    if (!String.IsNullOrEmpty(folderRelativePath))
                    {
                        folderList.Add(folderRelativePath);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Excludes the file and folder items from their corresponding maps if they are part of the build.
        /// </summary>
        /// <param name="project">The project to modify.</param>
        /// <param name="fileList">List containing relative files paths.</param>
        /// <param name="folderList">List containing relative folder paths.</param>
        private static void ExcludeProjectBuildItems(WixProjectNode project, IList <string> fileList, IList <string> folderList)
        {
            if (project.BuildProject.Items == null)
            {
                return; // do nothig, just ignore it.
            }
            else if (fileList == null && folderList == null)
            {
                throw new ArgumentNullException("folderList");
            }

            // we need these maps becuase we need to have both lowercase and actual case path information.
            // we use lower case paths for case-insesitive search of file entries and actual paths for
            // creating hierarchy node. if we don't do that, we will end up with duplicate nodes when the
            // case of path in .wixproj file doesn't match with the actual file path on the disk.
            IDictionary <string, string> folderMap = null;
            IDictionary <string, string> fileMap   = null;

            if (folderList != null)
            {
                folderMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (string folder in folderList)
                {
                    folderMap.Add(folder, folder);
                }
            }

            if (fileList != null)
            {
                fileMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (string file in fileList)
                {
                    fileMap.Add(file, file);
                }
            }

            foreach (ProjectItem buildItem in project.BuildProject.Items)
            {
                if (folderMap != null &&
                    folderMap.Count > 0 &&
                    String.Equals(buildItem.ItemType, ProjectFileConstants.Folder, StringComparison.OrdinalIgnoreCase))
                {
                    string relativePath = buildItem.EvaluatedInclude;
                    if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative
                    {
                        relativePath = WixHelperMethods.GetRelativePath(project.ProjectFolder, relativePath);
                    }

                    if (folderMap.ContainsKey(relativePath))
                    {
                        folderList.Remove(folderMap[relativePath]); // remove it from the actual list.
                        folderMap.Remove(relativePath);
                    }
                }
                else if (fileMap != null &&
                         fileMap.Count > 0 &&
                         WixProjectMembers.IsWixFileItem(buildItem))
                {
                    string relativePath = buildItem.EvaluatedInclude;
                    if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative
                    {
                        relativePath = WixHelperMethods.GetRelativePath(project.ProjectFolder, relativePath);
                    }

                    if (fileMap.ContainsKey(relativePath))
                    {
                        fileList.Remove(fileMap[relativePath]); // remove it from the actual list.
                        fileMap.Remove(relativePath);
                    }
                }
            }
        }
示例#3
0
 /// <summary>
 /// Converts the path to relative (if it is absolute) to the project folder.
 /// </summary>
 /// <param name="path">Path to be made relative.</param>
 /// <returns>Path relative to the project folder.</returns>
 public virtual string GetRelativePath(string path)
 {
     return(WixHelperMethods.GetRelativePath(this.ProjectFolder, path));
 }