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
コード例 #1
0
ファイル: Dir.cs プロジェクト: 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;
                }
            }
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: denis-peshkov/WixSharp
        static void ProcessDirectories(Project wProject, Dictionary<Feature, List<string>> featureComponents,
            List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement dirs)
        {
            wProject.ResolveWildCards();

            if (wProject.Dirs.Count() == 0)
            {
                //WIX/MSI does not like no-directory deployments thus create fake one
                string dummyDir = @"%ProgramFiles%\WixSharp\DummyDir";
                if (wProject.Platform == Platform.x64)
                    dummyDir = dummyDir.Map64Dirs();

                wProject.Dirs = new[] { new Dir(dummyDir) };
            }

            Dir[] wDirs = wProject.Dirs;

            //auto-assign INSTALLDIR id for installation directory (the first directory that has multiple items)
            if (wDirs.Count() != 0)
            {
                Dir firstDirWithItems = wDirs.First();

                string logicalPath = firstDirWithItems.Name;
                while (firstDirWithItems.Shortcuts.Count() == 0 &&
                       firstDirWithItems.Dirs.Count() == 1 &&
                       firstDirWithItems.Files.Count() == 0)
                {
                    firstDirWithItems = firstDirWithItems.Dirs.First();
                    logicalPath += "\\" + firstDirWithItems.Name;
                }

                if (!firstDirWithItems.IsIdSet() && !Compiler.AutoGeneration.InstallDirDefaultId.IsEmpty())
                {
                    firstDirWithItems.Id = Compiler.AutoGeneration.InstallDirDefaultId;
                    wProject.AutoAssignedInstallDirPath = logicalPath;
                }
            }

            foreach (Dir wDir in wDirs)
            {
                ProcessDirectory(wDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirs);
            }

            foreach (string dirPath in autogeneratedShortcutLocations.Keys)
            {
                Feature feature = autogeneratedShortcutLocations[dirPath];

                //be careful as some parts of the auto-generated director may already exist
                XElement existingParent = null;
                string dirToAdd = dirPath;
                string[] dirsToSearch = Dir.ToFlatPathTree(dirPath);
                foreach (string path in dirsToSearch)
                {
                    Dir d = wProject.FindDir(path);
                    if (d != null)
                    {
                        dirToAdd = dirPath.Substring(path.Length + 1);
                        existingParent = dirs.FindDirectory(path.ExpandWixEnvConsts());
                        break;
                    }
                }

                if (existingParent != null)
                {
                    Dir dir = new Dir(feature, dirToAdd);
                    ProcessDirectory(dir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, existingParent);
                }
                else
                {
                    Dir dir = new Dir(feature, dirPath);
                    ProcessDirectory(dir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirs);
                }
            }
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: denis-peshkov/WixSharp
        static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents,
            List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement parent)
        {
            XElement dirItem = AddDir(parent, wDir);

            if (wDir.Files.Count() == 0 && wDir.Shortcuts.Count() == 0 && wDir.Dirs.Count() == 0 && wDir.Permissions.Count() == 0)
            {
                var existingCompElement = dirItem.Elements("Component");

                if (existingCompElement.Count() == 0)
                {
                    string compId = wDir.Id + ".EmptyDirectory";

                    if (wDir.Feature != null)
                    {
                        featureComponents.Map(wDir.Feature, compId);
                    }
                    else
                    {
                        defaultFeatureComponents.Add(compId);
                    }

                    dirItem.AddElement(
                        new XElement("Component",
                            new XAttribute("Id", compId),
                            new XAttribute("Guid", WixGuid.NewGuid(compId))));
                }


                //insert MergeModules
                ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents);

                foreach (Dir subDir in wDir.Dirs)
                    ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem);

                return;
            }

            if (wDir.Feature != null)
            {
                string compId = "Component." + wDir.Id;
                featureComponents.Map(wDir.Feature, compId);
                dirItem.AddElement(
                        new XElement("Component",
                            new XAttribute("Id", compId),
                            new XAttribute("Guid", WixGuid.NewGuid(compId))));
            }

            #region Process Files

            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
                        new XElement("Shortcut",
                            new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id),
                            new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId),
                            new XAttribute("Directory", locationDirId),
                            new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk"));

                    wShortcut.EmitAttributes(shortcutElement);

                    file.Add(shortcutElement);
                }

                //insert file related IIS virtual directories
                InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject);

                //insert file owned permissions
                ProcessFilePermissions(wProject, wFile, file);
            }

            #endregion

            #region Process Shorcuts

            //insert directory owned shortcuts
            foreach (Shortcut wShortcut in wDir.Shortcuts)
            {
                string compId = wShortcut.Id;
                if (wShortcut.Feature != null)
                {
                    if (!featureComponents.ContainsKey(wShortcut.Feature))
                        featureComponents[wShortcut.Feature] = new List<string>();

                    featureComponents[wShortcut.Feature].Add(compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                   new XElement("Component",
                       new XAttribute("Id", compId),
                       new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wShortcut.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", wShortcut.Condition.ToCData())
                            .AddAttributes(wShortcut.Condition.Attributes));

                XElement sc;
                sc = comp.AddElement(
                   new XElement("Shortcut",
                       new XAttribute("Id", wDir.Id + "." + wShortcut.Id),
                    //new XAttribute("Directory", wDir.Id), //not needed for Wix# as this attributed is required only if the shortcut is not nested under a Component element.
                       new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : GetShortcutWorkingDirectopry(wShortcut.Target)),
                       new XAttribute("Target", wShortcut.Target),
                       new XAttribute("Arguments", wShortcut.Arguments),
                       new XAttribute("Name", wShortcut.Name + ".lnk")));

                wShortcut.EmitAttributes(sc);
            }


            #endregion

            //insert MergeModules
            ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents);

            ProcessDirPermissions(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);

            foreach (Dir subDir in wDir.Dirs)
                ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem);
        }
コード例 #4
0
ファイル: Dir.cs プロジェクト: Eun/WixSharp
        internal Dir(Feature feature, string targetPath, Project project)
        {
            //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(newSubDirs[i]);
                            currDir.Dirs = new Dir[] { nextSubDir };
                            currDir = nextSubDir;
                        }

                        currDir.Feature = feature;
                    }
                    else
                    {
                        Dir lastDir = ProcessTargetPath(targetPath);
                        lastDir.Feature = feature;
                    }
                    break;
                }
            }
        }
コード例 #5
0
ファイル: Compiler.cs プロジェクト: Eun/WixSharp
        static void ProcessDirectoryFiles(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                wFile.DriverInstaller.Compile(wProject, comp);

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
                        new XElement("Shortcut",
                            new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id),
                            new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId),
                            new XAttribute("Directory", locationDirId),
                            new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk"));

                    wShortcut.EmitAttributes(shortcutElement);

                    file.Add(shortcutElement);
                }

                //insert file related IIS virtual directories
                InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject);

                //insert file owned permissions
                ProcessFilePermissions(wProject, wFile, file);
            }
        }