コード例 #1
0
        private void CreateXmlDataAndParseTree()
        {
            // Now simply format the XML Document and load it again
            mXmlData = FormatXMLData(LoadDataFromXML(mProjectFile + ".xml"));
            SaveDataToXML(mXmlData, mProjectFile + ".xml");
            XmlDocument document = new XmlDocument();

            try
            {
                // Load the XmlDocument with the xmlData
                ProgressMessage("Converting project '" + mProjectFile + "' to XML...");
                document.LoadXml(mXmlData);

                // 0. Get Project details
                ProgressMessage("Getting project details...");
                XmlNode projectNode = document.SelectSingleNode("/DeployProject");
                ProjectName = ElementValue(ref projectNode, "ProjectName");
                ProjectType = VdProduct.GetProjectTypeFromGUID(ElementValue(ref projectNode, "ProjectType"), VdProduct.AtrToBool(ElementValue(ref projectNode, "IsWebType")));
                XmlNode releaseNode = document.SelectSingleNode("/DeployProject/Configurations/Release");
                Output = ElementValue(ref releaseNode, "OutputFilename");
                if (String.IsNullOrEmpty(Output))
                {
                    releaseNode = document.SelectSingleNode("/DeployProject/Configurations/Debug");
                    Output      = ElementValue(ref releaseNode, "OutputFilename");
                }

                // 1. Get list of <Folder>
                ProgressMessage("Creating folders...");
                XmlNode documentFolderNode = document.SelectSingleNode("/DeployProject/Deployable/Folder");
                if (documentFolderNode != null && documentFolderNode.HasChildNodes)
                {
                    XmlNodeList foldersList = documentFolderNode.ChildNodes;
                    mFolders = new List <BaseFolder>(foldersList.Count);

                    for (int i = 0; i < foldersList.Count; i++)
                    {
                        VdFolder folder = new VdFolder(foldersList.Item(i), ref mFolders, null);
                        if (!String.IsNullOrEmpty(folder.Id))
                        {
                            mFolders.Add(folder);
                            // Is this [TARGETDIR] -> remember it
                            if (folder.Path == "[TARGETDIR]")
                            {
                                XmlNode defaultDirNode = foldersList.Item(i).SelectSingleNode("DefaultLocation");
                                DefaultDir = folder.Atribute(ref defaultDirNode, "value");
                            }
                        }
                    }
                }

                // 2. Get list of <File>
                ProgressMessage("Creating files...");
                XmlNode documentFileNode = document.SelectSingleNode(VdProduct.GetFilesNodeNameFromProjectType(ProjectType));
                if (documentFileNode != null && documentFileNode.HasChildNodes)
                {
                    XmlNodeList filesList = documentFileNode.ChildNodes;
                    mFiles = new List <BaseFile>(filesList.Count);

                    for (int i = 0; i < filesList.Count; i++)
                    {
                        VdFile file = new VdFile(filesList.Item(i));
                        if (!String.IsNullOrEmpty(file.Id))
                        {
                            mFiles.Add(file);
                        }
                    }
                }

                // 3. Get list of <Registry>
                ProgressMessage("Creating registry keys...");
                XmlNode documentRegistryNode = document.SelectSingleNode("/DeployProject/Deployable/Registry");
                if (documentRegistryNode != null && documentRegistryNode.HasChildNodes)
                {
                    XmlNodeList regKeyList = documentRegistryNode.ChildNodes;
                    mRegistryKeys = new List <BaseRegKey>(regKeyList.Count);
                    for (int i = 0; i < regKeyList.Count; i++)
                    {
                        try
                        {
                            var     root     = (RegRoot)Enum.Parse(typeof(RegRoot), regKeyList.Item(i).Name);
                            XmlNode keysNode = regKeyList.Item(i).SelectSingleNode("Keys");
                            for (int j = 0; j < keysNode.ChildNodes.Count; j++)
                            {
                                VdRegKey regKey = new VdRegKey(ref mRegistryKeys, root, string.Empty, keysNode.ChildNodes[j]);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                // 4. Get Installer details - different for each ProductType!
                ProgressMessage("Reading product details...");
                XmlNode documentProductNode = document.SelectSingleNode(VdProduct.GetInstallerNodeNameFromProjectType(ProjectType));
                mProduct = new VdProduct(documentProductNode);

                // 5. Get list of <Shortcut>
                ProgressMessage("Creating shortcuts...");
                XmlNode documentShortcutNode = document.SelectSingleNode("/DeployProject/Deployable/Shortcut");
                if (documentShortcutNode != null && documentShortcutNode.HasChildNodes)
                {
                    XmlNodeList shortcutsList = documentShortcutNode.ChildNodes;
                    mShortcuts = new List <BaseShortcut>(shortcutsList.Count);

                    for (int i = 0; i < shortcutsList.Count; i++)
                    {
                        VdShortcut shortcut = new VdShortcut(shortcutsList.Item(i));
                        if (!String.IsNullOrEmpty(shortcut.Id))
                        {
                            mShortcuts.Add(shortcut);
                        }
                    }
                }

                // 6. Get list of OtherType (e.g. ProjectOutput, ...)
                ProgressMessage("Reading other files...");
                XmlNode projectOutputNode = document.SelectSingleNode("/DeployProject/Deployable/ProjectOutput");
                if (projectOutputNode != null && projectOutputNode.HasChildNodes)
                {
                    XmlNodeList projectOutputList = projectOutputNode.ChildNodes;
                    mOtherTypeObjects = new List <BaseOtherType>(projectOutputList.Count);

                    for (int i = 0; i < projectOutputList.Count; i++)
                    {
                        VdOtherType projectOutput = new VdOtherType(projectOutputList.Item(i), OtherType.ProjectOutput);
                        if (!String.IsNullOrEmpty(projectOutput.Id))
                        {
                            mOtherTypeObjects.Add(projectOutput);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
ファイル: VdFolder.cs プロジェクト: tSlappy/setupconverter
        public VdFolder(XmlNode folderNode, ref List <BaseFolder> allFolders, VdFolder parentFolder)
        {
            mFolders = allFolders;

            // Create this
            Id = folderNode.Name;
            XmlNode propertyNode = folderNode.SelectSingleNode("Property");
            XmlNode nameNode     = folderNode.SelectSingleNode("Name");
            string  property     = PropertyReference.CheckFolderProperty(Atribute(ref propertyNode, "value"));
            string  name         = Atribute(ref nameNode, "value");

            // Now resolve Path for this folder
            if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(property))
            {
                if (name[0] == '#' && property[0] != '_')
                {
                    // Use <Property value
                    if (parentFolder == null)
                    {
                        Path = property;
                    }
                    else
                    {
                        Path = parentFolder.Path + "\\" + Path;
                    }
                }
                else
                {
                    // Use <Name value
                    if (parentFolder == null)
                    {
                        Path = name;
                    }
                    else
                    {
                        Path = parentFolder.Path + "\\" + name;
                    }
                }
            }
            if (!String.IsNullOrEmpty(Path))
            {
                if (Path.Contains(coTargetDir))
                {
                    IsAppDir = true;
                }
            }


            // Add sub-folders for this (recursively)
            XmlNode documentFolderNode = folderNode.SelectSingleNode("Folders");

            if (documentFolderNode.HasChildNodes)
            {
                XmlNodeList foldersList = documentFolderNode.ChildNodes;
                for (int i = 0; i < foldersList.Count; i++)
                {
                    VdFolder folder = new VdFolder(foldersList.Item(i), ref mFolders, this);
                    mFolders.Add(folder);
                }
            }
        }