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