Skip to content

Commit

Permalink
Tools: Windows code signing
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Oct 4, 2024
1 parent 439b51f commit 53f58fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
14 changes: 13 additions & 1 deletion NAPS2.Tools/Project/Packaging/InnoSetupPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NAPS2.Tools.Project.Packaging;

public static class InnoSetupPackager
{
public static void PackageExe(Func<PackageInfo> pkgInfoFunc)
public static void PackageExe(Func<PackageInfo> pkgInfoFunc, bool noSign)
{
Output.Verbose("Building binaries");
Cli.Run("dotnet", "clean NAPS2.App.Worker -c Release");
Expand All @@ -15,6 +15,12 @@ public static void PackageExe(Func<PackageInfo> pkgInfoFunc)
Cli.Run("dotnet", "publish NAPS2.App.Console -c Release /p:DebugType=None /p:DebugSymbols=false");

var pkgInfo = pkgInfoFunc();
if (!noSign)
{
Output.Verbose("Signing contents");
WindowsSigning.SignContents(pkgInfo);
}

var exePath = pkgInfo.GetPath("exe");
Output.Info($"Packaging exe installer: {exePath}");

Expand All @@ -24,6 +30,12 @@ public static void PackageExe(Func<PackageInfo> pkgInfoFunc)
var iscc = Environment.ExpandEnvironmentVariables("%PROGRAMFILES(X86)%/Inno Setup 6/iscc.exe");
Cli.Run(iscc, $"\"{innoDefPath}\"");

if (!noSign)
{
Output.Verbose("Signing installer");
WindowsSigning.SignFile(exePath);
}

Output.OperationEnd($"Packaged exe installer: {exePath}");
}

Expand Down
6 changes: 3 additions & 3 deletions NAPS2.Tools/Project/Packaging/PackageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public int Run(PackageOptions opts)
switch (target.Type)
{
case PackageType.Exe:
InnoSetupPackager.PackageExe(GetPackageInfoForConfig);
InnoSetupPackager.PackageExe(GetPackageInfoForConfig, opts.NoSign);
break;
case PackageType.Msi:
WixToolsetPackager.PackageMsi(GetPackageInfoForConfig);
WixToolsetPackager.PackageMsi(GetPackageInfoForConfig, opts.NoSign);
break;
case PackageType.Zip:
ZipArchivePackager.PackageZip(GetPackageInfoForConfig);
ZipArchivePackager.PackageZip(GetPackageInfoForConfig, opts.NoSign);
break;
case PackageType.Deb:
DebPackager.PackageDeb(GetPackageInfoForConfig(), opts.NoSign);
Expand Down
15 changes: 14 additions & 1 deletion NAPS2.Tools/Project/Packaging/WixToolsetPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace NAPS2.Tools.Project.Packaging;

public static class WixToolsetPackager
{
public static void PackageMsi(Func<PackageInfo> pkgInfoFunc)
public static void PackageMsi(Func<PackageInfo> pkgInfoFunc, bool noSign)
{
Output.Verbose("Building binaries");
Cli.Run("dotnet", "clean NAPS2.App.Worker -c Release");
Expand All @@ -17,6 +17,12 @@ public static void PackageMsi(Func<PackageInfo> pkgInfoFunc)
Cli.Run("dotnet", "publish NAPS2.App.Console -c Release /p:DebugType=None /p:DebugSymbols=false /p:DefineConstants=MSI");

var pkgInfo = pkgInfoFunc();
if (!noSign)
{
Output.Verbose("Signing contents");
WindowsSigning.SignContents(pkgInfo);
}

var msiPath = pkgInfo.GetPath("msi");
Output.Info($"Packaging msi installer: {msiPath}");

Expand All @@ -30,6 +36,13 @@ public static void PackageMsi(Func<PackageInfo> pkgInfoFunc)

var light = Environment.ExpandEnvironmentVariables("%PROGRAMFILES(X86)%/WiX Toolset v3.11/bin/light.exe");
Cli.Run(light, $"\"{wixobjPath}\" -spdb -ext WixUIExtension -o \"{msiPath}\"");

if (!noSign)
{
Output.Verbose("Signing installer");
WindowsSigning.SignFile(msiPath);
}

Output.OperationEnd($"Packaged msi installer: {msiPath}");
}

Expand Down
8 changes: 7 additions & 1 deletion NAPS2.Tools/Project/Packaging/ZipArchivePackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NAPS2.Tools.Project.Packaging;

public static class ZipArchivePackager
{
public static void PackageZip(Func<PackageInfo> pkgInfoFunc)
public static void PackageZip(Func<PackageInfo> pkgInfoFunc, bool noSign)
{
Output.Verbose("Building binaries");
Cli.Run("dotnet", "clean NAPS2.App.Worker -c Release");
Expand All @@ -16,6 +16,12 @@ public static void PackageZip(Func<PackageInfo> pkgInfoFunc)
Cli.Run("dotnet", "build NAPS2.App.PortableLauncher -c Release");

var pkgInfo = pkgInfoFunc();
if (!noSign)
{
Output.Verbose("Signing contents");
WindowsSigning.SignContents(pkgInfo);
}

var zipPath = pkgInfo.GetPath("zip");
Output.Info($"Packaging zip archive: {zipPath}");

Expand Down

0 comments on commit 53f58fb

Please sign in to comment.