WixSharp.Project.FindDir C# (CSharp) Method

FindDir() public method

Finds T:WixSharp.Dir corresponding to the specified path. new Project("MyProduct", new Dir("%ProgramFiles%", new Dir("My Company", new Dir("My Product", ... In the sample above the call FindDir(@"%ProgramFiles%\My Company\My Product") returns the last declared T:WixSharp.Dir.
public FindDir ( string path ) : Dir
path string The path string.
return Dir
        public Dir FindDir(string path)
        {
            int iterator = 0;
            var dirList = new List<Dir>();
            int tokenIndex = 0;
            string[] pathTokens = path.Split("\\/".ToCharArray());

            dirList.AddRange(Dirs);

            while (iterator < dirList.Count)
            {
                string dirName = dirList[iterator].Name.Expand().ToLower();
                string currentSubDir = pathTokens[tokenIndex].Expand().ToLower();
                if (dirName == currentSubDir)
                {
                    if (tokenIndex == pathTokens.Length - 1)
                        return dirList[iterator];

                    dirList.AddRange(dirList[iterator].Dirs);
                    tokenIndex++;
                }
                iterator++;
            }

            return null;
        }

Usage Example

Example #1
0
File: Dir.cs Project: ygel/wixsharp
        internal Dir(Feature feature, string targetPath, Project project)
        {
            this.Feature = feature;

            //create nested Dirs on-fly but reuse already existing ones in the project
            var nestedDirs = targetPath.Split("\\/".ToCharArray());

            Dir    lastFound    = null;
            string lastMatching = null;

            string[] flatTree = ToFlatPathTree(targetPath);

            foreach (string path in flatTree)
            {
                var existingDir = project.FindDir(path);
                if (existingDir != null)
                {
                    lastFound    = existingDir;
                    lastMatching = path;
                }
                else
                {
                    if (lastFound != null)
                    {
                        Dir currDir = lastFound;

                        string[] newSubDirs = targetPath.Substring(lastMatching.Length + 1).Split("\\/".ToCharArray());
                        for (int i = 0; i < newSubDirs.Length; i++)
                        {
                            Dir nextSubDir = new Dir(feature, newSubDirs[i]);
                            currDir.Dirs = new Dir[] { nextSubDir };
                            currDir      = nextSubDir;
                        }

                        currDir.Feature = feature;
                    }
                    else
                    {
                        lastDir         = ProcessTargetPath(targetPath, feature);
                        lastDir.Feature = feature;
                    }
                    break;
                }
            }
        }
All Usage Examples Of WixSharp.Project::FindDir