コード例 #1
0
ファイル: ParseHelper.cs プロジェクト: slamj1/Core-4
        private Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
        {
            Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet;
            string value = this.GetAttributeValue(sourceLineNumbers, attribute);

            if (0 < value.Length)
            {
                registryRoot = Wix.Enums.ParseRegistryRootType(value);

                if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot))
                {
                    // TODO: Find a way to expose the valid values programatically!
                    if (allowHkmu)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
                                                                                 "HKMU", "HKCR", "HKCU", "HKLM", "HKU"));
                    }
                    else
                    {
                        this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
                                                                                 "HKCR", "HKCU", "HKLM", "HKU"));
                    }
                }
            }

            return(registryRoot);
        }
コード例 #2
0
ファイル: ParseHelper.cs プロジェクト: slamj1/Core-4
        public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
        {
            Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu);

            switch (registryRoot)
            {
            case Wix.RegistryRootType.NotSet:
                return(CompilerConstants.IntegerNotSet);

            case Wix.RegistryRootType.HKCR:
                return(Core.Native.MsiInterop.MsidbRegistryRootClassesRoot);

            case Wix.RegistryRootType.HKCU:
                return(Core.Native.MsiInterop.MsidbRegistryRootCurrentUser);

            case Wix.RegistryRootType.HKLM:
                return(Core.Native.MsiInterop.MsidbRegistryRootLocalMachine);

            case Wix.RegistryRootType.HKU:
                return(Core.Native.MsiInterop.MsidbRegistryRootUsers);

            case Wix.RegistryRootType.HKMU:
                // This is gross, but there was *one* registry root parsing instance
                // (in Compiler.ParseRegistrySearchElement()) that did not explicitly
                // handle HKMU and it fell through to the default error case. The
                // others treated it as -1, which is what we do here.
                if (allowHkmu)
                {
                    return(-1);
                }
                break;
            }

            return(CompilerConstants.IntegerNotSet);
        }
コード例 #3
0
        /// <summary>
        /// Converts the registry key to a WiX component element.
        /// </summary>
        /// <param name="sr">The registry file stream.</param>
        /// <param name="directory">A WiX directory reference.</param>
        /// <param name="root">The root key.</param>
        /// <param name="line">The current line.</param>
        private void ConvertKey(StreamReader sr, ref Wix.Directory directory, Wix.RegistryRootType root, string line)
        {
            Wix.Component component = new Wix.Component();

            component.Id      = this.Core.GenerateIdentifier(ComponentPrefix, line);
            component.KeyPath = Wix.YesNoType.yes;

            this.ConvertValues(sr, ref component, root, line);
            directory.AddChild(component);
        }
コード例 #4
0
        /// <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);
        }