/// <summary> /// Writes and error to the pipeline. /// </summary> /// <param name="record">The <see cref="Deployment.WindowsInstaller.Record"/> containing the error details.</param> /// <returns>The result code indicating how Windows Installer should proceed.</returns> protected MessageResult OnError(Deployment.WindowsInstaller.Record record) { if (null == record) { return(MessageResult.None); } else if (0 < record.FieldCount) { // Ignore certain errors. int code = record.GetInteger(1); switch (code) { case 1605: // Continue even if there isn't enough disk space for rollback. return(MessageResult.Ignore); case 1704: // Roll back suspended installs so we can continue. return(MessageResult.OK); } } using (var ex = new PSInstallerException(record)) { if (null != ex.ErrorRecord) { this.WriteError(ex.ErrorRecord); } } return(MessageResult.OK); }
private static ErrorCategory GetErrorCategory(Deployment.WindowsInstaller.Record record, out string resource) { resource = null; if (1 < record.FieldCount) { int code = record.GetInteger(1); if (1000 <= code && code < 25000) { // Specifically handle common errors. switch (code) { case 1301: case 1304: resource = record.GetString(2); return(ErrorCategory.WriteError); case 1303: case 1306: case 1718: resource = record.GetString(2); return(ErrorCategory.PermissionDenied); case 1305: resource = record.GetString(2); return(ErrorCategory.ReadError); case 1308: case 1334: resource = record.GetString(2); return(ErrorCategory.ResourceUnavailable); case 1706: resource = record.GetString(2); return(ErrorCategory.ResourceUnavailable); case 1715: case 1716: case 1717: resource = record.GetString(2); return(ErrorCategory.NotSpecified); case 1935: case 1937: resource = record.GetString(6); return(ErrorCategory.InvalidData); } } } return(ErrorCategory.NotSpecified); }
/// <summary> /// Provides information about the install session. /// </summary> /// <param name="record">The <see cref="Deployment.WindowsInstaller.Record"/> containing common details.</param> /// <returns>The result code indicating how Windows Installer should proceed.</returns> protected MessageResult OnCommonData(Deployment.WindowsInstaller.Record record) { // Get the current session language and Windows Installer-generated caption. if (1 < record.FieldCount) { var subtype = record.GetInteger(1); if (0 == subtype) { var langId = record.GetInteger(2); if (0 != langId) { this.progress.CurrentCulture = CultureInfo.GetCultureInfo(langId); } } else if (1 == subtype) { this.progress.CurrentName = record.GetString(2); } } return(MessageResult.OK); }
/// <summary> /// Writes progress information. /// </summary> /// <param name="record">The <see cref="Deployment.WindowsInstaller.Record"/> containing the progress details.</param> /// <returns>The result code indicating how Windows Installer should proceed.</returns> protected MessageResult OnProgress(Deployment.WindowsInstaller.Record record) { if (null == record || 2 > record.FieldCount) { return(MessageResult.None); } switch (record.GetInteger(1)) { // Add a new phase of progress information. case 0: if (4 > record.FieldCount) { // Invalid message. break; } // Add a new phase of progress. var current = this.progress.Add(); current.Forward = 0 == record.GetInteger(3); current.Total = record.GetInteger(2); current.Complete = current.Forward ? 0 : current.Total; current.EnableActionData = false; current.GeneratingScript = 1 == record.GetInteger(4); // Windows Installer team advises to add ~50 ticks to script generation. if (0 == this.progress.CurrentIndex) { current.Total += 50; } break; // Update progress information. case 1: if (3 > record.FieldCount) { // Invalid message. break; } else if (!this.progress.IsValid) { // Progress not initialized. break; } if (0 == record.GetInteger(3)) { this.progress.Current.EnableActionData = false; } else { this.progress.Current.EnableActionData = true; this.progress.Current.Step = record.GetInteger(2); } break; // Report progress information. case 2: if (!this.progress.IsValid || 0 == this.progress.Current.Total) { // Progress not initialized. break; } // Adjust the current progress. if (this.progress.Current.Forward) { this.progress.Current.Complete += record.GetInteger(2); } else { this.progress.Current.Complete -= record.GetInteger(2); } break; // Expand the total. case 3: if (!this.progress.IsValid) { // Progress not initialized. break; } // Expand the progress maximum. this.progress.Current.Total += record.GetInteger(2); break; default: return(MessageResult.None); } this.WriteProgress(); return(MessageResult.OK); }