update nugets & cleanup

This commit is contained in:
2023-11-21 08:55:48 +01:00
parent c9e9239477
commit 5d031f8ead
45 changed files with 265 additions and 2002 deletions

View File

@@ -1,23 +1,37 @@
using global::System.IO;
using global::System.Reflection;
using System.IO;
using System.Reflection;
using Pilz.Plugins;
using System.Configuration;
using Z.Reflection.Extensions;
namespace Pilz.Updating.UpdateInstaller
{
internal static class General
{
private static string p = string.Empty;
private static string p = null;
public static string MyAppPath
{
get
{
if (string.IsNullOrEmpty(p))
{
p = Path.GetDirectoryName(IO.Extensions.GetExecutablePath());
}
return p;
}
}
public static void LoadAddons(bool isAfterCopyFiles, string folderPath)
{
var pluginsPath = Path.Combine(MyAppPath, "AddOns");
if (Directory.Exists(pluginsPath))
{
foreach (var subdir in Directory.GetDirectories(pluginsPath, string.Empty, SearchOption.TopDirectoryOnly))
{
var pluginPath = Path.Combine(subdir, Path.GetFileName(subdir) + ".dll");
if (File.Exists(pluginPath))
PluginManager.Instance.LoadPlugin(pluginPath);
}
}
}
}
}

View File

