Пример #1
0
        /// <summary>
        /// Gets a summary information property.
        /// </summary>
        /// <param name="index">Index of the summary information property.</param>
        /// <returns>The summary information property.</returns>
        public string GetProperty(int index)
        {
            uint          dataType;
            StringBuilder stringValue = new StringBuilder("");
            int           bufSize     = 0;
            int           intValue;
            FILETIME      timeValue;

            timeValue.dwHighDateTime = 0;
            timeValue.dwLowDateTime  = 0;

            int error = MsiInterop.MsiSummaryInfoGetProperty(this.Handle, index, out dataType, out intValue, ref timeValue, stringValue, ref bufSize);

            if (234 == error)
            {
                stringValue.EnsureCapacity(++bufSize);
                error = MsiInterop.MsiSummaryInfoGetProperty(this.Handle, index, out dataType, out intValue, ref timeValue, stringValue, ref bufSize);
            }

            if (0 != error)
            {
                throw new MsiException(error);
            }

            switch ((VT)dataType)
            {
            case VT.EMPTY:
                return(String.Empty);

            case VT.LPSTR:
                return(stringValue.ToString());

            case VT.I2:
            case VT.I4:
                return(Convert.ToString(intValue, CultureInfo.InvariantCulture));

            case VT.FILETIME:
                long     longFileTime = (((long)timeValue.dwHighDateTime) << 32) | unchecked ((uint)timeValue.dwLowDateTime);
                DateTime dateTime     = DateTime.FromFileTime(longFileTime);
                return(dateTime.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture));

            default:
                throw new InvalidOperationException();
            }
        }