/// <summary> /// Creates the shim component. /// </summary> /// <returns>Component for the shim.</returns> private Wix.Component GenerateShimComponent() { Wix.Component shimComponent = new Wix.Component(); if (Guid.Empty == this.shimGuid) { this.shimGuid = Guid.NewGuid(); } shimComponent.Id = "ThisApplicationShimDllComponent"; shimComponent.Guid = this.shimGuid.ToString("B"); Wix.File file = new Wix.File(); file.Id = "ThisApplicationShimDll"; file.Name = String.Concat(Path.GetFileNameWithoutExtension(this.entryFileRelativePath), "Shim.dll"); file.Vital = Wix.YesNoType.yes; file.KeyPath = Wix.YesNoType.yes; file.Source = this.shimPath; shimComponent.AddChild(file); // Add the CLSID and ProgId to the component. Wix.Class classId = new Wix.Class(); classId.Id = this.ShimClsid.ToString("B"); classId.Context = Wix.Class.ContextType.InprocServer32; if (null != this.Description && String.Empty != this.Description) { classId.Description = this.Description; } classId.ThreadingModel = Wix.Class.ThreadingModelType.apartment; file.AddChild(classId); Wix.ProgId progId = new Wix.ProgId(); progId.Id = this.ShimProgid; progId.Description = "Connect Class"; classId.AddChild(progId); // Add the Addin to the extended Office applications. foreach (OfficeAddinFabricator.OfficeApplications extendedOfficeApp in this.extendedOfficeApplications) { Wix.RegistryKey registryKey = new Wix.RegistryKey(); registryKey.Root = Wix.RegistryRootType.HKMU; registryKey.Key = String.Format("Software\\Microsoft\\Office\\{0}\\Addins\\{1}", OfficeAddinFabricator.OfficeApplicationStrings[(int)extendedOfficeApp], this.ShimProgid); shimComponent.AddChild(registryKey); Wix.RegistryValue registryValue = new Wix.RegistryValue(); registryValue.Name = "Description"; registryValue.Value = "[ProductName] v[ProductVersion]"; registryValue.Type = Wix.RegistryValue.TypeType.@string; registryKey.AddChild(registryValue); registryValue = new Wix.RegistryValue(); registryValue.Name = "FriendlyName"; registryValue.Value = "[ProductName]"; registryValue.Type = Wix.RegistryValue.TypeType.@string; registryKey.AddChild(registryValue); registryValue = new Wix.RegistryValue(); registryValue.Name = "LoadBehavior"; registryValue.Value = "3"; registryValue.Type = Wix.RegistryValue.TypeType.integer; registryKey.AddChild(registryValue); } return(shimComponent); }
/// <summary> /// Converts the registry values to WiX regisry key element. /// </summary> /// <param name="sr">The registry file stream.</param> /// <param name="component">A WiX component reference.</param> /// <param name="root">The root key.</param> /// <param name="line">The current line.</param> private void ConvertValues(StreamReader sr, ref Wix.Component component, Wix.RegistryRootType root, string line) { string name = null; string value = null; Wix.RegistryValue.TypeType type; Wix.RegistryKey registryKey = new Wix.RegistryKey(); registryKey.Root = root; registryKey.Key = line; while (this.GetValue(sr, ref name, ref value, out type)) { Wix.RegistryValue registryValue = new Wix.RegistryValue(); ArrayList charArray; // Don't specifiy name for default attribute if (!string.IsNullOrEmpty(name)) { registryValue.Name = name; } registryValue.Type = type; switch (type) { case Wix.RegistryValue.TypeType.binary: registryValue.Value = value.Replace(",", string.Empty).ToUpper(); break; case Wix.RegistryValue.TypeType.integer: registryValue.Value = Int32.Parse(value, NumberStyles.HexNumber).ToString(); break; case Wix.RegistryValue.TypeType.expandable: charArray = this.ConvertCharList(value); value = string.Empty; // create the string, remove the terminating null for (int i = 0; i < charArray.Count; i++) { if ('\0' != (char)charArray[i]) { value += charArray[i]; } } registryValue.Value = value; break; case Wix.RegistryValue.TypeType.multiString: charArray = this.ConvertCharList(value); value = string.Empty; // Convert the character array to a string so we can simply split it at the nulls, ignore the final null null. for (int i = 0; i < (charArray.Count - 2); i++) { value += charArray[i]; } // Although the value can use [~] the preffered way is to use MultiStringValue string[] parts = value.Split("\0".ToCharArray()); foreach (string part in parts) { Wix.MultiStringValue multiStringValue = new Wix.MultiStringValue(); multiStringValue.Content = part; registryValue.AddChild(multiStringValue); } break; case Wix.RegistryValue.TypeType.@string: // Remove \\ and \" value = value.ToString().Replace("\\\"", "\""); value = value.ToString().Replace(@"\\", @"\"); // Escape [ and ] value = value.ToString().Replace(@"[", @"[\[]"); value = value.ToString().Replace(@"]", @"[\]]"); // This undoes the duplicate escaping caused by the second replace value = value.ToString().Replace(@"[\[[\]]", @"[\[]"); // Escape $ value = value.ToString().Replace(@"$", @"$$"); registryValue.Value = value; break; default: throw new ApplicationException(String.Format("Did not recognize the type of reg value on line {0}", this.currentLineNumber)); } registryKey.AddChild(registryValue); } // Make sure empty keys are created if (null == value) { registryKey.ForceCreateOnInstall = Wix.YesNoType.yes; } component.AddChild(registryKey); }