add single file type
This commit is contained in:
@@ -111,7 +111,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
if (package.AddressType == PackageAddressType.Http)
|
||||
{
|
||||
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);
|
||||
|
||||
try
|
||||
@@ -127,7 +127,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
await zipStream.CopyToAsync(zipFile);
|
||||
|
||||
// Remember path to package directory
|
||||
dicPackagePaths.Add(package, dirPath);
|
||||
dicPackagePaths.Add(package, zipPath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -163,7 +163,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
return;
|
||||
}
|
||||
string dataPath;
|
||||
if (package.Type == PackageType.Zip)
|
||||
if (package.PackageType == PackageType.Zip)
|
||||
{
|
||||
dataPath = packagePath + ".extracted";
|
||||
var packagePathDir = new DirectoryInfo(packagePath);
|
||||
@@ -174,26 +174,31 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChanne
|
||||
}
|
||||
ZipFile.ExtractToDirectory(packagePath, dataPath);
|
||||
}
|
||||
else if (package.Type == PackageType.Folder)
|
||||
dataPath = packagePath;
|
||||
else
|
||||
throw new NotImplementedException("This PackageType is not defined and not support!");
|
||||
dataPath = packagePath;
|
||||
RaiseStatusChanged(UpdateStatus.Extracting, UpdateStatusEvent.PostEvent);
|
||||
|
||||
// Install Package
|
||||
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent);
|
||||
var dataPathDir = Directory.CreateDirectory(dataPath);
|
||||
var destDir = Directory.CreateDirectory(localInstallPath);
|
||||
Utils.CopyFiles(dataPathDir, destDir);
|
||||
if (package.UpdateType == UpdateType.Folder)
|
||||
{
|
||||
var dataPathDir = Directory.CreateDirectory(dataPath);
|
||||
var destDir = Directory.CreateDirectory(localInstallPath);
|
||||
Utils.CopyFiles(dataPathDir, destDir);
|
||||
}
|
||||
else if (package.UpdateType == UpdateType.File)
|
||||
File.Copy(dataPath, localInstallPath);
|
||||
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent);
|
||||
|
||||
// Delete Package
|
||||
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PreEvent);
|
||||
if (package.Type == PackageType.Zip)
|
||||
if (package.PackageType == PackageType.Zip)
|
||||
{
|
||||
File.Delete(packagePath);
|
||||
Directory.Delete(dataPath, true);
|
||||
}
|
||||
else if (package.PackageType == PackageType.File)
|
||||
File.Delete(dataPath);
|
||||
RaiseStatusChanged(UpdateStatus.Cleanup, UpdateStatusEvent.PostEvent);
|
||||
|
||||
// Finish
|
||||
|
||||
@@ -4,4 +4,5 @@ public enum PackageType
|
||||
{
|
||||
Zip,
|
||||
Folder,
|
||||
File,
|
||||
}
|
||||
|
||||
@@ -7,15 +7,25 @@ namespace Pilz.Updating;
|
||||
public class UpdatePackageInfo(AppVersion version, string address)
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonConverter(typeof(AppVersionStringJsonConverter))]
|
||||
public AppVersion Version { get; set; } = version;
|
||||
|
||||
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 Type { get; set; }
|
||||
public PackageType PackageType { get; set; }
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public UpdateType UpdateType { get; set; }
|
||||
|
||||
[Obsolete, JsonProperty]
|
||||
private string Packagelink => Address;
|
||||
}
|
||||
7
Pilz.Updating/UpdateType.cs
Normal file
7
Pilz.Updating/UpdateType.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public enum UpdateType
|
||||
{
|
||||
Folder,
|
||||
File,
|
||||
}
|
||||
Reference in New Issue
Block a user