Speed up SimpleFileSource

This commit is contained in:
Caelan Sayler
2024-01-21 11:15:24 +00:00
parent d4b199d811
commit c33aae323b
3 changed files with 13 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ namespace Velopack.NuGet
public string LoadedFromPath { get; private set; }
public ZipPackage(string filePath)
public ZipPackage(string filePath, bool loadUpdateExe = false)
{
using var zipStream = File.OpenRead(filePath);
using var zip = new ZipArchive(zipStream, ZipArchiveMode.Read, false);
@@ -24,7 +24,10 @@ namespace Velopack.NuGet
LoadedFromPath = filePath;
Files = GetPackageFiles(zip).ToArray();
UpdateExeBytes = ReadFile(zip, f => f.FullName.EndsWith("Squirrel.exe"));
if (loadUpdateExe) {
UpdateExeBytes = ReadFile(zip, f => f.FullName.EndsWith("Squirrel.exe"));
}
}
protected byte[]? ReadFile(ZipArchive archive, Func<ZipArchiveEntry, bool> predicate)

View File

@@ -32,6 +32,13 @@ namespace Velopack.Sources
return Task.FromResult(new VelopackAssetFeed());
}
// if a feed exists in the folder, let's use that.
var feedLoc = Path.Combine(BaseDirectory.FullName, Utility.GetVeloReleaseIndexName(channel));
if (File.Exists(feedLoc)) {
return Task.FromResult(VelopackAssetFeed.FromJson(File.ReadAllText(feedLoc)));
}
// if not, we can try to iterate the packages, hopefully this is not a remote/network folder!
var list = new List<VelopackAsset>();
foreach (var pkg in Directory.EnumerateFiles(BaseDirectory.FullName, "*.nupkg")) {
try {
@@ -48,7 +55,6 @@ namespace Velopack.Sources
logger.Warn(ex, $"Error while reading local package '{pkg}'.");
}
}
return Task.FromResult(new VelopackAssetFeed { Assets = list.ToArray() });
}

View File

@@ -266,7 +266,7 @@ namespace Velopack
try {
var updateExe = Locator.UpdateExePath!;
Log.Info("Extracting new Update.exe to " + updateExe);
var zip = new ZipPackage(completeFile);
var zip = new ZipPackage(completeFile, loadUpdateExe: true);
if (zip.UpdateExeBytes == null) {
Log.Error("Update.exe not found in package, skipping extraction.");