示例#1
0
        public IList <InstallCost> GetTotalCost()
        {
            this.ValidateSessionAccess();

            IList <InstallCost> costs    = new List <InstallCost>();
            StringBuilder       driveBuf = new StringBuilder(20);

            for (uint i = 0; true; i++)
            {
                int  cost, tempCost;
                uint driveBufSize = (uint)driveBuf.Capacity;
                uint ret          = RemotableNativeMethods.MsiEnumComponentCosts(
                    (int)this.Handle,
                    null,
                    i,
                    (int)InstallState.Default,
                    driveBuf,
                    ref driveBufSize,
                    out cost,
                    out tempCost);
                if (ret == (uint)NativeMethods.Error.NO_MORE_ITEMS)
                {
                    break;
                }
                if (ret == (uint)NativeMethods.Error.MORE_DATA)
                {
                    driveBuf.Capacity = (int)++driveBufSize;
                    ret = RemotableNativeMethods.MsiEnumComponentCosts(
                        (int)this.Handle,
                        null,
                        i,
                        (int)InstallState.Default,
                        driveBuf,
                        ref driveBufSize,
                        out cost,
                        out tempCost);
                }

                if (ret != 0)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
                costs.Add(new InstallCost(driveBuf.ToString(), cost * 512L, tempCost * 512L));
            }
            return(costs);
        }