Exemple #1
0
        private void parseFilesButtonClick(object sender, EventArgs e)
        {
            releaseFilesInProjectDict.Clear();
            debugFilesInProjectDict.Clear();

            filesToAddDict.Clear();
            x1FilterDict.Clear();
            pcFilterDict.Clear();

            BasicXmlData projXml = new BasicXmlData();

            openXml(projFileName, ref projXml);

            parseProj(ref debugFilesInProjectDict, ref projXml, "Debug", "Win32");
            parseProj(ref releaseFilesInProjectDict, ref projXml, "Release", "Win32");

            BasicXmlData filtersXml = new BasicXmlData();

            openXml(filtersFileName, ref filtersXml);

            parseFilters(ref debugFilesInProjectDict, ref x1FilterDict, ref filtersXml, "Debug", "Win32");
            parseFilters(ref releaseFilesInProjectDict, ref x1FilterDict, ref filtersXml, "Release", "Win32");

            parseSrcFiles(ref filesToAddDict);
        }
Exemple #2
0
 void openXml(string fileName, ref BasicXmlData basicXmlData)
 {
     basicXmlData.doc = new XmlDocument();
     readXmlFromFile(fileName, ref basicXmlData.doc);
     basicXmlData.root = basicXmlData.doc.DocumentElement;
     basicXmlData.ns   = new XmlNamespaceManager(basicXmlData.doc.NameTable);
     basicXmlData.ns.AddNamespace("", "http://schemas.microsoft.com/developer/msbuild/2003");
 }
