Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Copy Squirrel to release during releasify (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Aug 30, 2021
1 parent df894ec commit e88b523
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
}
}

// copy input package to target output directory
var di = new DirectoryInfo(targetDir);
File.Copy(package, Path.Combine(di.FullName, Path.GetFileName(package)), true);

Expand All @@ -357,6 +358,8 @@ public void Releasify(string package, string targetDir = null, string packagesDi

var rp = new ReleasePackage(file.FullName);
rp.CreateReleasePackage(Path.Combine(di.FullName, rp.SuggestedReleaseFileName), packagesDir, contentsPostProcessHook: pkgPath => {
// create sub executable for all exe's in this package (except Squirrel!)
new DirectoryInfo(pkgPath).GetAllFilesRecursively()
.Where(x => x.Name.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.Name.Contains("squirrel.exe", StringComparison.InvariantCultureIgnoreCase))
Expand All @@ -365,8 +368,18 @@ public void Releasify(string package, string targetDir = null, string packagesDi
.ForEachAsync(x => createExecutableStubForExe(x.FullName))
.Wait();
// copy myself into the package so Squirrel can also be updated
// how we find the lib dir is a huge hack here, but 'ReleasePackage' verifies there can only be one of these so it should be fine.
var re = new Regex(@"lib[\\\/][^\\\/]*[\\\/]?", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
var libDir = Directory
.EnumerateDirectories(pkgPath, "*", SearchOption.AllDirectories)
.Where(d => re.IsMatch(d))
.OrderBy(d => d.Length)
.FirstOrDefault();
File.Copy(getUpdateExePath(selfContained), Path.Combine(libDir, "Squirrel.exe"));
// sign all exe's in this package
if (signingOpts == null) return;
new DirectoryInfo(pkgPath).GetAllFilesRecursively()
.Where(x => Utility.FileIsLikelyPEImage(x.Name))
.ForEachAsync(async x => {
Expand Down Expand Up @@ -554,26 +567,26 @@ void waitForParentToExit()
}
}

string getUpdateExePath(bool selfContained)
{
if (selfContained) {
var selfPath = Path.Combine(AssemblyRuntimeInfo.BaseDirectory, "UpdateSelfContained.exe");
if (!File.Exists(selfPath)) {
this.Log().Error("Could not find UpdateSelfContained.exe in base directory. Am I published?");
}
return selfPath;
}
return AssemblyRuntimeInfo.EntryExePath;
}

async Task<string> createSetupEmbeddedZip(string fullPackage, string releasesDir, string signingOpts, string setupIcon, bool selfContained)
{
string tempPath;

this.Log().Info("Building embedded zip file for Setup.exe");
using (Utility.WithTempDirectory(out tempPath, null)) {
this.ErrorIfThrows(() => {
if (selfContained) {
var selfPath = Path.Combine(AssemblyRuntimeInfo.BaseDirectory, "UpdateSelfContained.exe");
if (File.Exists(selfPath)) {
File.Copy(selfPath, Path.Combine(tempPath, "Update.exe"));
} else {
this.Log().Error("Could not find UpdateSelfContained.exe in base directory. Am I published?");
throw new ArgumentException();
}
} else {
File.Copy(AssemblyRuntimeInfo.EntryExePath, Path.Combine(tempPath, "Update.exe"));
}
File.Copy(getUpdateExePath(selfContained), Path.Combine(tempPath, "Update.exe"));
File.Copy(fullPackage, Path.Combine(tempPath, Path.GetFileName(fullPackage)));
}, "Failed to write package files to temp dir: " + tempPath);

Expand Down

0 comments on commit e88b523

Please sign in to comment.