Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #3
0
        private void ImportFilesInComponent(TreeNode node, XmlNode componentNode, string[] files)
        {
            if (componentNode.Name == "Component")
            {
                bool mustExpand = (node.Nodes.Count == 0);

                CurrentTreeView.SuspendLayout();

                bool foundReg = false;
                foreach (string file in files)
                {
                    if (Path.GetExtension(file).ToLower() == ".reg")
                    {
                        foundReg = true;
                        break;
                    }
                }

                bool importRegistryFiles = false;
                if (foundReg == true)
                {
                    DialogResult result = MessageBox.Show(this, "Import Registry (*.reg) files to Registry elements?", "Import?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                    else if (result == DialogResult.Yes)
                    {
                        importRegistryFiles = true;
                    }
                }

                WixFiles.UndoManager.BeginNewCommandRange();
                StringBuilder errorMessageBuilder = new StringBuilder();

                foreach (string file in files)
                {
                    FileInfo fileInfo = new FileInfo(file);
                    try
                    {
                        if (fileInfo.Extension.ToLower() == ".reg" && importRegistryFiles)
                        {
                            RegistryImport regImport = new RegistryImport(WixFiles, fileInfo, componentNode);
                            regImport.Import(node);
                        }
                        else
                        {
                            FileImport fileImport = new FileImport(WixFiles, fileInfo, componentNode);
                            fileImport.Import(node);
                        }
                    }
                    catch (WixEditException ex)
                    {
                        errorMessageBuilder.AppendFormat("{0} ({1})\r\n", fileInfo.Name, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        string message = String.Format("An exception occured during the import of \"{0}\"! Please press OK to report this error to the WixEdit website, so this error can be fixed.", fileInfo.Name);
                        ExceptionForm form = new ExceptionForm(message, ex);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            ErrorReporter reporter = new ErrorReporter();
                            reporter.Report(ex);
                        }
                    }
                }

                if (errorMessageBuilder.Length > 0)
                {
                    MessageBox.Show(this, "Import failed for the following files:\r\n\r\n" + errorMessageBuilder.ToString(), "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ShowNode(componentNode);

                if (mustExpand)
                {
                    node.Expand();
                }

                CurrentTreeView.ResumeLayout();
            }
        }