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); }
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); } }