using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Forms;
namespace HakInstaller
{
///
/// Summary description for InstallProgress.
///
public class InstallProgressForm : System.Windows.Forms.Form,
IHakInstallProgress
{
#region public properties/methods
///
/// Class constructor
///
public InstallProgressForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
cancelled = false;
builder = new System.Text.StringBuilder();
}
#endregion
#region IHakInstallProgress implementation
///
/// Gets whether the user cancelled the install.
///
bool IHakInstallProgress.IsCancelled { get { return cancelled; } }
///
/// Gets/sets the number of steps for the progress bar.
///
int IHakInstallProgress.ProgressSteps
{
get { return progressBar.Maximum; }
set
{
progressBar.Minimum = 1;
progressBar.Maximum = value;
progressBar.Value = 1;
progressBar.Step = 1;
}
}
///
/// Advances the progress bar 1 step.
///
void IHakInstallProgress.Step()
{
progressBar.PerformStep();
}
///
/// Sets the currently displayed progress message.
///
/// Format string
/// Message arguments
void IHakInstallProgress.SetMessage(string format, params object[] args)
{
builder.Length = 0;
builder.AppendFormat(format, args);
labelMessage.Text = builder.ToString();
}
///
/// This methods should ask the user for confirmation of replacing
/// the listed files in the module with files from sources in the
/// hif files, as this operation may break the module.
///
/// The list of file conflicts
/// true if the files should be replaced, false if adding
/// the hak(s) to the module should be aborted
bool IHakInstallProgress.ShouldReplaceFiles(FileConflictCollection conflicts)
{
// Confirm the file replace operation with the user.
ReplacingFilesForm form = new ReplacingFilesForm(conflicts);
return DialogResult.OK == form.ShowDialog((Form) this);
}
///
/// This method should ask the user for confirmation of overwriting
/// the listed files. If fatal is true then there is no confirmation,
/// it is just an informational message that the operation must be aborted.
///
/// The list of warnings
/// True if the warnings are fatal
/// The type of overwrite being confirmed
/// True if the operation should proceed
bool IHakInstallProgress.ShouldOverwrite(OverwriteWarningCollection warnings,
bool fatal, OverwriteWarningType type)
{
OverwriteWarningsForm form = new OverwriteWarningsForm(warnings, fatal, type);
return DialogResult.OK == form.ShowDialog((Form) this);
}
///
/// Displays an error message to the user.
///
/// The error message to display
void IHakInstallProgress.DisplayErrorMessage(string error)
{
MessageBox.Show(this, error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
///
/// Displays a message to the user.
///
/// The message to display
void IHakInstallProgress.DisplayMessage(string message)
{
MessageBox.Show(this, message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
#region protected fields/properties/methods
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows Form Designer generated code
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Label labelMessage;
private System.Windows.Forms.Button buttonCancel;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.progressBar = new System.Windows.Forms.ProgressBar();
this.labelMessage = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// progressBar
//
this.progressBar.Location = new System.Drawing.Point(16, 56);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(344, 16);
this.progressBar.TabIndex = 0;
//
// labelMessage
//
this.labelMessage.Location = new System.Drawing.Point(16, 16);
this.labelMessage.Name = "labelMessage";
this.labelMessage.Size = new System.Drawing.Size(344, 32);
this.labelMessage.TabIndex = 1;
this.labelMessage.Text = "label1";
//
// buttonCancel
//
this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.buttonCancel.Location = new System.Drawing.Point(16, 96);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(72, 24);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// InstallProgressForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(378, 136);
this.ControlBox = false;
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelMessage);
this.Controls.Add(this.progressBar);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InstallProgressForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Installing Haks";
this.ResumeLayout(false);
}
#endregion
#region private fields/properties/methods
private bool cancelled;
private System.Text.StringBuilder builder;
#endregion
#region event handlers
///
/// Event handler for the cancel button's click event.
///
///
///
private void buttonCancel_Click(object sender, System.EventArgs e)
{
cancelled = true;
}
#endregion
}
}