115 lines
3.5 KiB
C#
115 lines
3.5 KiB
C#
namespace Pilz.Updating.Client.Gui;
|
|
|
|
public partial class UpdateWindow : Telerik.WinControls.UI.RadForm
|
|
{
|
|
// C o n s t r u c t o r s
|
|
|
|
public UpdateWindow()
|
|
{
|
|
// Init Form
|
|
InitializeComponent();
|
|
|
|
// Events
|
|
Shown += Main_Shown;
|
|
FormClosed += Main_FormClosed;
|
|
FormClosing += Main_FormClosing;
|
|
|
|
// Init Application Header Text
|
|
string header;
|
|
if (!string.IsNullOrEmpty(installer.Configuration.ApplicationName))
|
|
header = string.Format(My.Resources.UpdateInstallerGuiLangRes.String_UpdatingApplicationX, installer.Configuration.ApplicationName);
|
|
else
|
|
header = My.Resources.UpdateInstallerGuiLangRes.String_UpdateIsRunning;
|
|
|
|
radLabel_Header.Text = $"<html><span style=\"font-size: 18pt; color: #b7472a\"><b>{header}</b></span></html>";
|
|
}
|
|
|
|
// F i e l d s
|
|
|
|
private bool allowClose = false;
|
|
|
|
// F e a t u r e s
|
|
|
|
public void SetStatus(UpdateStatus status)
|
|
{
|
|
string newStatusText = string.Empty;
|
|
Image newStatusImage = null;
|
|
|
|
switch (status)
|
|
{
|
|
case UpdateStatus.Copying:
|
|
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_CopyingFiles;
|
|
break;
|
|
case UpdateStatus.Done:
|
|
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Done;
|
|
break;
|
|
case UpdateStatus.Extracting:
|
|
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Extracting;
|
|
break;
|
|
case UpdateStatus.Cleanup:
|
|
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_RemovingFiles;
|
|
break;
|
|
case UpdateStatus.Waiting:
|
|
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Waiting;
|
|
break;
|
|
}
|
|
|
|
switch (status)
|
|
{
|
|
case UpdateStatus.Copying:
|
|
newStatusImage = MyIcons.icons8_copy_16px;
|
|
break;
|
|
case UpdateStatus.Extracting:
|
|
newStatusImage = MyIcons.icons8_open_archive_16px;
|
|
break;
|
|
case UpdateStatus.Cleanup:
|
|
newStatusImage = MyIcons.icons8_recycle_bin_16px;
|
|
break;
|
|
case UpdateStatus.Waiting:
|
|
newStatusImage = MyIcons.icons8_sand_timer_16px;
|
|
break;
|
|
case UpdateStatus.Done:
|
|
newStatusImage = MyIcons.icons8_checkmark_16px;
|
|
break;
|
|
}
|
|
|
|
radLabel_Status.Text = newStatusText;
|
|
radLabel_Status.Image = newStatusImage;
|
|
}
|
|
|
|
private async Task WaitforHostApp()
|
|
{
|
|
SetStatus(UpdateStatus.Waiting);
|
|
await Task.Run(installer.WaitForHostApplication);
|
|
}
|
|
|
|
private async void ExecuteUpdate()
|
|
{
|
|
await Task.Run(installer.InstallUpdate);
|
|
allowClose = true;
|
|
Close();
|
|
}
|
|
|
|
private async void Main_Shown(object sender, EventArgs e)
|
|
{
|
|
radWaitingBar1.StartWaiting();
|
|
await WaitforHostApp();
|
|
ExecuteUpdate();
|
|
}
|
|
|
|
private void Main_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
installer.StartHostApplication();
|
|
}
|
|
|
|
private void Main_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
radWaitingBar1.StopWaiting();
|
|
e.Cancel = !allowClose;
|
|
}
|
|
|
|
private void Installer_StatusChanges(object sender, UpdateClientStatusChangedEventArgs e)
|
|
{
|
|
Invoke(new Action(() => SetStatus(e.NewStatus)));
|
|
}
|
|
} |