diff --git a/Pilz.Updating.Client/UpdateClient.cs b/Pilz.Updating.Client/UpdateClient.cs index cf1c607..536bc3f 100644 --- a/Pilz.Updating.Client/UpdateClient.cs +++ b/Pilz.Updating.Client/UpdateClient.cs @@ -108,29 +108,36 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels { RaiseStatusChanged(UpdateStatus.Downloading, UpdateStatusEvent.PreEvent); - var dirPath = Path.Combine(MyPaths.GetMyAppDataPath(), package.GetHashCode().ToString()); - var zipPath = Path.Combine(dirPath, "package.zip"); - var dir = new DirectoryInfo(dirPath); - - try + if (package.AddressType == PackageAddressType.Http) { - // Ensure existing and empty directory for the Zip File - if (dir.Exists) - dir.Delete(true); - dir.Create(); + var dirPath = Path.Combine(MyPaths.GetMyAppDataPath(), package.GetHashCode().ToString()); + var zipPath = Path.Combine(dirPath, "package.zip"); + var dir = new DirectoryInfo(dirPath); - // Download zip package - using var zipFile = new FileStream(zipPath, FileMode.Create, FileAccess.ReadWrite); - using var zipStream = await WebClient.GetStreamAsync(package.Packagelink); - await zipStream.CopyToAsync(zipFile); + try + { + // Ensure existing and empty directory for the Zip File + if (dir.Exists) + dir.Delete(true); + dir.Create(); - // Remember path to package directory - dicPackagePaths.Add(package, dirPath); + // Download zip package + using var zipFile = new FileStream(zipPath, FileMode.Create, FileAccess.ReadWrite); + using var zipStream = await WebClient.GetStreamAsync(package.Address); + await zipStream.CopyToAsync(zipFile); + + // Remember path to package directory + dicPackagePaths.Add(package, dirPath); + } + catch (Exception) + { + return false; + } } - catch (Exception) - { + else if (package.AddressType == PackageAddressType.Local) + dicPackagePaths.Add(package, package.Address); + else return false; - } if (!RaiseStatusChanged(UpdateStatus.Downloading, UpdateStatusEvent.PostEvent, true)) { @@ -154,14 +161,22 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels RaiseStatusChanged(UpdateStatus.Failed); return; } - var dataPath = packagePath + ".extracted"; - var packagePathDir = new DirectoryInfo(packagePath); - if (packagePathDir.Exists) + string dataPath; + if (package.Type == PackageType.Zip) { - packagePathDir.Delete(true); - Task.Delay(1000); + dataPath = packagePath + ".extracted"; + var packagePathDir = new DirectoryInfo(packagePath); + if (packagePathDir.Exists) + { + packagePathDir.Delete(true); + Task.Delay(1000); + } + ZipFile.ExtractToDirectory(packagePath, dataPath); } - ZipFile.ExtractToDirectory(packagePath, dataPath); + else if (package.Type == PackageType.Folder) + dataPath = packagePath; + else + throw new NotImplementedException("This PackageType is not defined and not support!"); RaiseStatusChanged(UpdateStatus.Extracting, UpdateStatusEvent.PostEvent); // Install Package diff --git a/Pilz.Updating.Client/UpdateMethod.cs b/Pilz.Updating.Client/UpdateMethod.cs new file mode 100644 index 0000000..ad51fcd --- /dev/null +++ b/Pilz.Updating.Client/UpdateMethod.cs @@ -0,0 +1,7 @@ +namespace Pilz.Updating.Client; + +public enum UpdateMethod +{ + Replace, + Temp, +} diff --git a/Pilz.Updating/PackageAddressType.cs b/Pilz.Updating/PackageAddressType.cs new file mode 100644 index 0000000..18ece11 --- /dev/null +++ b/Pilz.Updating/PackageAddressType.cs @@ -0,0 +1,7 @@ +namespace Pilz.Updating; + +public enum PackageAddressType +{ + Http, + Local, +} diff --git a/Pilz.Updating/PackageType.cs b/Pilz.Updating/PackageType.cs new file mode 100644 index 0000000..25ca023 --- /dev/null +++ b/Pilz.Updating/PackageType.cs @@ -0,0 +1,7 @@ +namespace Pilz.Updating; + +public enum PackageType +{ + Zip, + Folder, +} diff --git a/Pilz.Updating/UpdatePackageInfo.cs b/Pilz.Updating/UpdatePackageInfo.cs index 80119e3..631ca22 100644 --- a/Pilz.Updating/UpdatePackageInfo.cs +++ b/Pilz.Updating/UpdatePackageInfo.cs @@ -1,9 +1,16 @@ -namespace Pilz.Updating; +using Newtonsoft.Json; -public class UpdatePackageInfo(AppVersion version, string packagelink) +namespace Pilz.Updating; + +public class UpdatePackageInfo(AppVersion version, string address) { public string? Name { get; set; } public AppVersion Version { get; set; } = version; public UpdateNotes Notes { get; } = new(); - public string Packagelink { get; set; } = packagelink; + public string Address { get; set; } = address; + public PackageAddressType AddressType { get; set; } + public PackageType Type { get; set; } + + [Obsolete, JsonProperty] + private string Packagelink => Address; } \ No newline at end of file