@@ -6,12 +6,14 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.Themes;
using Pilz.Updating.UpdateInstaller.Lib;
using Pilz.Plugins.Advanced;
using Pilz.Updating.UpdateInstaller.AddOns;
namespace Pilz.Updating.UpdateInstaller
{
public partial class Main
{
// C o n s t r u c t o r s
public Main()
@@ -26,58 +28,34 @@ namespace Pilz.Updating.UpdateInstaller
if (args.Any())
{
// Load config
Installer = new UpdateInstaller(UpdateInstallerConfig.Parse(args[0]));
installer = new Lib.UpdateInstaller(UpdateInstallerConfig.Parse(args[0]));
PluginFunctionController.Instance.ExecuteAll(UpdateInstallerFunctionTypes.OnInstancingUpdateInstaller);
// Init Form
InitializeComponent();
// Init Style
RadThemeComponentBase themeToUse = Installer.Configuration.UIDarkMode ? new FluentDarkTheme() : new FluentTheme();
RadThemeComponentBase themeToUse = installer.Configuration.UIDarkMode ? new FluentDarkTheme() : new FluentTheme();
ThemeResolutionService.ApplicationThemeName = themeToUse.ThemeName;
// 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(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>";
}
if (Installer is null)
if (installer is null)
Environment.Exit(0);
}
// F i e l d s
private bool allowClose = false;
private UpdateInstaller _Installer;
private UpdateInstaller Installer
{
get
{
return _Installer;
}
set
{
if (_Installer != null)
{
_Installer.StatusChanges -= Installer_StatusChanges;
}
_Installer = value;
if (_Installer != null)
{
_Installer.StatusChanges += Installer_StatusChanges;
}
}
}
private readonly Lib.UpdateInstaller installer;
// F e a t u r e s
@@ -97,9 +75,6 @@ namespace Pilz.Updating.UpdateInstaller
case UpdateInstallerStatus.Extracting:
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_Extracting;
break;
case UpdateInstallerStatus.RunningAddons:
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_RunningAddOns;
break;
case UpdateInstallerStatus.RemovingFiles:
newStatusText = My.Resources.UpdateInstallerGuiLangRes.Status_RemovingFiles;
break;
@@ -116,9 +91,6 @@ namespace Pilz.Updating.UpdateInstaller
case UpdateInstallerStatus.Extracting:
newStatusImage = MyIcons.icons8_open_archive_16px;
break;
case UpdateInstallerStatus.RunningAddons:
newStatusImage = MyIcons.icons8_console_16px_1;
break;
case UpdateInstallerStatus.RemovingFiles:
newStatusImage = MyIcons.icons8_recycle_bin_16px;
break;
@@ -143,12 +115,12 @@ namespace Pilz.Updating.UpdateInstaller
private async Task WaitforHostApp()
{
SetStatus(UpdateInstallerStatus.Waiting);
await Task.Run(() => Installer.WaitForHostApplication());
await Task.Run(() => installer.WaitForHostApplication());
}
private async void ExecuteUpdate()
{
await Task.Run(() => Installer.InstallUpdate());
await Task.Run(() => installer.InstallUpdate());
allowClose = true;
Close();
}
@@ -162,7 +134,7 @@ namespace Pilz.Updating.UpdateInstaller
private void Main_FormClosed(object sender, FormClosedEventArgs e)
{
Installer.StartHostApplication();
installer.StartHostApplication();
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)

View File

@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<StartupObject>Pilz.Updating.UpdateInstaller.My.MyApplication</StartupObject>
<RootNamespace>Pilz.Updating.UpdateInstaller</RootNamespace>
<MyType>WindowsForms</MyType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
<LangVersion>latest</LangVersion>
@@ -47,7 +47,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="Pilz.IO" Version="1.2023.914.856" />
<PackageReference Include="Pilz.IO" Version="2.0.0" />
<PackageReference Include="Pilz.Plugins" Version="2.0.0" />
<PackageReference Include="Pilz.Plugins.Advanced" Version="2.0.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
@@ -146,6 +148,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pilz.Updating.Administration\Pilz.Updating.Administration.csproj" />
<ProjectReference Include="..\Pilz.Updating.UpdateInstaller.AddOns\Pilz.Updating.UpdateInstaller.AddOns.csproj" />
<ProjectReference Include="..\Pilz.Updating.UpdateInstaller.Lib\Pilz.Updating.UpdateInstaller.Lib.csproj" />
<ProjectReference Include="..\Pilz.Updating\Pilz.Updating.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,185 +0,0 @@
using System;
using System.Diagnostics;
using global::System.IO;
using global::System.IO.Compression;
using System.Linq;
using global::System.Reflection;
using System.Threading.Tasks;
using Microsoft.VisualBasic.CompilerServices;
namespace Pilz.Updating.UpdateInstaller
{
internal class UpdateInstaller
{
// E v e n t s
public event StatusChangesEventHandler StatusChanges;
public delegate void StatusChangesEventHandler(object sender, UpdateInstallerStatusChangedEventArgs e);
// F i e l d s
private string dataPath = string.Empty;
// P r o p e r t i e s
public UpdateInstallerConfig Configuration { get; private set; }
// C o n s t r c u t o r s
public UpdateInstaller(UpdateInstallerConfig config)
{
Configuration = config;
}
// F e a t u r e s
private void ChangeStatus(UpdateInstallerStatus newStatus)
{
StatusChanges?.Invoke(this, new UpdateInstallerStatusChangedEventArgs(newStatus));
}
public void StartHostApplication()
{
if (!string.IsNullOrEmpty(Conversions.ToString(Configuration.RestartHostApplication)) && File.Exists(Configuration.HostApplicationProcessPath))
{
Process.Start(Configuration.HostApplicationProcessPath, Configuration.RestartHostApplicationArguments);
}
}
public void InstallUpdate()
{
// Extract Package
ChangeStatus(UpdateInstallerStatus.Extracting);
ExtractPackage();
// Install Package
InstallPackage();
// Delete Package
ChangeStatus(UpdateInstallerStatus.RemovingFiles);
DeletePackage();
// Finish
ChangeStatus(UpdateInstallerStatus.Done);
}
public void WaitForHostApplication()
{
bool forcedKill = false;
bool enabled = true;
var stw = new Stopwatch();
stw.Start();
Process[] getProcesses() => Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Configuration.HostApplicationProcessPath));
while (enabled)
{
if (getProcesses().Any())
{
if (stw.ElapsedMilliseconds >= Configuration.MillisecondsToWaitForHostApplicationToClose)
{
if (!forcedKill && Configuration.ForceClosingHostApplication)
{
foreach (Process p in getProcesses())
p.Kill();
stw.Reset();
forcedKill = true;
}
else
{
stw.Stop();
enabled = false;
}
}
}
else
{
enabled = false;
}
}
}
private void ExtractPackage()
{
string packagePath = Configuration.PackagePath;
string zipPath = Path.Combine(packagePath, PackageFileNameDefinations.ZIP_PACKAGE_FILENAME);
dataPath = Path.Combine(packagePath, Path.GetFileNameWithoutExtension(PackageFileNameDefinations.ZIP_PACKAGE_FILENAME));
var dataPathDir = new DirectoryInfo(dataPath);
if (dataPathDir.Exists)
{
dataPathDir.Delete(true);
Task.Delay(100);
}
ZipFile.ExtractToDirectory(zipPath, dataPath);
}
private void InstallPackage()
{
// Run installation addon
ChangeStatus(UpdateInstallerStatus.RunningAddons);
RunAddOns(false);
// Copy files
ChangeStatus(UpdateInstallerStatus.CopyingFiles);
CopyFiles();
// Run installation addon
ChangeStatus(UpdateInstallerStatus.RunningAddons);
RunAddOns(true);
}
private void CopyFiles()
{
var sourceDir = new DirectoryInfo(Path.Combine(dataPath, PackageFileNameDefinations.ZIP_APP_DATA_FILES_DIRECTORY));
var destDir = new DirectoryInfo(Configuration.HostApplicationPath);
CopyFiles(sourceDir, destDir);
}
private void CopyFiles(DirectoryInfo sourceDir, DirectoryInfo destinationDir)
{
if (!destinationDir.Exists)
{
destinationDir.Create();
}
foreach (FileInfo sFile in sourceDir.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
{
var dFile = new FileInfo(Path.Combine(destinationDir.FullName, sFile.Name));
try
{
sFile.CopyTo(dFile.FullName, true);
}
catch (Exception)
{
}
}
foreach (DirectoryInfo sDir in sourceDir.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
{
var dDir = destinationDir.CreateSubdirectory(sDir.Name);
CopyFiles(sDir, dDir);
}
}
private void RunAddOns(bool isAfterCopyFiles)
{
foreach (string addOnPath in Directory.GetFiles(Path.Combine(General.MyAppPath, "AddOns"))) // Directory.GetFiles(Path.Combine(dataPath, ZIP_UPDATE_INSTALLER_ADDONS_DIRECTORY))
{
var asm = Assembly.LoadFile(addOnPath);
var t = asm.GetType($"{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_NAMESPACE}.{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_TYPE}", false);
if (t is object)
{
var m = t.GetMethod(UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_METHOD, BindingFlags.Static | BindingFlags.Public);
m?.Invoke(null, new object[] { Configuration, isAfterCopyFiles });
}
}
}
private void DeletePackage()
{
Directory.Delete(Configuration.PackagePath, true);
}
}
}

View File

@@ -1,13 +0,0 @@
namespace Pilz.Updating.UpdateInstaller
{
internal enum UpdateInstallerStatus
{
Waiting,
Extracting,
CopyingFiles,
RunningAddons,
RemovingFiles,
Done
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace Pilz.Updating.UpdateInstaller
{
internal class UpdateInstallerStatusChangedEventArgs : EventArgs
{
public UpdateInstallerStatus NewStatus { get; private set; }
public UpdateInstallerStatusChangedEventArgs(UpdateInstallerStatus newStatus) : base()
{
NewStatus = newStatus;
}
}
}