void INvnControl.Build()
        {
            MsiBuilder.EnvironmentComponents.Clear();

            foreach (EnvironmentVariable envVariable in environmentVaribaleItems.Items)
            {
                // create component node for each key
                Wix.Component component = new Wix.Component();
                component.Id   = Common.GetId();
                component.Guid = Guid.NewGuid().ToString();
                // add this component to install directory
                MsiBuilder.EnvironmentComponents.Add(component);

                Wix.Environment environment = new Wix.Environment();
                environment.Id = envVariable.Id;
                environment.ActionSpecified    = true;
                environment.Action             = envVariable.Action;
                environment.Name               = envVariable.Name;
                environment.PermanentSpecified = true;
                environment.Permanent          = envVariable.Permanent ? Wix.YesNoType.yes : Wix.YesNoType.no;
                environment.SystemSpecified    = true;
                environment.System             = envVariable.SystemEnvironmentVariable ? Wix.YesNoType.yes : Wix.YesNoType.no;
                environment.Value              = envVariable.Value;
                environment.Separator          = ";";
                environment.Part               = Wix.EnvironmentPart.last;
                environment.PartSpecified      = true;

                component.Items = new object[] { environment };
                // Set component ref in FeatureNode
                Support.SetComponentRef(component, envVariable.Feature);
            }
        }
예제 #2
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);
        }
예제 #3
0
 public static void SetComponentRef(Wix.Component component, FeatureProperty componentFeature)
 {
     // Define component Ref
     Wix.ComponentRef componentRef = new Wix.ComponentRef();
     componentRef.Id = component.Id;
     // get the proper property... i,e defualt if feature is not assigned or assifned feature
     WixClasses.Feature applicableFeature = null;
     if (componentFeature == null)
     {
         // use default feature
         applicableFeature = MsiBuilder.FeatureTable[Common.DefaultFeature.Id];
     }
     else
     {
         applicableFeature = MsiBuilder.FeatureTable[componentFeature.Id];
     }
     // create ComponentRef node
     if (applicableFeature != null)
     {
         // Add new component Ref to feature node
         applicableFeature.Items = Common.AddItemToArray(applicableFeature.Items, componentRef);
     }
 }
예제 #4
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
            }
        }
예제 #5
0
        private void SetRegistries(TreeNode keyNode, string root)
        {
            //CreateKeyNode(keyNode, root);

            // create all registry VALUES
            List <RegistryValue> values = (List <RegistryValue>)keyNode.Tag;

            if (values != null)
            {
                foreach (RegistryValue value in values)
                {
                    // create component node for each key
                    Wix.Component component = new Wix.Component();
                    component.Id             = Common.GetId();
                    component.Guid           = Guid.NewGuid().ToString();
                    component.Win64Specified = true;
                    component.Win64          = (value.Win64 ? Wix.YesNoType.yes : Wix.YesNoType.no);
                    // add this component to install directory
                    MsiBuilder.RegistryComponents.Add(component);

                    Wix.Registry registry = new Wix.Registry();
                    registry.ActionSpecified = true;
                    registry.Action          = Wix.RegistryAction.write;
                    registry.Id   = value.Id;
                    registry.Key  = GetKey(keyNode);
                    registry.Name = value.Name;
                    //TODO: type looks inconsistant
                    registry.TypeSpecified = true;
                    registry.Type          = value.Type;
                    if (value is RegistrySingleValue)
                    {
                        registry.Value = ((RegistrySingleValue)value).Value;
                    }
                    else if (value is RegistryMultipleValue)
                    {
                        string[] regValues = ((RegistryMultipleValue)value).Value;
                        registry.Items = Common.AddItemToArray(registry.Items, regValues);
                    }
                    registry.RootSpecified = true;
                    switch (root)
                    {
                    case HKCR:
                        registry.Root = Wix.RegistryRoot.HKCR; break;

                    case HKCU:
                        registry.Root = Wix.RegistryRoot.HKCU; break;

                    case HKLM:
                        registry.Root = Wix.RegistryRoot.HKLM; break;

                    //case HKMU:
                    //    registry.Root = Wix.RegistryRoot.HKMU; break;
                    case HKU:
                        registry.Root = Wix.RegistryRoot.HKU; break;
                    }

                    component.Items = new object[] { registry };
                    // Set component ref in FeatureNode
                    Support.SetComponentRef(component, value.Feature);
                }
            }
            // loop through child nodes
            foreach (TreeNode node in keyNode.Nodes)
            {
                SetRegistries(node, root);
            }
        }