protected override void InternalValidate() { TaskLogger.LogEnter(); if (!File.Exists(this.PackagePath)) { base.WriteError(new FileNotFoundException(this.PackagePath), ErrorCategory.InvalidData, null); } if (this.Reinstall) { string packageName = null; try { packageName = MsiUtility.GetProductInfo(MsiUtility.GetProductCode(this.PackagePath), InstallProperty.PackageName); } catch (ArgumentOutOfRangeException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, null); } catch (TaskException exception2) { base.WriteError(exception2, ErrorCategory.InvalidOperation, null); } if (this.newProduct) { base.WriteError(new TaskException(Strings.MsiIsNotInstalled(packageName)), ErrorCategory.InvalidArgument, 0); } else if (base.Features != null && base.Features.Length != 0) { base.WriteError(new TaskException(Strings.MsiReinstallMustAll), ErrorCategory.InvalidArgument, 0); } } TaskLogger.LogExit(); }
public static bool IsInstalled(string packagePath) { TaskLogger.LogEnter(); if (packagePath == null || packagePath == string.Empty) { throw new ArgumentNullException("packagePath", Strings.ExceptionProductInfoRequired); } Guid productCode = MsiUtility.GetProductCode(packagePath); bool result = MsiUtility.IsInstalled(productCode); TaskLogger.LogExit(); return(result); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); this.datetime = ((DateTime)ExDateTime.Now).ToString("yyyyMMdd-HHmmss"); try { string value = "LOGVERBOSE=1 TARGETDIR=\"" + this.InstallPath + "\""; Dictionary <string, bool> dictionary = new Dictionary <string, bool>(); Dictionary <string, bool> dictionary2 = new Dictionary <string, bool>(); int num = 0; for (int i = 0; i < this.LanguagePacksToInstall.Length; i++) { bool flag = Convert.ToBoolean(this.LPServerFlags[i]); dictionary.Add(this.LanguagePacksToInstall[i], flag); if (flag) { num++; } flag = Convert.ToBoolean(this.LPClientFlags[i]); dictionary2.Add(this.LanguagePacksToInstall[i], flag); if (flag) { num++; } } int num2 = num * 2; if (this.SourceIsBundle) { num2 += this.LanguagePacksToInstall.Length; } int num3 = 0; foreach (string text in this.LanguagePacksToInstall) { int lcid = CultureInfo.GetCultureInfo(text).LCID; string text2 = ""; if (this.SourceIsBundle) { TaskLogger.Log(Strings.ExtractingLang(text)); base.WriteProgress(this.Description, Strings.ExtractingLang(text), (int)((double)num3 * 100.0 / (double)num2 + 0.5)); DirectoryInfo directoryInfo = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(this.LangPackPath.PathName))); string text3 = text + "\\"; EmbeddedCabWrapper.ExtractFiles(this.LangPackPath.PathName, directoryInfo.FullName, text3); text2 = directoryInfo.FullName + '\\' + text3; num3++; } else { text2 = Path.Combine(this.LangPackPath.PathName, text); } string text4 = Path.Combine(text2, "ClientLanguagePack.msi"); if (dictionary2[text] && File.Exists(text4)) { TaskLogger.Log(Strings.UninstallOldMSIFor(text, "client")); base.WriteProgress(this.Description, Strings.UninstallOldMSIFor(text, "client"), (int)((double)num3 * 100.0 / (double)num2 + 0.5)); using (MonadCommand monadCommand = new MonadCommand("Uninstall-MsiPackage", this.monadConnection)) { string value2 = this.CreateMsilogPathname("Uninstall", "Client", text); monadCommand.Parameters.AddWithValue("LogFile", value2); Guid productCode = MsiUtility.GetProductCode(text4); monadCommand.Parameters.AddWithValue("ProductCode", productCode); monadCommand.Execute(); } num3++; TaskLogger.Log(Strings.InstallingMSIFor(text, "client")); base.WriteProgress(this.Description, Strings.InstallingMSIFor(text, "client"), (int)((double)num3 * 100.0 / (double)num2 + 0.5)); using (MonadCommand monadCommand2 = new MonadCommand("Install-MsiPackage", this.monadConnection)) { monadCommand2.Parameters.AddWithValue("PackagePath", text4); string value3 = this.CreateMsilogPathname("Install", "Client", text); monadCommand2.Parameters.AddWithValue("LogFile", value3); monadCommand2.Parameters.AddWithValue("Features", new string[] { "AdminTools", "Mailbox", "ClientAccess", "Gateway", "Bridgehead", "UnifiedMessaging", "ClientLanguagePack" }); monadCommand2.Parameters.AddWithValue("PropertyValues", value); monadCommand2.Execute(); } num3++; } text4 = Path.Combine(text2, "ServerLanguagePack.msi"); if (dictionary[text] && File.Exists(text4)) { TaskLogger.Log(Strings.UninstallOldMSIFor(text, "server")); base.WriteProgress(this.Description, Strings.UninstallOldMSIFor(text, "server"), (int)((double)num3 * 100.0 / (double)num2 + 0.5)); using (MonadCommand monadCommand3 = new MonadCommand("Uninstall-MsiPackage", this.monadConnection)) { string value4 = this.CreateMsilogPathname("Uninstall", "Server", text); monadCommand3.Parameters.AddWithValue("LogFile", value4); Guid productCode2 = MsiUtility.GetProductCode(text4); monadCommand3.Parameters.AddWithValue("ProductCode", productCode2); monadCommand3.Execute(); } num3++; TaskLogger.Log(Strings.InstallingMSIFor(text, "server")); base.WriteProgress(this.Description, Strings.InstallingMSIFor(text, "server"), (int)((double)num3 * 100.0 / (double)num2 + 0.5)); using (MonadCommand monadCommand4 = new MonadCommand("Install-MsiPackage", this.monadConnection)) { monadCommand4.Parameters.AddWithValue("PackagePath", text4); string value5 = this.CreateMsilogPathname("Install", "Server", text); monadCommand4.Parameters.AddWithValue("LogFile", value5); monadCommand4.Parameters.AddWithValue("Features", new string[] { "AdminTools", "Mailbox", "ClientAccess", "Gateway", "Bridgehead", "UnifiedMessaging", "ServerLanguagePack" }); monadCommand4.Parameters.AddWithValue("PropertyValues", value); monadCommand4.Execute(); } num3++; } if (this.SourceIsBundle) { try { Directory.Delete(text2, true); } catch (IOException e) { TaskLogger.LogError(e); } } } } finally { base.WriteProgress(this.Description, Strings.ProgressStatusCompleted, 100); TaskLogger.LogExit(); } }
protected override void InternalValidate() { TaskLogger.LogEnter(); if (this.ProductCode == Guid.Empty && string.IsNullOrEmpty(this.PackagePath)) { base.ThrowTerminatingError(new ArgumentNullException("ProductInfo", Strings.ExceptionProductInfoRequired), ErrorCategory.InvalidArgument, null); } else { try { if (!string.IsNullOrEmpty(this.PackagePath) && MsiUtility.IsInstalled(this.PackagePath)) { this.isInstalled = true; } else if (this.ProductCode != Guid.Empty && MsiUtility.IsInstalled(this.ProductCode)) { this.isInstalled = true; } } catch (ArgumentNullException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, null); } catch (ArgumentOutOfRangeException exception2) { base.WriteError(exception2, ErrorCategory.InvalidArgument, null); } catch (TaskException exception3) { base.WriteError(exception3, ErrorCategory.InvalidOperation, null); } } if (this.isInstalled) { if (base.Features != null && base.Features.Length != 0) { List <string> list = new List <string>(base.Features); bool flag = string.Equals("ExchangeServer.MSI", Path.GetFileName(this.PackagePath), StringComparison.OrdinalIgnoreCase); if (flag) { bool flag2 = false; bool flag3 = false; foreach (string b in list) { if (string.Equals("Gateway", b, StringComparison.OrdinalIgnoreCase)) { flag2 = true; } else if (string.Equals("AdminTools", b, StringComparison.OrdinalIgnoreCase)) { flag3 = true; } } if (flag2 && !flag3) { base.PropertyValues = string.Format("{0} ADDLOCAL={1}", base.PropertyValues, "AdminToolsNonGateway"); } if (flag2 && flag3) { list.Add("AdminToolsNonGateway"); } } base.PropertyValues = string.Format("{0} REMOVE={1}", base.PropertyValues, string.Join(",", base.Features)); } else { base.PropertyValues = string.Format("{0} REMOVE=ALL", base.PropertyValues); } if (base.ParameterSetName == "PackagePath") { string fullPath = Path.GetFullPath(this.PackagePath); base.WriteVerbose(Strings.MsiFullPackagePath(this.PackagePath, fullPath)); this.PackagePath = fullPath; try { this.ProductCode = MsiUtility.GetProductCode(this.PackagePath); } catch (ArgumentOutOfRangeException exception4) { base.WriteError(exception4, ErrorCategory.InvalidArgument, null); } catch (TaskException exception5) { base.WriteError(exception5, ErrorCategory.InvalidOperation, null); } } if (!base.Fields.IsChanged("LogFile") && this.PackagePath != null && this.PackagePath != string.Empty) { base.LogFile = Path.Combine(ConfigurationContext.Setup.SetupLoggingPath, Path.ChangeExtension(Path.GetFileName(this.PackagePath), ".msilog")); } } TaskLogger.LogExit(); }
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(); }