public static void PopUILevel() { TaskLogger.LogEnter(); MsiUtility.InternalUISettings internalUISettings = (MsiUtility.InternalUISettings)MsiUtility.uiSettings.Pop(); MsiNativeMethods.SetInternalUI(internalUISettings.UILevel, ref internalUISettings.Window); TaskLogger.LogExit(); }
public static void PopExternalUI() { TaskLogger.LogEnter(); MsiUtility.InternalUISettings internalUISettings = (MsiUtility.InternalUISettings)MsiUtility.uiSettings.Pop(); MsiNativeMethods.SetExternalUI(internalUISettings.UIHandlerDelegate, InstallLogMode.None, null); MsiNativeMethods.SetInternalUI(internalUISettings.UILevel, ref internalUISettings.Window); TaskLogger.LogExit(); }
internal void SetLogging() { TaskLogger.LogEnter(); if (this.LogMode != InstallLogMode.None) { MsiNativeMethods.EnableLog(this.LogMode, this.LogFile, InstallLogAttributes.Append); } TaskLogger.LogExit(); }
private static void PushUILevel(InstallUILevel uiLevel, ref IntPtr window) { TaskLogger.LogEnter(); InstallUILevel installUILevel = MsiNativeMethods.SetInternalUI(uiLevel, ref window); if (installUILevel == InstallUILevel.NoChange) { throw new ArgumentOutOfRangeException("uiLevel", installUILevel, Strings.ExceptionInvalidUILevel); } MsiUtility.uiSettings.Push(new MsiUtility.InternalUISettings(uiLevel, window, null)); TaskLogger.LogExit(); }
public static Guid GetProductCode(string packagePath) { TaskLogger.LogEnter(); StringBuilder stringBuilder = new StringBuilder(); Guid guid = Guid.Empty; MsiUtility.PushUILevel(InstallUILevel.None); try { SafeMsiHandle safeMsiHandle; uint num = MsiNativeMethods.OpenPackageEx(packagePath, OpenPackageFlags.IgnoreMachineState, out safeMsiHandle); if (num != 0U) { Win32Exception ex = new Win32Exception((int)num); throw new TaskException(Strings.MsiCouldNotOpenPackage(packagePath, ex.Message, (int)num), ex); } using (safeMsiHandle) { uint num2 = 38U; for (;;) { num2 += 1U; if (num2 > 2147483647U) { break; } stringBuilder.EnsureCapacity((int)num2); num = MsiNativeMethods.GetProductProperty(safeMsiHandle, "ProductCode", stringBuilder, ref num2); if (234U != num) { goto Block_7; } } throw new TaskException(Strings.MsiPropertyTooLarge); Block_7: if (num != 0U) { Win32Exception ex2 = new Win32Exception((int)num); throw new TaskException(Strings.MsiCouldNotGetProdcutProperty("ProductCode", ex2.Message, (int)num), ex2); } guid = new Guid(stringBuilder.ToString()); TaskLogger.Log(Strings.MsiProductCode(guid)); } } finally { MsiUtility.PopUILevel(); } TaskLogger.LogExit(); return(guid); }
public static void PushExternalUI(MsiUIHandler handler, InstallLogMode logMode) { TaskLogger.LogEnter(); IntPtr zero = IntPtr.Zero; InstallUILevel installUILevel = MsiNativeMethods.SetInternalUI(InstallUILevel.None | InstallUILevel.SourceResOnly, ref zero); if (installUILevel == InstallUILevel.NoChange) { throw new ArgumentOutOfRangeException("uiLevel", installUILevel, Strings.ExceptionInvalidUILevel); } MsiUIHandlerDelegate handlerDelegate = MsiNativeMethods.SetExternalUI(handler.UIHandlerDelegate, logMode, null); MsiUtility.uiSettings.Push(new MsiUtility.InternalUISettings(InstallUILevel.None | InstallUILevel.SourceResOnly, zero, handlerDelegate)); }
internal void RemoveProductCode(Guid productCode) { TaskLogger.LogEnter(); base.SetLogging(); try { MsiUtility.PushExternalUI(base.UIHandler, (InstallLogMode)10115); try { string text = productCode.ToString("B").ToUpper(CultureInfo.InvariantCulture); base.WriteVerbose(Strings.RemovingPackageByProductCode(productCode)); uint num = MsiNativeMethods.ConfigureProduct(text, InstallLevel.Default, InstallState.Default, base.PropertyValues); if (num != 0U) { Win32Exception ex = new Win32Exception((int)num); if (num == 3010U) { if (this.WarnOnRebootRequests) { TaskException ex2 = new TaskException(Strings.MsiRebootRequiredToFinish(text), ex); TaskLogger.SendWatsonReport(ex2); base.WriteWarning(ex2.Message); } else if (UninstallMsi.rebootRequiredException == null) { UninstallMsi.rebootRequiredException = new TaskException(Strings.MsiRebootRequiredToContinue(text), ex); } } else if (string.IsNullOrEmpty(base.LastMsiError)) { base.WriteError(new TaskException(Strings.MsiCouldNotRemoveProduct(productCode, ex.Message, (int)num), ex), ErrorCategory.InvalidOperation, null); } else { base.WriteError(new TaskException(Strings.MsiCouldNotRemoveProductDetailed(productCode, ex.Message, (int)num, base.LastMsiError), ex), ErrorCategory.InvalidOperation, null); } } } finally { MsiUtility.PopExternalUI(); } } catch (ArgumentOutOfRangeException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, 0); } TaskLogger.LogExit(); }
public static string GetProductInfo(Guid productCode, string propertyName) { TaskLogger.LogEnter(); StringBuilder stringBuilder = new StringBuilder(); string productCodeString = productCode.ToString("B").ToUpper(CultureInfo.InvariantCulture); uint num = (uint)stringBuilder.Capacity; MsiUtility.PushUILevel(InstallUILevel.None); try { uint productInfo; for (;;) { num += 1U; if (num > 2147483647U) { break; } stringBuilder.EnsureCapacity((int)num); productInfo = MsiNativeMethods.GetProductInfo(productCodeString, propertyName, stringBuilder, ref num); if (234U != productInfo) { goto Block_3; } } throw new TaskException(Strings.MsiPropertyTooLarge); Block_3: if (productInfo != 0U) { Win32Exception ex = new Win32Exception((int)productInfo); throw new TaskException(Strings.MsiCouldNotGetProdcutProperty(propertyName, ex.Message, (int)productInfo), ex); } } finally { MsiUtility.PopUILevel(); } TaskLogger.Log(Strings.MsiProperty(propertyName, stringBuilder.ToString())); TaskLogger.LogExit(); return(stringBuilder.ToString()); }
public static bool IsInstalled(Guid ProductCode) { TaskLogger.LogEnter(); bool result = false; if (Guid.Empty == ProductCode) { throw new ArgumentNullException("ProductCode", Strings.ExceptionProductInfoRequired); } MsiUtility.PushUILevel(InstallUILevel.None); try { InstallState installState = MsiNativeMethods.QueryProductState(ProductCode.ToString("B").ToUpper(CultureInfo.InvariantCulture)); result = (installState != InstallState.Unknown); } finally { MsiUtility.PopUILevel(); } TaskLogger.LogExit(); return(result); }
internal void InstallPackageFile(string packagePath) { TaskLogger.LogEnter(); try { Guid productCode = MsiUtility.GetProductCode(this.PackagePath); base.SetLogging(); MsiUtility.PushExternalUI(base.UIHandler, (InstallLogMode)10115); try { base.WriteVerbose(Strings.InstallingPackage(packagePath)); List <MsiNativeMethods.PatchSequenceInfo> list = new List <MsiNativeMethods.PatchSequenceInfo>(); uint num; if (this.UpdatesDir != null) { try { string[] files = Directory.GetFiles(this.UpdatesDir.PathName, "*.msp"); foreach (string patchData in files) { MsiNativeMethods.PatchSequenceInfo item = new MsiNativeMethods.PatchSequenceInfo { patchData = patchData, patchDataType = PatchDataType.PatchFile, order = -1, status = 0U }; list.Add(item); base.WriteVerbose(Strings.PatchFileFound(item.patchData)); } } catch (DirectoryNotFoundException) { base.WriteVerbose(Strings.UpdatesDirectoryNotFound(this.UpdatesDir.PathName)); } catch (IOException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); } if (list.Count > 0) { MsiNativeMethods.PatchSequenceInfo[] array2 = list.ToArray(); num = MsiNativeMethods.DetermineApplicablePatches(this.PackagePath, array2.Length, array2); if (num != 0U) { base.WriteError(new TaskException(Strings.FailedToSortPatches(num)), ErrorCategory.InvalidOperation, null); } else { base.WriteVerbose(Strings.SortedAvailablePatches); List <MsiNativeMethods.PatchSequenceInfo> list2 = new List <MsiNativeMethods.PatchSequenceInfo>(); foreach (MsiNativeMethods.PatchSequenceInfo item2 in array2) { base.WriteVerbose(Strings.PrintPatchOrderInfo(item2.patchData, item2.order, item2.status)); if (item2.order >= 0) { list2.Add(item2); } } if (list2.Count > 0) { list2.Sort(new Comparison <MsiNativeMethods.PatchSequenceInfo>(MsiNativeMethods.ComparePatchSequence)); StringBuilder stringBuilder = new StringBuilder(); foreach (MsiNativeMethods.PatchSequenceInfo patchSequenceInfo in list2) { base.WriteVerbose(Strings.ValidPatch(patchSequenceInfo.patchData, patchSequenceInfo.order)); stringBuilder.Append(patchSequenceInfo.patchData); stringBuilder.Append(";"); } base.WriteVerbose(Strings.PatchAttributeValue(stringBuilder.ToString())); base.PropertyValues = string.Format("PATCH=\"{0}\" {1}", stringBuilder.ToString(), base.PropertyValues); } } } } else { base.WriteVerbose(Strings.NoUpdatesDirectorySpecified); } if (this.newProduct) { base.WriteVerbose(Strings.NewProductInstallation(packagePath, base.PropertyValues)); num = MsiNativeMethods.InstallProduct(packagePath, base.PropertyValues); } else { string productCodeString = productCode.ToString("B").ToUpper(CultureInfo.InvariantCulture); base.WriteVerbose(Strings.ExistingProductConfiguration(productCodeString, base.PropertyValues)); num = MsiNativeMethods.ConfigureProduct(productCodeString, InstallLevel.Default, InstallState.Default, base.PropertyValues); } if (num != 0U) { Win32Exception ex = new Win32Exception((int)num); if (num == 3010U) { throw new TaskException(Strings.MsiRebootRequiredToContinue(packagePath), ex); } if (string.IsNullOrEmpty(base.LastMsiError)) { base.WriteError(new TaskException(Strings.MsiInstallFailed(packagePath, ex.Message, (int)num), ex), ErrorCategory.InvalidOperation, null); } else { base.WriteError(new TaskException(Strings.MsiInstallFailedDetailed(packagePath, ex.Message, (int)num, base.LastMsiError), ex), ErrorCategory.InvalidOperation, null); } } } finally { MsiUtility.PopExternalUI(); } } catch (ArgumentOutOfRangeException exception2) { base.WriteError(exception2, ErrorCategory.InvalidArgument, null); } catch (TaskException exception3) { base.WriteError(exception3, ErrorCategory.InvalidOperation, null); } TaskLogger.LogExit(); }