mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Speed up SimpleFileSource
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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() });
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user