finish migration
This commit is contained in:
111
Pilz.Updating.Client.Gui/BaseFeatures.cs
Normal file
111
Pilz.Updating.Client.Gui/BaseFeatures.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Pilz.Updating.GUIBase;
|
||||
|
||||
internal static class BaseFeatures
|
||||
{
|
||||
[DllImport("user32")]
|
||||
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam);
|
||||
|
||||
private const int BCM_FIRST = 0x1600; // Normal button
|
||||
private const int BCM_SETSHIELD = BCM_FIRST + 0xC; // Elevated button
|
||||
|
||||
public static void AddShieldToButton(Button b)
|
||||
{
|
||||
b.FlatStyle = FlatStyle.System;
|
||||
SendMessage(b.Handle, BCM_SETSHIELD, 0, 0xFFFFFFFFU);
|
||||
}
|
||||
|
||||
// Return a bitmap containing the UAC shield.
|
||||
private static Bitmap shield_bm = null;
|
||||
|
||||
public static Bitmap GetUacShieldImage()
|
||||
{
|
||||
if (shield_bm is object)
|
||||
{
|
||||
return shield_bm;
|
||||
}
|
||||
|
||||
const int WID = 50;
|
||||
const int HGT = 50;
|
||||
const int MARGIN = 4;
|
||||
|
||||
// Make the button. For some reason, it must
|
||||
// have text or the UAC shield won't appear.
|
||||
var btn = new Button
|
||||
{
|
||||
Text = " ",
|
||||
Size = new Size(WID, HGT)
|
||||
};
|
||||
AddShieldToButton(btn);
|
||||
|
||||
// Draw the button onto a bitmap.
|
||||
var bm = new Bitmap(WID, HGT);
|
||||
btn.Refresh();
|
||||
btn.DrawToBitmap(bm, new Rectangle(0, 0, WID, HGT));
|
||||
|
||||
// Find the part containing the shield.
|
||||
int min_x = WID;
|
||||
int max_x = 0;
|
||||
int min_y = HGT;
|
||||
int max_y = 0;
|
||||
|
||||
// Fill on the left.
|
||||
int y = MARGIN;
|
||||
while (y < HGT - MARGIN)
|
||||
{
|
||||
// Get the leftmost pixel's color.
|
||||
var target_color = bm.GetPixel(MARGIN, y);
|
||||
|
||||
// Fill in with this color as long as we see the target.
|
||||
int x = MARGIN;
|
||||
while (x < WID - MARGIN)
|
||||
{
|
||||
// See if this pixel is part of the shield.
|
||||
if (bm.GetPixel(x, y).Equals(target_color))
|
||||
{
|
||||
// It's not part of the shield.
|
||||
// Clear the pixel.
|
||||
bm.SetPixel(x, y, Color.Transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's part of the shield.
|
||||
if (min_y > y)
|
||||
{
|
||||
min_y = y;
|
||||
}
|
||||
|
||||
if (min_x > x)
|
||||
{
|
||||
min_x = x;
|
||||
}
|
||||
|
||||
if (max_y < y)
|
||||
{
|
||||
max_y = y;
|
||||
}
|
||||
|
||||
if (max_x < x)
|
||||
{
|
||||
max_x = x;
|
||||
}
|
||||
}
|
||||
|
||||
x += 1;
|
||||
}
|
||||
|
||||
y += 1;
|
||||
}
|
||||
|
||||
// Clip out the shield part.
|
||||
int shield_wid = max_x - min_x + 1;
|
||||
int shield_hgt = max_y - min_y + 1;
|
||||
shield_bm = new Bitmap(shield_wid, shield_hgt);
|
||||
var shield_gr = Graphics.FromImage(shield_bm);
|
||||
shield_gr.DrawImage(bm, 0, 0, new Rectangle(min_x, min_y, shield_wid, shield_hgt), GraphicsUnit.Pixel);
|
||||
|
||||
// Return the shield.
|
||||
return shield_bm;
|
||||
}
|
||||
}
|
||||
19
Pilz.Updating.Client.Gui/Symbols/GlobalSymbolFactory.cs
Normal file
19
Pilz.Updating.Client.Gui/Symbols/GlobalSymbolFactory.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Pilz.UI.Telerik;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pilz.Updating.Client.Gui;
|
||||
|
||||
public class GlobalSymbolFactory : SymbolFactory<GlobalSymbols>
|
||||
{
|
||||
public static GlobalSymbolFactory Instance { get; } = new();
|
||||
|
||||
public override Assembly GetSvgImageResourceAssembly()
|
||||
{
|
||||
return Assembly.GetExecutingAssembly();
|
||||
}
|
||||
|
||||
public override string GetSvgImageRessourcePath(GlobalSymbols svgImage)
|
||||
{
|
||||
return $"{GetType().Namespace}.Symbols.{Enum.GetName(svgImage)}.svg";
|
||||
}
|
||||
}
|
||||
12
Pilz.Updating.Client.Gui/Symbols/GlobalSymbols.cs
Normal file
12
Pilz.Updating.Client.Gui/Symbols/GlobalSymbols.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Pilz.Updating.Client.Gui;
|
||||
|
||||
public enum GlobalSymbols
|
||||
{
|
||||
cancel,
|
||||
copy,
|
||||
done,
|
||||
open_archive,
|
||||
recycle_bin,
|
||||
software_installer,
|
||||
timer,
|
||||
}
|
||||
6
Pilz.Updating.Client.Gui/Symbols/Symbols/cancel.svg
Normal file
6
Pilz.Updating.Client.Gui/Symbols/Symbols/cancel.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32">
|
||||
<path fill="#f44336" d="M44,24c0,11-9,20-20,20S4,35,4,24S13,4,24,4S44,13,44,24z" />
|
||||
<line x1="16.9" x2="31.1" y1="16.9" y2="31.1" fill="none" stroke="#fff" stroke-width="4" />
|
||||
<line x1="31.1" x2="16.9" y1="16.9" y2="31.1" fill="none" stroke="#fff" stroke-width="4" />
|
||||
</svg>
|
||||
11
Pilz.Updating.Client.Gui/Symbols/Symbols/copy.svg
Normal file
11
Pilz.Updating.Client.Gui/Symbols/Symbols/copy.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 48 48">
|
||||
<path fill="#42A5F5" d="M31 36L6 36 6 3 23 3 31 11z" />
|
||||
<path fill="#E1F5FE" d="M29.5 12L22 12 22 4.5z" />
|
||||
<path fill="#1565C0" d="M11 16H27V18H11zM11 20H23V22H11zM11 24H27V26H11zM11 28H23V30H11z" />
|
||||
<path fill="#90CAF9" d="M42 44L17 44 17 11 34 11 42 19z" />
|
||||
<path fill="#E1F5FE" d="M40.5 20L33 20 33 12.5z" />
|
||||
<g>
|
||||
<path fill="#1976D2" d="M22 24H37V26H22zM22 28H33V30H22zM22 32H37V34H22zM22 36H33V38H22z" />
|
||||
</g>
|
||||
</svg>
|
||||
4
Pilz.Updating.Client.Gui/Symbols/Symbols/done.svg
Normal file
4
Pilz.Updating.Client.Gui/Symbols/Symbols/done.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32">
|
||||
<path fill="#43A047" d="M40.6 12.1L17 35.7 7.4 26.1 4.6 29 17 41.3 43.4 14.9z" />
|
||||
</svg>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32">
|
||||
<path fill="#90CAF9" d="M8 3H40V45H8z" />
|
||||
<path fill="#42A5F5" d="M8 3L22 27 26 27 40 3z" />
|
||||
<path fill="#3F51B5" d="M26,27h-4c0,3-2,6-2,8c0,2.2,1.8,4,4,4s4-1.8,4-4C28,33,26,30,26,27z M24,37c-1.1,0-2-0.9-2-2s0.9-2,2-2s2,0.9,2,2S25.1,37,24,37z" />
|
||||
<path fill="#1565C0" d="M30.5,19.3l-1,1.7l-3.5-2l1-1.7L30.5,19.3z M29,13.8l-1,1.7l3.5,2l1-1.7L29,13.8z M25.1,20.7l-1,1.7l3.5,2l1-1.7L25.1,20.7z M33.1,6.9l-1,1.7l3.5,2l1-1.7L33.1,6.9z M35.1,3.4l-1,1.7l3.5,2l1-1.7L35.1,3.4z M31.1,10.4l-1,1.7l3.5,2l1-1.7L31.1,10.4z M17.5,19.3l1,1.7l3.5-2l-1-1.7L17.5,19.3z M15.5,15.8l1,1.7l3.5-2l-1-1.7L15.5,15.8z M19.6,22.7l1,1.7l3.5-2l-1-1.7L19.6,22.7z M11.5,8.9l1,1.7l3.5-2l-1-1.7L11.5,8.9z M9.4,5.5l1,1.7l3.5-2l-1-1.7L9.4,5.5z M13.5,12.4l1,1.7l3.5-2l-1-1.7L13.5,12.4z M26,27l0.5-0.8l-2.4-1.4l-2.5,1.4L22,27H26z" />
|
||||
</svg>
|
||||
13
Pilz.Updating.Client.Gui/Symbols/Symbols/recycle_bin.svg
Normal file
13
Pilz.Updating.Client.Gui/Symbols/Symbols/recycle_bin.svg
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32">
|
||||
<path fill="#e3f2fd" d="M39.996,7l-4.011,31.875l-0.008,0.062V39v2c0,0.551-0.449,1-1,1H13c-0.551,0-1-0.449-1-1v-2v-0.062 l-0.008-0.061L8.032,7.005h31.958L39.996,7" />
|
||||
<path fill="#bbdefb" d="M38.862,8.005L34.993,38.75l-0.016,0.124V39v2H13v-2v-0.124l-0.015-0.123L9.16,8.005H38.862 M39.991,6.005H8.032c-0.618,0-1.09,0.53-0.998,1.12L11,39v2c0,1.105,0.895,2,2,2h21.977c1.105,0,2-0.895,2-2v-2l4.011-31.875 C41.081,6.536,40.608,6.005,39.991,6.005L39.991,6.005z" />
|
||||
<path fill="#78909c" d="M41.837 7.15l.152-1C42.08 5.545 41.612 5 41 5H7C6.388 5 5.92 5.545 6.011 6.15l.152 1C6.237 7.639 6.657 8 7.152 8h33.697C41.343 8 41.763 7.639 41.837 7.15zM34.977 43H13c-1.105 0-2-.895-2-2v-2h25.977v2C36.977 42.105 36.082 43 34.977 43z" />
|
||||
<path fill="#1e88e5" d="M24.74 29L26.49 32 26.49 26z" />
|
||||
<path fill="#1565c0" d="M30.238,29.381l1.555-3.151c0.312-0.633,0.268-1.384-0.117-1.975L30.354,22L27,24.18L30.238,29.381z" />
|
||||
<path fill="#1e88e5" d="M26.24 31l2.564-.018c.389.019.754-.189.936-.535l2.015-4.137c0 0-.547.697-2.118.697L26.115 27 26.24 31zM20 22.5L16.375 22.5 21.5 25.75z" />
|
||||
<path fill="#1565c0" d="M16.75,27l1.788,3.002c0.36,0.607,1.006,0.997,1.712,0.998H23v-4H16.75z" />
|
||||
<path fill="#1e88e5" d="M17.45 22.745l-1.26 2.158c-.229.316-.253.735-.063 1.076l2.365 3.947c0 0-.285-.839.573-2.155l1.804-2.946L17.45 22.745zM28 21.736L29.25 18.736 24 21.736z" />
|
||||
<path fill="#1565c0" d="M25.313,17H21.8c-0.706,0-1.359,0.388-1.719,0.995l-1.395,2.354l3.441,2.04L25.313,17z" />
|
||||
<path fill="#1e88e5" d="M27.394,17.588C27.219,17.24,26.89,17.009,26.5,17h-4.625c0,0,0.929,0.078,1.625,1.486l1.484,2.931 l3.53-1.885C28.515,19.532,27.646,18.089,27.394,17.588z" />
|
||||
</svg>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 48 48">
|
||||
<path fill="#78909C" d="M6,29v10c0,2.209,1.791,4,4,4h28c2.209,0,4-1.791,4-4V29H6z" />
|
||||
<path fill="#455A64" d="M42,29c0,2.209-1.791,4-4,4H10c-2.209,0-4-1.791-4-4l3-18c0.219-2.094,1.791-4,4-4h22c2.209,0,3.688,1.75,4,4L42,29z" />
|
||||
<path fill="#64DD17" d="M35 36A2 2 0 1 0 35 40A2 2 0 1 0 35 36Z" />
|
||||
<path fill="#00E5FF" d="M24.001 27.242L32 19.242 16 19.242z" />
|
||||
<path fill="#00E5FF" d="M21 4H26.998V19.999000000000002H21z" />
|
||||
</svg>
|
||||
11
Pilz.Updating.Client.Gui/Symbols/Symbols/timer.svg
Normal file
11
Pilz.Updating.Client.Gui/Symbols/Symbols/timer.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32">
|
||||
<path fill="#7cb342" d="M44,24c0,11.047-8.953,20-20,20S4,35.047,4,24S12.953,4,24,4S44,12.953,44,24" />
|
||||
<path fill="#dcedc8" d="M9.924,9.793C13.54,6.214,18.512,4,24,4v20L9.924,9.793z" />
|
||||
<path fill="#fff" d="M40,24c0,8.836-7.164,16-16,16S8,32.836,8,24S15.164,8,24,8S40,15.164,40,24" />
|
||||
<path d="M22.08,24.562c0.312,1.057,1.424,1.666,2.481,1.354c1.057-0.312,1.666-1.42,1.354-2.478c-0.312-1.061-1.42-1.666-2.478-1.358C22.377,22.393,21.772,23.501,22.08,24.562" />
|
||||
<path d="M9.924,9.793l15.236,12.582l-2.749,2.838L9.924,9.793z" />
|
||||
<path fill="#8bc34a" d="M23,23.996c0,0.555,0.449,1,1,1s1-0.445,1-1c0-0.551-0.449-1-1-1S23,23.445,23,23.996" />
|
||||
<path fill="#dcedc8" d="M19.214,4.6C19.079,5.044,19,5.511,19,6c0,2.76,2.24,5,5,5s5-2.24,5-5c0-0.489-0.079-0.956-0.214-1.4C27.25,4.222,25.653,4,24,4S20.75,4.222,19.214,4.6z" />
|
||||
<path fill="#33691e" d="M27,6c0,1.656-1.344,3-3,3s-3-1.344-3-3s1.344-3,3-3S27,4.344,27,6z" />
|
||||
</svg>
|
||||
@@ -1,10 +1,18 @@
|
||||
namespace Pilz.Updating.Client.Gui;
|
||||
using Pilz.UI.Telerik;
|
||||
using Pilz.Updating.UpdateInstaller.My.Resources;
|
||||
using Telerik.WinControls;
|
||||
|
||||
namespace Pilz.Updating.Client.Gui;
|
||||
|
||||
public partial class UpdateWindow : Telerik.WinControls.UI.RadForm
|
||||
{
|
||||
// P r o p e r t i e s
|
||||
|
||||
public bool AllowClose { get; set; }
|
||||
|
||||
// C o n s t r u c t o r s
|
||||
|
||||
public UpdateWindow()
|
||||
public UpdateWindow(string applicationName)
|
||||
{
|
||||
// Init Form
|
||||
InitializeComponent();
|
||||
@@ -16,100 +24,76 @@ public partial class UpdateWindow : Telerik.WinControls.UI.RadForm
|
||||
|
||||
// Init Application Header Text
|
||||
string header;
|
||||
if (!string.IsNullOrEmpty(installer.Configuration.ApplicationName))
|
||||
header = string.Format(My.Resources.UpdateInstallerGuiLangRes.String_UpdatingApplicationX, installer.Configuration.ApplicationName);
|
||||
if (!string.IsNullOrEmpty(applicationName))
|
||||
header = string.Format(UpdateInstallerLangRes.String_UpdatingApplicationX, applicationName);
|
||||
else
|
||||
header = My.Resources.UpdateInstallerGuiLangRes.String_UpdateIsRunning;
|
||||
header = UpdateInstallerLangRes.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;
|
||||
var newStatusText = string.Empty;
|
||||
RadSvgImage newStatusImage = null;
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case UpdateStatus.Copying:
|
||||
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_CopyingFiles;
|
||||
newStatusText = UpdateInstallerLangRes.Status_CopyingFiles;
|
||||
break;
|
||||
case UpdateStatus.Done:
|
||||
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Done;
|
||||
newStatusText = UpdateInstallerLangRes.Status_Done;
|
||||
break;
|
||||
case UpdateStatus.Extracting:
|
||||
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Extracting;
|
||||
newStatusText = UpdateInstallerLangRes.Status_Extracting;
|
||||
break;
|
||||
case UpdateStatus.Cleanup:
|
||||
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_RemovingFiles;
|
||||
newStatusText = UpdateInstallerLangRes.Status_RemovingFiles;
|
||||
break;
|
||||
case UpdateStatus.Waiting:
|
||||
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Waiting;
|
||||
newStatusText = UpdateInstallerLangRes.Status_Waiting;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case UpdateStatus.Copying:
|
||||
newStatusImage = MyIcons.icons8_copy_16px;
|
||||
newStatusImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.copy, SvgImageSize.Small);
|
||||
break;
|
||||
case UpdateStatus.Extracting:
|
||||
newStatusImage = MyIcons.icons8_open_archive_16px;
|
||||
newStatusImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.open_archive, SvgImageSize.Small);
|
||||
break;
|
||||
case UpdateStatus.Cleanup:
|
||||
newStatusImage = MyIcons.icons8_recycle_bin_16px;
|
||||
newStatusImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.recycle_bin, SvgImageSize.Small);
|
||||
break;
|
||||
case UpdateStatus.Waiting:
|
||||
newStatusImage = MyIcons.icons8_sand_timer_16px;
|
||||
newStatusImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.timer, SvgImageSize.Small);
|
||||
break;
|
||||
case UpdateStatus.Done:
|
||||
newStatusImage = MyIcons.icons8_checkmark_16px;
|
||||
newStatusImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.done, SvgImageSize.Small);
|
||||
break;
|
||||
}
|
||||
|
||||
radLabel_Status.Text = newStatusText;
|
||||
radLabel_Status.Image = newStatusImage;
|
||||
radLabel_Status.SvgImage = 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)
|
||||
private void Main_Shown(object sender, EventArgs e)
|
||||
{
|
||||
radWaitingBar1.StartWaiting();
|
||||
await WaitforHostApp();
|
||||
ExecuteUpdate();
|
||||
}
|
||||
|
||||
private void Main_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
installer.StartHostApplication();
|
||||
radWaitingBar1.StopWaiting();
|
||||
}
|
||||
|
||||
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)));
|
||||
if (!AllowClose)
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user