From d32a4272e36611b5662d74ecb860096ec9f6bbc8 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Wed, 4 Sep 2024 09:32:03 +0200 Subject: [PATCH] add single file type --- Pilz.Updating.Client/UpdateClient.cs | 25 +++++++++++++++---------- Pilz.Updating/PackageType.cs | 1 + Pilz.Updating/UpdatePackageInfo.cs | 12 +++++++++++- Pilz.Updating/UpdateType.cs | 7 +++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 Pilz.Updating/UpdateType.cs diff --git a/Pilz.Updating.Client/UpdateClient.cs b/Pilz.Updating.Client/UpdateClient.cs index 219dc7f..719c003 100644 --- a/Pilz.Updating.Client/UpdateClient.cs +++ b/Pilz.Updating.Client/UpdateClient.cs @@ -111,7 +111,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne if (package.AddressType == PackageAddressType.Http) { var dirPath = Path.Combine(MyPaths.GetMyAppDataPath(), package.GetHashCode().ToString()); - var zipPath = Path.Combine(dirPath, "package.zip"); + var zipPath = Path.Combine(dirPath, package.PackageType == PackageType.File ? "app.exe" : "package.zip"); var dir = new DirectoryInfo(dirPath); try @@ -127,7 +127,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne await zipStream.CopyToAsync(zipFile); // Remember path to package directory - dicPackagePaths.Add(package, dirPath); + dicPackagePaths.Add(package, zipPath); } catch (Exception) { @@ -163,7 +163,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne return; } string dataPath; - if (package.Type == PackageType.Zip) + if (package.PackageType == PackageType.Zip) { dataPath = packagePath + ".extracted"; var packagePathDir = new DirectoryInfo(packagePath); @@ -174,26 +174,31 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne } ZipFile.ExtractToDirectory(packagePath, dataPath); } - else if (package.Type == PackageType.Folder) - dataPath = packagePath; else - throw new NotImplementedException("This PackageType is not defined and not support!"); + dataPath = packagePath; RaiseStatusChanged(UpdateStatus.Extracting, UpdateStatusEvent.PostEvent); // Install Package RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent); - var dataPathDir = Directory.CreateDirectory(dataPath); - var destDir = Directory.CreateDirectory(localInstallPath); - Utils.CopyFiles(dataPathDir, destDir); + if (package.UpdateType == UpdateType.Folder) + { + var dataPathDir = Directory.CreateDirectory(dataPath); + var destDir = Directory.CreateDirectory(localInstallPath); + Utils.CopyFiles(dataPathDir, destDir); + } + else if (package.UpdateType == UpdateType.File) + File.Copy(dataPath, localInstallPath); RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent); // Delete Package RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent); - if (package.Type == PackageType.Zip) + if (package.PackageType == PackageType.Zip) { File.Delete(packagePath); Directory.Delete(dataPath, true); } + else if (package.PackageType == PackageType.File) + File.Delete(dataPath); RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent); // Finish diff --git a/Pilz.Updating/PackageType.cs b/Pilz.Updating/PackageType.cs index 25ca023..2781f35 100644 --- a/Pilz.Updating/PackageType.cs +++ b/Pilz.Updating/PackageType.cs @@ -4,4 +4,5 @@ public enum PackageType { Zip, Folder, + File, } diff --git a/Pilz.Updating/UpdatePackageInfo.cs b/Pilz.Updating/UpdatePackageInfo.cs index a3abd7a..368286e 100644 --- a/Pilz.Updating/UpdatePackageInfo.cs +++ b/Pilz.Updating/UpdatePackageInfo.cs @@ -7,15 +7,25 @@ namespace Pilz.Updating; public class UpdatePackageInfo(AppVersion version, string address) { public string? Name { get; set; } + [JsonConverter(typeof(AppVersionStringJsonConverter))] public AppVersion Version { get; set; } = version; + public UpdateNotes Notes { get; } = new(); + public string Address { get; set; } = address; + public string? ExePath { get; set; } + [JsonConverter(typeof(StringEnumConverter))] public PackageAddressType AddressType { get; set; } + [JsonConverter(typeof(StringEnumConverter))] - public PackageType Type { get; set; } + public PackageType PackageType { get; set; } + + [JsonConverter(typeof(StringEnumConverter))] + public UpdateType UpdateType { get; set; } + [Obsolete, JsonProperty] private string Packagelink => Address; } \ No newline at end of file diff --git a/Pilz.Updating/UpdateType.cs b/Pilz.Updating/UpdateType.cs new file mode 100644 index 0000000..f4c1312 --- /dev/null +++ b/Pilz.Updating/UpdateType.cs @@ -0,0 +1,7 @@ +namespace Pilz.Updating; + +public enum UpdateType +{ + Folder, + File, +}