add single file type

This commit is contained in:
Pilzinsel64
2024-09-04 09:32:03 +02:00
parent 0c93c1cee1
commit d32a4272e3
4 changed files with 34 additions and 11 deletions

View File

@@ -111,7 +111,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
if (package.AddressType == PackageAddressType.Http) if (package.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.zip"); var zipPath = Path.Combine(dirPath, package.PackageType == PackageType.File ? "app.exe" : "package.zip");
var dir = new DirectoryInfo(dirPath); var dir = new DirectoryInfo(dirPath);
try try
@@ -127,7 +127,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
await zipStream.CopyToAsync(zipFile); await zipStream.CopyToAsync(zipFile);
// Remember path to package directory // Remember path to package directory
dicPackagePaths.Add(package, dirPath); dicPackagePaths.Add(package, zipPath);
} }
catch (Exception) catch (Exception)
{ {
@@ -163,7 +163,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
return; return;
} }
string dataPath; string dataPath;
if (package.Type == PackageType.Zip) if (package.PackageType == PackageType.Zip)
{ {
dataPath = packagePath + ".extracted"; dataPath = packagePath + ".extracted";
var packagePathDir = new DirectoryInfo(packagePath); var packagePathDir = new DirectoryInfo(packagePath);
@@ -174,26 +174,31 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
} }
ZipFile.ExtractToDirectory(packagePath, dataPath); ZipFile.ExtractToDirectory(packagePath, dataPath);
} }
else if (package.Type == PackageType.Folder)
dataPath = packagePath;
else else
throw new NotImplementedException("This PackageType is not defined and not support!"); dataPath = packagePath;
RaiseStatusChanged(UpdateStatus.Extracting, UpdateStatusEvent.PostEvent); RaiseStatusChanged(UpdateStatus.Extracting, UpdateStatusEvent.PostEvent);
// Install Package // Install Package
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent); RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent);
if (package.UpdateType == UpdateType.Folder)
{
var dataPathDir = Directory.CreateDirectory(dataPath); var dataPathDir = Directory.CreateDirectory(dataPath);
var destDir = Directory.CreateDirectory(localInstallPath); var destDir = Directory.CreateDirectory(localInstallPath);
Utils.CopyFiles(dataPathDir, destDir); Utils.CopyFiles(dataPathDir, destDir);
}
else if (package.UpdateType == UpdateType.File)
File.Copy(dataPath, localInstallPath);
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent); RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent);
// Delete Package // Delete Package
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent); RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent);
if (package.Type == PackageType.Zip) if (package.PackageType == PackageType.Zip)
{ {
File.Delete(packagePath); File.Delete(packagePath);
Directory.Delete(dataPath, true); Directory.Delete(dataPath, true);
} }
else if (package.PackageType == PackageType.File)
File.Delete(dataPath);
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent); RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent);
// Finish // Finish

View File

@@ -4,4 +4,5 @@ public enum PackageType
{ {
Zip, Zip,
Folder, Folder,
File,
} }

View File

@@ -7,15 +7,25 @@ namespace Pilz.Updating;
public class UpdatePackageInfo(AppVersion version, string address) public class UpdatePackageInfo(AppVersion version, string address)
{ {
public string? Name { get; set; } public string? Name { get; set; }
[JsonConverter(typeof(AppVersionStringJsonConverter))] [JsonConverter(typeof(AppVersionStringJsonConverter))]
public AppVersion Version { get; set; } = version; public AppVersion Version { get; set; } = version;
public UpdateNotes Notes { get; } = new(); public UpdateNotes Notes { get; } = new();
public string Address { get; set; } = address; public string Address { get; set; } = address;
public string? ExePath { get; set; } public string? ExePath { get; set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public PackageAddressType AddressType { get; set; } public PackageAddressType AddressType { get; set; }
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public PackageType Type { get; set; } public PackageType PackageType { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public UpdateType UpdateType { get; set; }
[Obsolete, JsonProperty] [Obsolete, JsonProperty]
private string Packagelink => Address; private string Packagelink => Address;
} }

View File

@@ -0,0 +1,7 @@
namespace Pilz.Updating;
public enum UpdateType
{
Folder,
File,
}