void msiInterface_InstallerMessageReceived(object sender, InstallerMessageEventArgs e) { string message = string.Empty; if (e.InstallerMessage.Type == InstallerMessageType.ProgressReport) { message = ((ProgressReportMessage)e.InstallerMessage).ToString(); if (reset) { ProgressReportMessage progressReportMessage = (ProgressReportMessage)e.InstallerMessage; if (approximate && progressBar1.Maximum < (progressBar1.Value + progressReportMessage.TicksMoved)) { return; } progressBar1.Value += (int)progressReportMessage.TicksMoved; AddText("MsiInstall: Moved = " + (int)progressReportMessage.TicksMoved + " Progress = " + progressBar1.Value); } } else if (e.InstallerMessage.Type == InstallerMessageType.ResetMessage) { reset = false; message = ((ResetMessage)e.InstallerMessage).ToString(); AddText("MsiInstall: Reset ticks: " + ((ResetMessage)e.InstallerMessage).Ticks); // set progress bar properties ResetMessage resetMessage = (ResetMessage)e.InstallerMessage; progressBar1.Maximum = (int)resetMessage.Ticks; progressBar1.Minimum = 0; progressBar1.Step = 1; progressBar1.Value = 0; approximate = resetMessage.IsApproximate; AddText("MsiInstall: Reset done: value = " + progressBar1.Value + " max=" + progressBar1.Maximum); reset = true; } else if (e.InstallerMessage.Type == InstallerMessageType.ActionData) { AddText("MsiInstall: Action Data message =" + ((ActionDataMessage)e.InstallerMessage).Message); SetLabel(((ActionDataMessage)e.InstallerMessage).Message); //Globals.Instance.MsiInterface.SetUserAction(MsiResponse.Cancel); } else if (e.InstallerMessage.Type == InstallerMessageType.ActionStart) { ActionStartMessage actionStartMessage = (ActionStartMessage)e.InstallerMessage; AddText("MsiInstall: Action start message: action=" + actionStartMessage.Action + " desc=" + actionStartMessage.Description + " time=" + actionStartMessage.Time); SetLabel(actionStartMessage.Action + ": " + actionStartMessage.Description); } else if (e.InstallerMessage.Type == InstallerMessageType.FileInUse) { MsiResponse userAction = (MsiResponse)MessageBox.Show("file in use:" + ((FileInUseMessage)e.InstallerMessage).FilePath, "File in use", MessageBoxButtons.AbortRetryIgnore); Globals.Instance.MsiInterface.SetUserAction(userAction); } else if (e.InstallerMessage.Type == InstallerMessageType.InstallationComplete) { SetLabel("Installation Completed"); btnCancel.Enabled = false; btnBack.Enabled = false; } AddText("MsiInstall: " + message); }
/// <summary>Send user response back to Windows Installer. Ex: MsiResponse.Cancel will cancel installation. MsiResponse.OK is the default value.</summary> /// <param name="userAction">Input supplied by the user. Use MsiResponse</param> public void SetUserAction(MsiResponse userAction) { userActed = true; this.userAction = userAction; }