コード例 #1
0
ファイル: ProductInstallation.cs プロジェクト: roni8686/wix3
        /// <summary>
        /// Gets information about an installation of a product.
        /// </summary>
        /// <param name="propertyName">Name of the property being retrieved.</param>
        /// <exception cref="ArgumentOutOfRangeException">An unknown product or property was requested</exception>
        /// <exception cref="InstallerException">The installer configuration data is corrupt</exception>
        /// <remarks><p>
        /// Win32 MSI APIs:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msigetproductinfo.asp">MsiGetProductInfo</a>,
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msigetproductinfoex.asp">MsiGetProductInfoEx</a>
        /// </p></remarks>
        public override string this[string propertyName]
        {
            get
            {
                if (this.properties != null)
                {
                    string value = null;
                    this.properties.TryGetValue(propertyName, out value);
                    return(value);
                }
                else
                {
                    StringBuilder buf     = new StringBuilder(40);
                    uint          bufSize = (uint)buf.Capacity;
                    uint          ret;

                    if (this.Context == UserContexts.UserManaged ||
                        this.Context == UserContexts.UserUnmanaged ||
                        this.Context == UserContexts.Machine)
                    {
                        ret = NativeMethods.MsiGetProductInfoEx(
                            this.ProductCode,
                            this.UserSid,
                            this.Context,
                            propertyName,
                            buf,
                            ref bufSize);
                        if (ret == (uint)NativeMethods.Error.MORE_DATA)
                        {
                            buf.Capacity = (int)++bufSize;
                            ret          = NativeMethods.MsiGetProductInfoEx(
                                this.ProductCode,
                                this.UserSid,
                                this.Context,
                                propertyName,
                                buf,
                                ref bufSize);
                        }
                    }
                    else
                    {
                        ret = NativeMethods.MsiGetProductInfo(
                            this.ProductCode,
                            propertyName,
                            buf,
                            ref bufSize);
                        if (ret == (uint)NativeMethods.Error.MORE_DATA)
                        {
                            buf.Capacity = (int)++bufSize;
                            ret          = NativeMethods.MsiGetProductInfo(
                                this.ProductCode,
                                propertyName,
                                buf,
                                ref bufSize);
                        }
                    }

                    if (ret != 0)
                    {
                        return(null);
                    }

                    return(buf.ToString());
                }
            }
        }