public void Open(string filePath, MsiMethods.MSIDBOPEN mode) { if (opened) { Close(); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } this.filePath = filePath; dbhandle = IntPtr.Zero; var returnValue = MsiMethods.MsiOpenDatabase(this.filePath, (IntPtr)mode, ref dbhandle); if (returnValue != (int)MsiMethods.ErrorCodes.Success) { throw new InstallerVerificationLibraryException("Error opening file:" + this.filePath); } opened = true; }
/// <summary> /// http://msdn.microsoft.com/en-us/library/windows/desktop/aa372045(v=vs.85).aspx /// </summary> public void SetSummaryInformation(MsiMethods.PropertyId propertyId, VarEnum datatype, object value) { var summaryHandle = IntPtr.Zero; if (MsiMethods.MsiGetSummaryInformation(dbhandle, null, 7, ref summaryHandle) != (int)MsiMethods.ErrorCodes.Success) { throw new InstallerVerificationLibraryException("Could not open summary handler to"); } switch (datatype) { case VarEnum.VT_FILETIME: break; case VarEnum.VT_I2: case VarEnum.VT_I4: if (MsiMethods.MsiSummaryInfoSetProperty(summaryHandle, (int)propertyId, (int)datatype, Convert.ToInt32(value), IntPtr.Zero, null) != (int)MsiMethods.ErrorCodes.Success) { throw new InstallerVerificationLibraryException("Could not set summary property" + propertyId); } break; case VarEnum.VT_LPSTR: if (MsiMethods.MsiSummaryInfoSetProperty(summaryHandle, (int)propertyId, (int)datatype, 0, IntPtr.Zero, Convert.ToString(value)) != (int)MsiMethods.ErrorCodes.Success) { throw new InstallerVerificationLibraryException("Could not set summary property" + propertyId); } break; } if (MsiMethods.MsiSummaryInfoPersist(summaryHandle) != (int)MsiMethods.ErrorCodes.Success) { throw new InstallerVerificationLibraryException("Could not persist summary property"); } CloseHandle(summaryHandle); }