コード例 #1
0
        private void CreateProgIdComponent(DataGridViewRow rowData)
        {
            ComponentNode exeData = (ComponentNode)((TreeNode)rowData.Tag).Tag;

            Wix.Component exeComponent = (Wix.Component)exeData.Property.WixNode;
            Wix.File      exeFile      = (Wix.File)exeComponent.Items[0];
            string        extenstion   = (string)rowData.Cells[extensionColumn.Name].Value;

            if (extenstion.StartsWith("."))
            {
                extenstion = extenstion.Remove(0, 1);
            }
            string regKey = Path.GetFileNameWithoutExtension(exeFile.Source) + "." + extenstion;

            //keyReg
            Wix.Registry reg1 = new Wix.Registry();
            reg1.Id     = regKey;
            reg1.Root   = Wix.RegistryRoot.HKCR; reg1.RootSpecified = true;
            reg1.Action = Wix.RegistryAction.write; reg1.ActionSpecified = true;
            reg1.Type   = Wix.RegistryType.@string; reg1.TypeSpecified = true;
            reg1.Key    = regKey;
            reg1.Value  = (string)rowData.Cells[DescriptionColumn.Name].Value;
            //reg1.KeyPath = Wix.YesNoType.yes; reg1.KeyPathSpecified = true;

            // command or application to run
            Wix.Registry reg2 = new Wix.Registry();
            reg2.Id     = regKey + ".command";
            reg2.Root   = Wix.RegistryRoot.HKCR; reg2.RootSpecified = true;
            reg2.Action = Wix.RegistryAction.write; reg2.ActionSpecified = true;
            reg2.Type   = Wix.RegistryType.@string; reg2.TypeSpecified = true;
            reg2.Key    = regKey + @"\shell\open\command";
            reg2.Value  = "\"[#" + exeFile.Id + "]\" \"%1\"";
            //default icon
            Wix.Registry reg3 = new Wix.Registry();
            reg3.Id     = regKey + ".icon";
            reg3.Root   = Wix.RegistryRoot.HKCR; reg3.RootSpecified = true;
            reg3.Action = Wix.RegistryAction.write; reg3.ActionSpecified = true;
            reg3.Type   = Wix.RegistryType.@string; reg3.TypeSpecified = true;
            reg3.Key    = regKey + @"\DefaultIcon";
            reg3.Value  = "\"[#" + exeFile.Id + "]\"";
            //.<extension> key
            Wix.Registry reg4 = new Wix.Registry();
            reg4.Id     = regKey + ".association";
            reg4.Root   = Wix.RegistryRoot.HKCR; reg4.RootSpecified = true;
            reg4.Action = Wix.RegistryAction.write; reg4.ActionSpecified = true;
            reg4.Type   = Wix.RegistryType.@string; reg4.TypeSpecified = true;
            reg4.Key    = "." + extenstion;
            reg4.Value  = regKey;

            object[] items = new object[4] {
                reg1, reg2, reg3, reg4
            };

            exeComponent.Items = Common.AddItemToArray(exeComponent.Items, items);
        }
コード例 #2
0
 private void SetShortcuts(Wix.File file, TreeNode cmpNode, TreeNode treeNode, Wix.Directory directory, ShortcutType type)
 {
     foreach (TreeNode shortcutNode in treeNode.Nodes)
     {
         ComponentNode componentNode = (ComponentNode)shortcutNode.Tag;
         if (componentNode.Type == ComponentType.Folder)
         {
             SetShortcuts(file, cmpNode, shortcutNode, (Wix.Directory)componentNode.Property.WixNode, type);
         }
         else if (componentNode.Type == ComponentType.File)
         {
             if (componentNode.Property == ((ComponentNode)cmpNode.Tag).Property)
             {
                 Wix.Shortcut shortcut = new Wix.Shortcut();
                 shortcut.Id        = Common.GetId();
                 shortcut.Directory = directory.Id;
                 if (type == ShortcutType.Desktop)
                 {
                     file.Items[1] = shortcut;
                 }
                 else if (type == ShortcutType.StartMenu)
                 {
                     file.Items[0] = shortcut;
                 }
                 shortcut.Name = Common.GetShortname(shortcutNode.Text);
                 if (shortcut.Name != shortcutNode.Text)
                 {
                     shortcut.LongName = shortcutNode.Text;
                 }
                 shortcut.WorkingDirectory = "INSTALLDIR";
                 //shortcut.Icon = new NvnInstaller.WixClasses.Icon(
                 shortcut.IconIndex = "0";
             }
         }
     }
 }
