allow multiple distributions
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>4.2.12</Version>
|
||||
<Version>4.3.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -25,6 +25,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
public bool InstallAsAdmin { get; set; }
|
||||
public bool UIDarkMode { get; set; }
|
||||
public bool HasUpdates => UpdatePackageInfo != null;
|
||||
public string? Distro { get; set; }
|
||||
|
||||
// E v e n t M e t h o d s
|
||||
|
||||
@@ -111,10 +112,11 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
{
|
||||
RaiseStatusChanged(UpdateStatus.Downloading, UpdateStatusEvent.PreEvent);
|
||||
|
||||
if (package.AddressType == PackageAddressType.Http)
|
||||
var packageSource = package.GetSource(Distro);
|
||||
if (packageSource.AddressType == PackageAddressType.Http)
|
||||
{
|
||||
var dirPath = Path.Combine(MyPaths.GetMyAppDataPath(), package.GetHashCode().ToString());
|
||||
var zipPath = Path.Combine(dirPath, package.PackageType == PackageType.File ? "app.exe" : "package.zip");
|
||||
var zipPath = Path.Combine(dirPath, packageSource.PackageType == PackageType.File ? "app.exe" : "package.zip");
|
||||
var dir = new DirectoryInfo(dirPath);
|
||||
|
||||
try
|
||||
@@ -126,7 +128,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
|
||||
// Download zip package
|
||||
using var zipFile = new FileStream(zipPath, FileMode.Create, FileAccess.ReadWrite);
|
||||
using var zipStream = await WebClient.GetStreamAsync(package.GetAddress());
|
||||
using var zipStream = await WebClient.GetStreamAsync(package.GetAddress(Distro));
|
||||
await zipStream.CopyToAsync(zipFile);
|
||||
|
||||
// Remember path to package directory
|
||||
@@ -137,8 +139,8 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (package.AddressType == PackageAddressType.Local)
|
||||
dicPackagePaths.Add(package, package.GetAddress());
|
||||
else if (packageSource.AddressType == PackageAddressType.Local)
|
||||
dicPackagePaths.Add(package, package.GetAddress(Distro));
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -166,7 +168,8 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
return false;
|
||||
}
|
||||
string dataPath;
|
||||
if (package.PackageType == PackageType.Zip)
|
||||
var packageSource = package.GetSource(Distro);
|
||||
if (packageSource.PackageType == PackageType.Zip)
|
||||
{
|
||||
dataPath = packagePath + ".extracted";
|
||||
var packagePathDir = new DirectoryInfo(packagePath);
|
||||
@@ -195,12 +198,12 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
|
||||
// Delete Package
|
||||
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent);
|
||||
if (package.PackageType == PackageType.Zip)
|
||||
if (packageSource.PackageType == PackageType.Zip)
|
||||
{
|
||||
File.Delete(packagePath);
|
||||
Directory.Delete(dataPath, true);
|
||||
}
|
||||
else if (package.PackageType == PackageType.File && package.AddressType == PackageAddressType.Http)
|
||||
else if (packageSource.PackageType == PackageType.File && packageSource.AddressType == PackageAddressType.Http)
|
||||
File.Delete(dataPath);
|
||||
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent);
|
||||
|
||||
|
||||
15
Pilz.Updating/PackageSource.cs
Normal file
15
Pilz.Updating/PackageSource.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public class PackageSource(string address)
|
||||
{
|
||||
public string Address { get; set; } = address;
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public PackageAddressType AddressType { get; set; }
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public PackageType PackageType { get; set; }
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>4.2.5</Version>
|
||||
<Version>4.3.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@ using Pilz.Json;
|
||||
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public class UpdatePackageInfo(AppVersion version, string address)
|
||||
public class UpdatePackageInfo(AppVersion version)
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
@@ -13,25 +13,23 @@ public class UpdatePackageInfo(AppVersion version, string address)
|
||||
|
||||
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 PackageType { get; set; }
|
||||
public Dictionary<string, PackageSource> Packages = [];
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public UpdateType UpdateType { get; set; }
|
||||
|
||||
[Obsolete, JsonProperty]
|
||||
private string Packagelink => GetAddress();
|
||||
|
||||
public string GetAddress()
|
||||
public PackageSource GetSource(string? distro)
|
||||
{
|
||||
return Address
|
||||
if (distro == null || !Packages.TryGetValue(distro, out var definition))
|
||||
definition = Packages.Values.FirstOrDefault();
|
||||
return definition ?? throw new KeyNotFoundException("No package definition found!");
|
||||
}
|
||||
|
||||
public string GetAddress(string? distro)
|
||||
{
|
||||
return GetSource(distro).Address
|
||||
.Replace("{appversion}", Version.ToString())
|
||||
.Replace("{version}", Version.Version.ToString())
|
||||
.Replace("{channelstr}", Version.Channel.ToString())
|
||||
|
||||
Reference in New Issue
Block a user