Exemple #3
0
        private void addNewFileToFilters(string fileName, ref BasicXmlData xml)
        {
            // 1. Define cpp or h
            bool isH = isHeader(fileName);

            string pcFolder = filesToAddDict[fileName];

            // find parent node to append to
            string prefix = "ItemGroup";
            string suffix = "";

            if (isH == true)
            {
                suffix = "ClInclude";
            }
            else
            {
                suffix = "ClCompile";
            }
            string xPath = prefix + @"/" + suffix;

            // get last added filter node
            List <XmlNode> fileNodesList = null;
            {
                string fileNodesXPath = xPath;

                XmlNodeList fileNodes = xml.root.SelectNodes(fileNodesXPath, xml.ns);
                fileNodesList = new List <XmlNode>(fileNodes.Cast <XmlNode>());
            }

            // Create a new node.
            XmlElement nodeFile = xml.doc.CreateElement(suffix); // ClCompile or ClInclude

            XmlAttribute attrInclude = xml.doc.CreateAttribute("Include");

            attrInclude.Value = fileName;
            nodeFile.Attributes.Append(attrInclude);

            XmlElement nodeFilter     = xml.doc.CreateElement("Filter");
            string     folderRelative = pcFolder.Replace(@"..\Classes\", "");

            nodeFilter.InnerText = folderRelative;

            nodeFile.AppendChild(nodeFilter);


            if (fileNodesList.Count > 0)
            {
                fileNodesList[0].ParentNode.AppendChild(nodeFile);
            }
        }
Exemple #4
0
        private void parseProj(ref SortedDictionary <string, string> dict, ref BasicXmlData xml, string projectConfiguration, string projectPlatform)
        {
            // src (cpp, c files)
            XmlNodeList cppFileNodes = xml.root.SelectNodes(cppFileSearchXpath, xml.ns);
            // headers (hpp, h files)
            XmlNodeList    hFileNodes = xml.root.SelectNodes(hFileSearchXpath, xml.ns);
            List <XmlNode> fileNodes  = new List <XmlNode>(cppFileNodes.Cast <XmlNode>());
            List <XmlNode> fileNodesH = new List <XmlNode>(hFileNodes.Cast <XmlNode>());

            fileNodes.AddRange(fileNodesH);

            foreach (XmlNode fileNode in fileNodes)
            {
                string fileName = fileNode.Attributes["Include"].Value;

                if (dict.ContainsKey(fileName) == false)
                {
                    dict.Add(fileName, "");
                }
            }
        }
Exemple #5
0
        private void addAllFilesButtonClick(object sender, EventArgs e)
        {
            if (filesToAddSortedByFilters.Count > 0)
            {
                {
                    // open vcxproj file
                    BasicXmlData projXml = new BasicXmlData();
                    openXml(projFileName, ref projXml);

                    // open filters file
                    BasicXmlData filtersXml = new BasicXmlData();
                    openXml(filtersFileName, ref filtersXml);

                    makeNewFoldersAvailable(ref projXml, ref filtersXml);
                    removeSampleFilesReferences(ref projXml, ref filtersXml);

                    foreach (var kv in filesToAddSortedByFilters)
                    {
                        foreach (string file in kv.Value)
                        {
                            addNewFileToProj(file, ref projXml);
                            addNewFileToFilters(file, ref filtersXml);
                        }
                    }

                    writeXmlToFile(projFileName, ref projXml.doc);
                    writeXmlToFile(filtersFileName, ref filtersXml.doc);

                    projXml.doc    = null;
                    filtersXml.doc = null;
                }

                correctNameSpace(projFileName);
                correctNameSpace(filtersFileName);
            }
        }
Exemple #6
0
        private void removeSampleFilesReferences(ref BasicXmlData projXml, ref BasicXmlData filtersXml)
        {
            List <string> filesToRemove = new List <string>();

            filesToRemove.Add(@"..\Classes\AppDelegate.cpp");
            filesToRemove.Add(@"..\Classes\HelloWorldScene.cpp");
            filesToRemove.Add(@"..\Classes\AppDelegate.h");
            filesToRemove.Add(@"..\Classes\HelloWorldScene.h");

            foreach (string fileName in filesToRemove)
            {
                string xPath = constructXpathForFileName(fileName);

                // project
                {
                    XmlNodeList    foundFileNodes     = projXml.root.SelectNodes(xPath, projXml.ns);
                    List <XmlNode> foundFileNodesList = new List <XmlNode>(foundFileNodes.Cast <XmlNode>());

                    foreach (XmlNode node in foundFileNodesList)
                    {
                        node.ParentNode.RemoveChild(node);
                    }
                }

                // filters
                {
                    XmlNodeList    foundFileNodes     = filtersXml.root.SelectNodes(xPath, filtersXml.ns);
                    List <XmlNode> foundFileNodesList = new List <XmlNode>(foundFileNodes.Cast <XmlNode>());

                    foreach (XmlNode node in foundFileNodesList)
                    {
                        node.ParentNode.RemoveChild(node);
                    }
                }
            }
        }
Exemple #7
0
        private void addExtraSecondLevelBehaviorFolder(ref BasicXmlData filtersXml)
        {
            Guid   guid   = Guid.NewGuid();
            string filter = @"..\Classes\BehaviorTree";

            string guidStr = "{" + guid.ToString().ToUpper() + "}";

            // Create a new node.
            XmlElement nodeFilter = filtersXml.doc.CreateElement("Filter");

            XmlAttribute attrInclude        = filtersXml.doc.CreateAttribute("Include");
            string       relativeFolderName = filter.Replace(@"..\Classes\", "");

            attrInclude.Value = relativeFolderName;
            nodeFilter.Attributes.Append(attrInclude);

            XmlElement nodeUniqueIdentifier = filtersXml.doc.CreateElement("UniqueIdentifier");

            nodeUniqueIdentifier.InnerText = guidStr;

            nodeFilter.AppendChild(nodeUniqueIdentifier);

            // get last added filter node
            List <XmlNode> folderNodesList = null;

            {
                string folderNodesXPath = @"ItemGroup/Filter";

                XmlNodeList folderNodes = filtersXml.root.SelectNodes(folderNodesXPath, filtersXml.ns);
                folderNodesList = new List <XmlNode>(folderNodes.Cast <XmlNode>());
            }
            if (folderNodesList.Count > 0)
            {
                folderNodesList[0].ParentNode.AppendChild(nodeFilter);
            }
        }
Exemple #8
0
        private void makeNewFoldersAvailable(ref BasicXmlData projXml, ref BasicXmlData filtersXml)
        {
            if (filesToAddSortedByFilters.Count > 0)
            {
                // remove src filter from folders
                List <XmlNode> srcFolderNodesList = null;
                {
                    string prefix         = @"ItemGroup/Filter[@Include = """;
                    string suffix         = @"""]";
                    string srcFolderXPath = prefix + @"src" + suffix;

                    XmlNodeList srcFolderNodes = filtersXml.root.SelectNodes(srcFolderXPath, filtersXml.ns);
                    srcFolderNodesList = new List <XmlNode>(srcFolderNodes.Cast <XmlNode>());
                }
                if (srcFolderNodesList.Count == 1)
                {
                    srcFolderNodesList[0].ParentNode.RemoveChild(srcFolderNodesList[0]);
                }

                addExtraSecondLevelBehaviorFolder(ref filtersXml);

                string toAddToProj = "";
                Guid   guid;
                foreach (var kv in filesToAddSortedByFilters)
                {
                    string filter = kv.Key;
                    toAddToProj += (filter + ";");

                    // generate next unique id
                    guid = Guid.NewGuid();

                    string guidStr = "{" + guid.ToString().ToUpper() + "}";

                    // Create a new node.
                    XmlElement nodeFilter = filtersXml.doc.CreateElement("Filter");

                    XmlAttribute attrInclude        = filtersXml.doc.CreateAttribute("Include");
                    string       relativeFolderName = filter.Replace(@"..\Classes\", "");
                    attrInclude.Value = relativeFolderName;
                    nodeFilter.Attributes.Append(attrInclude);

                    XmlElement nodeUniqueIdentifier = filtersXml.doc.CreateElement("UniqueIdentifier");
                    nodeUniqueIdentifier.InnerText = guidStr;

                    nodeFilter.AppendChild(nodeUniqueIdentifier);

                    // get last added filter node
                    List <XmlNode> folderNodesList = null;
                    {
                        string folderNodesXPath = @"ItemGroup/Filter";

                        XmlNodeList folderNodes = filtersXml.root.SelectNodes(folderNodesXPath, filtersXml.ns);
                        folderNodesList = new List <XmlNode>(folderNodes.Cast <XmlNode>());
                    }
                    if (folderNodesList.Count > 0)
                    {
                        folderNodesList[0].ParentNode.AppendChild(nodeFilter);
                    }
                }

                // add string to proj

                // Debug
                // <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
                // ClCompile
                // AdditionalIncludeDirectories
                //
                // insert before @"%(AdditionalIncludeDirectories);" string
                List <XmlNode> debugIncludeDirsNodesList = null;
                {
                    string      debugIncludeDirsXPath = @"ItemDefinitionGroup[@Condition=""" + @"'$(Configuration)|$(Platform)'=='Debug|Win32'""" + @"]/ClCompile/AdditionalIncludeDirectories";
                    XmlNodeList debugIncludeDirsNodes = projXml.root.SelectNodes(debugIncludeDirsXPath, projXml.ns);
                    debugIncludeDirsNodesList = new List <XmlNode>(debugIncludeDirsNodes.Cast <XmlNode>());
                }
                if (debugIncludeDirsNodesList.Count == 1)
                {
                    string innerText = debugIncludeDirsNodesList[0].InnerText;
                    innerText = innerText.Replace(@"%(AdditionalIncludeDirectories);", toAddToProj + @"%(AdditionalIncludeDirectories);");
                    debugIncludeDirsNodesList[0].InnerText = innerText;
                }

                // Release
                List <XmlNode> releaseIncludeDirsNodesList = null;
                {
                    string      releaseIncludeDirsXPath = @"ItemDefinitionGroup[@Condition=""" + @"'$(Configuration)|$(Platform)'=='Release|Win32'""" + @"]/ClCompile/AdditionalIncludeDirectories";
                    XmlNodeList releaseIncludeDirsNodes = projXml.root.SelectNodes(releaseIncludeDirsXPath, projXml.ns);
                    releaseIncludeDirsNodesList = new List <XmlNode>(releaseIncludeDirsNodes.Cast <XmlNode>());
                }
                if (releaseIncludeDirsNodesList.Count == 1)
                {
                    string innerText = releaseIncludeDirsNodesList[0].InnerText;
                    innerText = innerText.Replace(@"%(AdditionalIncludeDirectories);", toAddToProj + @"%(AdditionalIncludeDirectories);");
                    releaseIncludeDirsNodesList[0].InnerText = innerText;
                }
            }
        }
Exemple #9
0
        private void addNewFileToProj(string fileName, ref BasicXmlData xml)
        {
            // 1. Define cpp or h
            bool isH = isHeader(fileName);

            string pcFolder = filesToAddDict[fileName];

            // find parent node to append to
            string prefix = "ItemGroup";
            string suffix = "";

            if (isH == true)
            {
                suffix = "ClInclude";
            }
            else
            {
                suffix = "ClCompile";
            }
            string xPath = prefix + @"/" + suffix;

            // get last added filter node
            List <XmlNode> fileNodesList = null;
            {
                string fileNodesXPath = xPath;

                XmlNodeList fileNodes = xml.root.SelectNodes(fileNodesXPath, xml.ns);
                fileNodesList = new List <XmlNode>(fileNodes.Cast <XmlNode>());
            }


            // Create a new node.
            XmlElement nodeFile = xml.doc.CreateElement(suffix); // ClCompile or ClInclude

            XmlAttribute attrInclude = xml.doc.CreateAttribute("Include");

            attrInclude.Value = fileName;
            nodeFile.Attributes.Append(attrInclude);

            if (fileNodesList.Count > 0)
            {
                fileNodesList[0].ParentNode.AppendChild(nodeFile);
            }


            // the fileName to add after
            string lastFileName = "";

            // 2. Define if there are already files in the same folder
            bool isPcFolderPresentOnX1 = x1FilterDict.ContainsKey(pcFolder);

            if (isPcFolderPresentOnX1 == true)
            {
                // 3. If there are ==> append
                List <string> allFilesInFolder = new List <string>();

                foreach (KeyValuePair <string, string> entry in releaseFilesInProjectDict)
                {
                    if (entry.Value == pcFolder)
                    {
                        // remember fileName
                        allFilesInFolder.Add(entry.Key);
                    }
                }
                // select all nodes (they should be in order)
                // discard (remove) mismatches
                // take the last (order should be preserved then)
                if (allFilesInFolder.Count > 0)
                {
                    // take the last one
                    string candidate = "";
                    for (int i = allFilesInFolder.Count - 1; i >= 0; --i)
                    {
                        candidate = allFilesInFolder[i];
                        if (isHeader(candidate) == isH)
                        {
                            // match
                            break;
                        }
                    }
                    if (candidate == "")
                    {
                        // not found any appropriate
                        lastFileName = getLastFileInProj(true, isH);
                    }
                    else
                    {
                        // found
                        lastFileName = candidate;
                    }
                }
                else
                {
                    // we should not be there
                }
            }
            else
            {
                // 4.2. Append file to the end of all file list in proj
                lastFileName = getLastFileInProj(true, isH);
            }
        }
Exemple #10
0
        private void parseFilters(ref SortedDictionary <string, string> dict, ref SortedDictionary <string, List <XmlNode> > filterDict, ref BasicXmlData xml, string projectConfiguration, string projectPlatform)
        {
            // src (cpp, c files)
            XmlNodeList cppFileNodes = xml.root.SelectNodes(cppFileSearchXpath, xml.ns);
            // headers (hpp, h files)
            XmlNodeList    hFileNodes = xml.root.SelectNodes(hFileSearchXpath, xml.ns);
            List <XmlNode> fileNodes  = new List <XmlNode>(cppFileNodes.Cast <XmlNode>());
            List <XmlNode> fileNodesH = new List <XmlNode>(hFileNodes.Cast <XmlNode>());

            fileNodes.AddRange(fileNodesH);

            foreach (XmlNode fileNode in fileNodes)
            {
                string fileName   = fileNode.Attributes["Include"].Value;
                string folderName = "";

                if (fileNode.HasChildNodes == true)
                {
                    XmlNode filterNode = fileNode.SelectSingleNode("Filter");
                    folderName = filterNode.InnerText;
                }

                if (dict.ContainsKey(fileName) == false)
                {
                    dict.Add(fileName, folderName);
                }
            }

            XmlNodeList    filterNodes     = xml.root.SelectNodes("ItemGroup/Filter[@Include]", xml.ns);
            List <XmlNode> filterNodesList = new List <XmlNode>(filterNodes.Cast <XmlNode>());

            filterDict.Clear();
            foreach (XmlNode filterNode in filterNodesList)
            {
                string filterName = filterNode.Attributes["Include"].Value;

                List <XmlNode> filterProps = null;

                if (filterNode.HasChildNodes == true)
                {
                    XmlNodeList xmlNodeList = filterNode.ChildNodes;
                    filterProps = new List <XmlNode>(xmlNodeList.Cast <XmlNode>());
                }
                filterDict.Add(filterName, filterProps);
            }
        }