コード例 #3
0
        private void BuildWixDirectory(Wix.Directory rootDir, TreeNode treeNode, bool isShortcutDir)
        {
            rootDir.Items = new object[treeNode.Nodes.Count];
            for (int i = 0; i < treeNode.Nodes.Count; i++)
            {
                TreeNode      node          = treeNode.Nodes[i];
                ComponentNode componentNode = (ComponentNode)node.Tag;

                #region Folder
                if (componentNode.Type == ComponentType.Folder)
                {
                    // create Wix directory
                    Wix.Directory dir = new Wix.Directory();
                    dir.Id   = Common.GetId();
                    dir.Name = Common.GetShortname(node.Text);
                    componentNode.Property.WixNode = dir;
                    if (dir.Name != node.Text)
                    {
                        dir.LongName = node.Text;
                    }
                    // add directory to parent directory
                    rootDir.Items[i] = dir;
                    // loop again
                    BuildWixDirectory(dir, node, isShortcutDir);
                }
                #endregion

                #region File
                else if (isShortcutDir == false && componentNode.Type == ComponentType.File)
                {
                    // add component
                    Wix.Component component = new Wix.Component();
                    component.Id   = Common.GetId();
                    component.Guid = Guid.NewGuid().ToString();
                    componentNode.Property.WixNode = component;
                    // create file node
                    Wix.File file = new Wix.File();
                    file.Id   = componentNode.Property.Id;
                    file.Name = Common.GetShortname(node.Text);
                    if (file.Name != node.Text)
                    {
                        file.LongName = node.Text;
                    }
                    file.DiskId           = "1"; // Only one disk supported
                    file.Source           = componentNode.Property.SourcePath;
                    file.KeyPathSpecified = true;
                    file.KeyPath          = Wix.YesNoType.yes;
                    file.VitalSpecified   = true;
                    file.Vital            = componentNode.Property.Vital;
                    // add file to component
                    component.Items    = new Wix.File[1];
                    component.Items[0] = file;

                    file.Items = new object[2];
                    if (node.TreeView == tvComponents)
                    {
                        // look in Start Menu
                        SetShortcuts(file, node, tvShortcuts.Nodes[0], this.menuDirectory, ShortcutType.StartMenu);
                        // look in Desktop
                        SetShortcuts(file, node, tvShortcuts.Nodes[1], this.desktopDirectory, ShortcutType.Desktop);
                    }
                    // Set component ref in FeatureNode
                    Support.SetComponentRef(component, componentNode.Property.Feature);
                    // add component to Directory node
                    rootDir.Items[i] = component;
                }
                #endregion

                #region Assembly
                else if (isShortcutDir == false && componentNode.Type == ComponentType.Assembly)
                {
                    // add component
                    Wix.Component component = new Wix.Component();
                    component.Id   = Common.GetId();
                    component.Guid = Guid.NewGuid().ToString();
                    componentNode.Property.WixNode = component;
                    // create file node
                    Wix.File file = new Wix.File();
                    file.Id = componentNode.Property.Id;
                    FileInfo fileInfo     = new FileInfo(componentNode.Property.SourcePath);
                    string   assemblyName = node.Text.Remove(0, 10).Replace(']', ' ').Trim();
                    file.Name = Common.GetShortname(assemblyName);
                    if (file.Name != assemblyName)
                    {
                        file.LongName = assemblyName;
                    }
                    //Install assembly to GAC
                    file.AssemblySpecified = true;
                    file.Assembly          = Wix.FileAssembly.net;
                    file.DiskId            = "1"; // Only one disk supported
                    file.Source            = componentNode.Property.SourcePath;
                    file.KeyPathSpecified  = true;
                    file.KeyPath           = Wix.YesNoType.yes;
                    file.VitalSpecified    = true;
                    file.Vital             = componentNode.Property.Vital;
                    // add file to component
                    component.Items    = new Wix.File[1];
                    component.Items[0] = file;

                    file.Items = new object[2];
                    if (node.TreeView == tvComponents)
                    {
                        // look in Start Menu
                        SetShortcuts(file, node, tvShortcuts.Nodes[0], this.menuDirectory, ShortcutType.StartMenu);
                        // look in Desktop
                        SetShortcuts(file, node, tvShortcuts.Nodes[1], this.desktopDirectory, ShortcutType.Desktop);
                    }
                    // Set component ref in FeatureNode
                    Support.SetComponentRef(component, componentNode.Property.Feature);
                    // add component to Directory node
                    rootDir.Items[i] = component;
                }
                #endregion

                #region Service
                else if (isShortcutDir == false && componentNode.Type == ComponentType.Service)
                {
                    // create component object
                    Wix.Component component = new Wix.Component();
                    component.Id   = Common.GetId();
                    component.Guid = Guid.NewGuid().ToString();
                    componentNode.Property.WixNode = component;

                    component.Items = new object[3];
                    // Create File Node
                    Wix.File file = new Wix.File();
                    file.Id   = componentNode.Property.Id;
                    file.Name = Common.GetShortname(node.Text);
                    if (file.Name != node.Text)
                    {
                        file.LongName = node.Text;
                    }
                    file.Source           = componentNode.Property.SourcePath;
                    file.DiskId           = "1"; // Only one disk supported
                    file.KeyPathSpecified = true;
                    file.KeyPath          = Wix.YesNoType.yes;
                    // add file to component
                    component.Items[0] = file;
                    // create ServiceInstall node
                    Wix.ServiceInstall serviceInstall = new Wix.ServiceInstall();
                    serviceInstall.Id           = Common.GetId();
                    serviceInstall.Name         = componentNode.Property.ServiceProperty.Name == null ? node.Text : componentNode.Property.ServiceProperty.Name;
                    serviceInstall.DisplayName  = componentNode.Property.ServiceProperty.DisplayName == null ? node.Text : componentNode.Property.ServiceProperty.DisplayName;
                    serviceInstall.Type         = componentNode.Property.ServiceProperty.InstallType;
                    serviceInstall.Start        = componentNode.Property.ServiceProperty.InstallStart;
                    serviceInstall.ErrorControl = componentNode.Property.ServiceProperty.InstallErrorControl;
                    // add serviceInstall node to component node
                    component.Items[1] = serviceInstall;

                    // Create Service Control Nodes
                    Wix.ServiceControl serviceControl = new Wix.ServiceControl();
                    serviceControl.Id              = Common.GetId();
                    serviceControl.Name            = componentNode.Property.ServiceProperty.Name == null ? node.Text : componentNode.Property.ServiceProperty.Name;
                    serviceControl.StartSpecified  = true;
                    serviceControl.Start           = Wix.ServiceControlStart.install;
                    serviceControl.StopSpecified   = true;
                    serviceControl.Stop            = Wix.ServiceControlStop.uninstall;
                    serviceControl.RemoveSpecified = true;
                    serviceControl.Remove          = Wix.ServiceControlRemove.uninstall;
                    // add to component node
                    component.Items[2] = serviceControl;
                    // Set component ref in FeatureNode
                    Support.SetComponentRef(component, componentNode.Property.Feature);
                    // add component to Directory node
                    rootDir.Items[i] = component;
                }
                #endregion

                #region Internet Shortcut
                else if (componentNode.Type == ComponentType.InternetShortcut)
                {
                    /* Create file *.url in local folder with content like below
                     * [InternetShortcut]
                     * URL=http://www.google.com */
                    InternetShortcutProperty shortcutProperty = componentNode.Property.ShortcutProperty;
                    string urlFile = Globals.localFolder + node.Text + ".url";
                    using (TextWriter writer = new StreamWriter(urlFile)) {
                        writer.WriteLine("[InternetShortcut]");
                        writer.WriteLine("URL=" + shortcutProperty.URL);
                    }
                    // create component node in the respective shortcut directory
                    // add component
                    Wix.Component component = new Wix.Component();
                    component.Id   = Common.GetId();
                    component.Guid = Guid.NewGuid().ToString();

                    // create file node
                    Wix.File file = new Wix.File();
                    file.Id   = Common.GetId();
                    file.Name = Common.GetShortname(node.Text);
                    if (file.Name != node.Text)
                    {
                        file.LongName = node.Text + ".url";
                    }
                    file.DiskId           = "1"; // Only one disk supported
                    file.Source           = urlFile;
                    file.KeyPathSpecified = true;
                    file.KeyPath          = Wix.YesNoType.yes;
                    file.VitalSpecified   = true;
                    file.Vital            = NvnInstaller.WixClasses.YesNoType.yes;
                    // add file to component
                    component.Items    = new Wix.File[1];
                    component.Items[0] = file;

                    // Set component ref in FeatureNode
                    Support.SetComponentRef(component, shortcutProperty.Feature);
                    // add component to Directory node
                    rootDir.Items[i] = component;
                }
                #endregion
            }
        }