From 6487c54797ebc04f9a37030f959f6d09007b5704 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sun, 9 Nov 2025 13:39:44 +0100 Subject: [PATCH] Add Path package source property --- .../Pilz.Updating.Client.csproj | 2 +- Pilz.Updating.Client/UpdateClient.cs | 47 ++++++++++++------- Pilz.Updating/PackageSource.cs | 1 + Pilz.Updating/Pilz.Updating.csproj | 2 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Pilz.Updating.Client/Pilz.Updating.Client.csproj b/Pilz.Updating.Client/Pilz.Updating.Client.csproj index 50ce849..6bbc89c 100644 --- a/Pilz.Updating.Client/Pilz.Updating.Client.csproj +++ b/Pilz.Updating.Client/Pilz.Updating.Client.csproj @@ -8,7 +8,7 @@ - 4.4.3 + 4.4.4 diff --git a/Pilz.Updating.Client/UpdateClient.cs b/Pilz.Updating.Client/UpdateClient.cs index 1702bd1..d9dfe9c 100644 --- a/Pilz.Updating.Client/UpdateClient.cs +++ b/Pilz.Updating.Client/UpdateClient.cs @@ -189,18 +189,30 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne // Install Package RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent); - if (package.UpdateType == UpdateType.Folder) + switch (package.UpdateType) { - var dataPathDir = Directory.CreateDirectory(dataPath); - var destDir = Directory.CreateDirectory(localInstallPath); - Utils.CopyFiles(dataPathDir, destDir); - } - else if (package.UpdateType == UpdateType.File) - { - if (packageSource.PackageType == PackageType.File) - Utils.CopyFile(new FileInfo(dataPath), new FileInfo(localInstallPath)); - else if (Directory.GetFiles(dataPath).FirstOrDefault() is { } firstFile) - Utils.CopyFile(new FileInfo(firstFile), new FileInfo(localInstallPath)); + case UpdateType.Folder: + { + var dataPathDir = Directory.CreateDirectory(dataPath); + var destDir = Directory.CreateDirectory(localInstallPath); + Utils.CopyFiles(dataPathDir, destDir); + break; + } + case UpdateType.File: + { + string? srcFilePath = null; + + if (packageSource.PackageType == PackageType.File) + srcFilePath = dataPath; + else if (!string.IsNullOrWhiteSpace(packageSource.Address)) + srcFilePath = Path.Combine(dataPath, packageSource.Address); + else if (Directory.GetFiles(dataPath).FirstOrDefault() is { } firstFile) + srcFilePath = firstFile; + + if (srcFilePath != null) + Utils.CopyFile(new FileInfo(srcFilePath), new FileInfo(localInstallPath)); + break; + } } RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent); @@ -220,13 +232,16 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne // Delete Package RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent); - if (packageSource.PackageType == PackageType.Zip) + switch (packageSource.PackageType) { - File.Delete(packagePath); - Directory.Delete(dataPath, true); + case PackageType.Zip: + File.Delete(packagePath); + Directory.Delete(dataPath, true); + break; + case PackageType.File when packageSource.AddressType == PackageAddressType.Http: + File.Delete(dataPath); + break; } - else if (packageSource.PackageType == PackageType.File && packageSource.AddressType == PackageAddressType.Http) - File.Delete(dataPath); RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent); // Finish diff --git a/Pilz.Updating/PackageSource.cs b/Pilz.Updating/PackageSource.cs index e7b4fbd..594a52f 100644 --- a/Pilz.Updating/PackageSource.cs +++ b/Pilz.Updating/PackageSource.cs @@ -6,6 +6,7 @@ namespace Pilz.Updating; public class PackageSource(string address) { public string Address { get; set; } = address; + public string? Path { get; set; } [JsonConverter(typeof(StringEnumConverter))] public PackageAddressType AddressType { get; set; } diff --git a/Pilz.Updating/Pilz.Updating.csproj b/Pilz.Updating/Pilz.Updating.csproj index 5b42de3..219b5e7 100644 --- a/Pilz.Updating/Pilz.Updating.csproj +++ b/Pilz.Updating/Pilz.Updating.csproj @@ -8,7 +8,7 @@ - 4.3.4 + 4.3.5