allow local folders as packagesource

This commit is contained in:
Pilzinsel64
2024-08-30 09:31:44 +02:00
parent 638cbb7b2c
commit 6cd7171819
5 changed files with 70 additions and 27 deletions

View File

@@ -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

View File

@@ -0,0 +1,7 @@
namespace Pilz.Updating.Client;
public enum UpdateMethod
{
Replace,
Temp,
}