Esempio n. 1
0
        /// <summary>
        /// Gets or sets the string value of a named installer property, as maintained by the
        /// Session object in the in-memory Property table, or, if it is prefixed with a percent
        /// sign (%), the value of a system environment variable for the current process.
        /// </summary>
        /// <exception cref="InvalidHandleException">the Session handle is invalid</exception>
        /// <remarks><p>
        /// Win32 MSI APIs:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msigetproperty.asp">MsiGetProperty</a>,
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msisetproperty.asp">MsiSetProperty</a>
        /// </p></remarks>
        public string this[string property]
        {
            get
            {
                if (string.IsNullOrWhiteSpace(property))
                {
                    throw new ArgumentNullException("property");
                }

                if (!this.sessionAccessValidated &&
                    !Session.NonImmediatePropertyNames.Contains(property))
                {
                    this.ValidateSessionAccess();
                }

                StringBuilder buf     = new StringBuilder();
                uint          bufSize = 0;
                uint          ret     = RemotableNativeMethods.MsiGetProperty((int)this.Handle, property, buf, ref bufSize);
                if (ret == (uint)NativeMethods.Error.MORE_DATA)
                {
                    buf.Capacity = (int)++bufSize;
                    ret          = RemotableNativeMethods.MsiGetProperty((int)this.Handle, property, buf, ref bufSize);
                }

                if (ret != 0)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
                return(buf.ToString());
            }

            set
            {
                if (string.IsNullOrWhiteSpace(property))
                {
                    throw new ArgumentNullException("property");
                }

                this.ValidateSessionAccess();

                if (value == null)
                {
                    value = String.Empty;
                }

                uint ret = RemotableNativeMethods.MsiSetProperty((int)this.Handle, property, value);
                if (ret != 0)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
            }
        }