Beispiel #1
0
        private void RecurseDirectories(string[] subFolders, TreeNode treeNode, XmlNode parentDirectoryElement)
        {
            foreach (string folder in subFolders)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(folder);

                if (FileImport.NeedToIgnore(dirInfo.Name))
                {
                    continue;
                }

                XmlElement newElement = parentDirectoryElement.OwnerDocument.CreateElement("Directory", WixFiles.WixNamespaceUri);

                newElement.SetAttribute("Id", FileImport.GenerateValidIdentifier(dirInfo.Name, newElement, wixFiles));

                newElement.SetAttribute(WixEditSettings.Instance.LongName, FileImport.GenerateValidLongName(dirInfo.Name));
                if (WixEditSettings.Instance.IsUsingWix2())
                {
                    newElement.SetAttribute(WixEditSettings.Instance.ShortName, FileImport.GenerateValidShortName(PathHelper.GetShortDirectoryName(dirInfo, wixFiles, parentDirectoryElement)));
                }

                TreeNode newNode = new TreeNode(newElement.GetAttribute(WixEditSettings.Instance.LongName));
                newNode.Tag = newElement;

                if (firstShowableNode == null)
                {
                    firstShowableNode = newNode;
                }

                int imageIndex = ImageListFactory.GetImageIndex("Directory");
                if (imageIndex >= 0)
                {
                    newNode.ImageIndex         = imageIndex;
                    newNode.SelectedImageIndex = imageIndex;
                }

                XmlNodeList sameNodes = parentDirectoryElement.SelectNodes("wix:Directory", wixFiles.WxsNsmgr);
                if (sameNodes.Count > 0)
                {
                    parentDirectoryElement.InsertAfter(newElement, sameNodes[sameNodes.Count - 1]);
                }
                else
                {
                    parentDirectoryElement.AppendChild(newElement);
                }

                treeNode.Nodes.Add(newNode);

                string[] subFiles = Directory.GetFiles(dirInfo.FullName);
                if (subFiles.Length > 0)
                {
                    FileImport.AddFiles(wixFiles, subFiles, newNode, newElement);
                }

                string[] subSubFolders = Directory.GetDirectories(dirInfo.FullName);
                RecurseDirectories(subSubFolders, newNode, newElement);
            }
        }
Beispiel #2
0
        public static void AddFiles(WixFiles wixFiles, string[] files, TreeNode treeNode, XmlNode parentDirectoryElement)
        {
            foreach (string file in files)
            {
                FileInfo fileInfo = new FileInfo(file);

                if (NeedToIgnore(fileInfo.Name))
                {
                    continue;
                }

                XmlElement newComponentElement = parentDirectoryElement.OwnerDocument.CreateElement("Component", WixFiles.WixNamespaceUri);

                newComponentElement.SetAttribute("Id", FileImport.GenerateValidIdentifier(fileInfo.Name, newComponentElement, wixFiles));
                newComponentElement.SetAttribute("DiskId", "1");
                newComponentElement.SetAttribute("Guid", Guid.NewGuid().ToString().ToUpper());

                parentDirectoryElement.AppendChild(newComponentElement);

                TreeNode newComponentNode = new TreeNode(newComponentElement.GetAttribute("Id"));
                newComponentNode.Tag = newComponentElement;

                int imageIndex = ImageListFactory.GetImageIndex("Component");
                if (imageIndex >= 0)
                {
                    newComponentNode.ImageIndex         = imageIndex;
                    newComponentNode.SelectedImageIndex = imageIndex;
                }

                treeNode.Nodes.Add(newComponentNode);

                XmlElement newFileElement = parentDirectoryElement.OwnerDocument.CreateElement("File", WixFiles.WixNamespaceUri);

                newFileElement.SetAttribute("Id", FileImport.GenerateValidIdentifier(fileInfo.Name, newFileElement, wixFiles));
                newFileElement.SetAttribute(WixEditSettings.Instance.LongName, FileImport.GenerateValidLongName(fileInfo.Name));
                if (WixEditSettings.Instance.IsUsingWix2())
                {
                    newFileElement.SetAttribute(WixEditSettings.Instance.ShortName, FileImport.GenerateValidShortName(PathHelper.GetShortFileName(fileInfo, wixFiles, newComponentElement)));
                }
                newFileElement.SetAttribute("Source", PathHelper.GetRelativePath(fileInfo.FullName, wixFiles));

                TreeNode newFileNode = new TreeNode(newFileElement.GetAttribute(WixEditSettings.Instance.LongName));
                newFileNode.Tag = newFileElement;

                imageIndex = ImageListFactory.GetImageIndex("File");
                if (imageIndex >= 0)
                {
                    newFileNode.ImageIndex         = imageIndex;
                    newFileNode.SelectedImageIndex = imageIndex;
                }

                XmlNodeList sameNodes = newComponentElement.SelectNodes("wix:File", wixFiles.WxsNsmgr);
                if (sameNodes.Count > 0)
                {
                    newComponentElement.InsertAfter(newFileElement, sameNodes[sameNodes.Count - 1]);
                }
                else
                {
                    newComponentElement.AppendChild(newFileElement);
                }

                newComponentNode.Nodes.Add(newFileNode);
            }
        }