[Installer] Make the Inno Setup installer the default, with its failure hook.

COCKATRICE_WIN_INSTALLER now defaults to InnoSetup. NSIS stays selectable for
one release as the legacy fallback, and the two can still be built from one
tree and compared on a real upgrade.

The switches question from the previous commit is settled from Inno Setup's
source: the setup command line is an if/else-if chain over the switches it
knows, with no fallback that rejects the rest, so /R, /PID= and /D= are
ignored rather than refused. The client therefore sends one command line that
drives either installer:

- /R and /PID= for NSIS, which also needs /D= last and unquoted;
- /VERYSILENT and the CloseApplications set for Setup, which releases the
  mapped runtime DLLs through Restart Manager instead of waiting for a pid;
- /UPDATER as the client's own mark, read only by the Inno Setup script.

An older client that passes only the NSIS switches still installs; it walks
the wizard once instead of running silently.

The Sentry offer that AbortInstall carried is ported: a silent run the updater
launched, which began replacing files and never reached the end, offers to
send its log through the same helper. The helper is embedded with a [Files]
dontcopy entry and extracted at send time; a repeated [Files] section merges
with the generated one instead of being a compile error. Setup prefixes every
log line with a timestamp, so the helper's ABORT scan now allows that prefix.

CI installs Inno Setup next to NSIS, dumps ISCCOutput.log and the generated
script when the installer fails to compile, and --package NSIS|InnoSetup
selects the installer through the CMake option instead of adding a second
CPack generator to the run.
This commit is contained in:
Lukas Brübach 2026-10-26 08:29:22 +01:00
parent 2c8e47a0a4
commit 0403ac9354
8 changed files with 220 additions and 73 deletions

View file

@ -1,9 +1,9 @@
# Windows installer written by Inno Setup, through CPack's own InnoSetup generator.
#
# Included from the WIN32 branch of the top-level CMakeLists.txt when
# COCKATRICE_WIN_INSTALLER is InnoSetup. It sits next to the NSIS template rather than
# replacing it so both installers can be built from the same tree and compared on a real
# upgrade.
# COCKATRICE_WIN_INSTALLER is InnoSetup, which is the default. The NSIS template is kept
# next to this file rather than deleted so both installers can still be built from one tree
# and compared on a real upgrade.
#
# The generator writes [Files], [Dirs], [Icons], [Run] and [Registry] from the install()
# rules the project already declares, so nothing here repeats them. What is added is only
@ -17,8 +17,10 @@ if(CMAKE_VERSION VERSION_LESS 3.27)
message(FATAL_ERROR "COCKATRICE_WIN_INSTALLER=InnoSetup needs CMake >= 3.27 (found ${CMAKE_VERSION})")
endif()
# CPack is allowed to be told -DCPACK_GENERATOR=... by the caller; do not list the
# generator twice when that caller already asked for it.
# CPack may be told -DCPACK_GENERATOR=... by the caller. For the Windows installers the
# choice is made by COCKATRICE_WIN_INSTALLER instead (.ci/compile.sh --package NSIS or
# InnoSetup maps to it), because picking the generator here and the installer tool there can
# silently build both in one run. Only guard against asking for InnoSetup twice.
if(NOT "InnoSetup" IN_LIST CPACK_GENERATOR)
set(CPACK_GENERATOR InnoSetup ${CPACK_GENERATOR})
endif()
@ -89,4 +91,13 @@ set(CPACK_INNOSETUP_SETUP_UninstallDisplayIcon "{app}\\cockatrice.exe")
set(CPACK_INNOSETUP_EXTRA_SCRIPTS "${COCKATRICE_CMAKE_PATH}/InnoSetup.install.iss")
set(CPACK_INNOSETUP_CODE_FILES "${COCKATRICE_CMAKE_PATH}/InnoSetup.code.iss")
# The installer-log sender the failure hook in InnoSetup.code.iss offers after an upgrade
# that did not finish. CPack passes these as public ISCC macros (/Dname=value), so the extra
# script can embed the helper with a [Files] dontcopy entry and the code can extract it at
# send time. Undefined when the build carries no reporting, which is what the ifdef guards in
# both scripts test.
if(CPACK_SENTRY_ENABLED)
set(CPACK_INNOSETUP_DEFINE_SentryHelperPath "${COCKATRICE_SENTRY_INSTALLER_LOG}")
endif()
message(STATUS "Windows installer: Inno Setup (CPack InnoSetup generator, ${CPACK_INNOSETUP_ARCHITECTURE})")

View file

@ -14,6 +14,12 @@ const
var
PortablePage: TCustomPage;
PortableCheck: TNewCheckBox;
// Progress of this run, for the failure hook further down. Setup has no "the installation
// failed" callback, and DeinitializeSetup runs on every way out of the wizard, so the two
// steps that bracket the file work are what distinguishes those ways.
InstallStarted: Boolean;
InstallCompleted: Boolean;
UserCancelled: Boolean;
// True when the given switch appears on the setup command line. Used for the legacy
// portable switch, which the in-app updater and the older installers pass.
@ -147,20 +153,93 @@ end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
InstallStarted := True;
if CurStep = ssPostInstall then
begin
InstallVCRedist();
WritePortableMarker();
RemoveLegacyNSISRegistration();
end;
if CurStep = ssDone then
InstallCompleted := True;
end;
// The 3.1.x client launches the installer with two switches that belong to the NSIS build:
// /R (silent reinstall) and /PID= (the process to wait for). Recording them from the log is
// how the first test of this installer answers the one open question about the migration:
// whether Inno Setup reaches this point at all with them on the command line. If it does,
// the updater keeps working across the switch; if it does not, Setup rejects them before
// running any script and the updater needs a version gate instead.
// Cancel is a decision, not a failure, so the hook below stays quiet after one.
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
UserCancelled := True;
end;
#ifdef SentryHelperPath
// The failure hook, which is what the NSIS template's AbortInstall did for updates that
// stopped half way. The three conditions it watched for - the application would not close,
// the stale runtime could not be purged, the launcher did not exit - are Restart Manager's
// and the [InstallDelete] section's job here, so what is left is the outcome rather than the
// cause: a silent run the in-app updater started, which began replacing files and never
// reached the end. That run is the one that needs it, because the updater quits after
// launching Setup and leaves no window on screen to read an error from; an interactive user
// sees the message Setup shows and can find the log in the temporary directory themselves.
procedure OfferToSendInstallerLog();
var
LogPath, Params: String;
ResultCode: Integer;
begin
LogPath := ExpandConstant('{log}');
if LogPath = '' then
Exit;
// The sender takes the reason from the log (see SendInstallerLog.ps1.in), so record it
// whether or not the user agrees: it is the first thing to look at in a report either way.
Log('ABORT: the update did not finish installing');
Log('full installer log: ' + LogPath);
if MsgBox('Send the installer log to the developers to help fix this? The log contains'
+ ' file paths from this machine, which may include your Windows user name.',
mbConfirmation, MB_YESNO) <> IDYES then
begin
Log('Sentry send: declined by user');
Exit;
end;
ExtractTemporaryFile('SendInstallerLog.ps1');
Params := '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "'
+ ExpandConstant('{tmp}\SendInstallerLog.ps1') + '" -LogPath "' + LogPath + '"';
ResultCode := -1;
if Exec('powershell.exe', Params, '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
and (ResultCode = 0) then
begin
Log('Sentry send: result=' + IntToStr(ResultCode));
MsgBox('The installer log was sent. Thank you for helping improve Cockatrice!',
mbInformation, MB_OK);
end
else
begin
Log('Sentry send: result=' + IntToStr(ResultCode));
MsgBox('The installer log could not be sent. You can still share it manually; it was'
+ ' written to:' + #13#10 + LogPath, mbError, MB_OK);
end;
end;
#endif
// Runs after logging has started and while the log is still open and flushed, which is what
// makes the log of this run available to the sender.
procedure DeinitializeSetup();
begin
#ifdef SentryHelperPath
// /UPDATER is the client's own mark on the command lines it hands either installer.
// Requiring it keeps this offer out of a package manager's silent install, where a message
// box that nobody answers would block the install - the case the NSIS template kept clear
// of by prompting on its /R switch rather than on silence alone.
if WizardSilent and HasSwitch('/UPDATER') and InstallStarted and not InstallCompleted
and not UserCancelled then
OfferToSendInstallerLog();
#endif
end;
// The in-app updater used to pass two switches that belong to the NSIS build: /R (silent
// reinstall) and /PID= (the process to wait for). Setup ignores switches it does not know -
// its command line is an if/else-if chain over the ones it does know, with no fallback that
// rejects the rest (ProcessCommandLine in Setup.MainFunc.pas) - so an older client still
// installs from this one, it just walks the wizard instead of running silently. Logging the
// switches keeps both cases visible in the log of the first upgrade that comes through here.
function InitializeSetup(): Boolean;
var
I: Integer;
@ -170,8 +249,9 @@ begin
for I := 1 to ParamCount do
begin
Param := ParamStr(I);
if (CompareText(Param, '/R') = 0) or (CompareText(Copy(Param, 1, 5), '/PID=') = 0) then
Log('Legacy in-app updater switch: ' + Param);
if (CompareText(Param, '/R') = 0) or (CompareText(Param, '/UPDATER') = 0)
or (CompareText(Copy(Param, 1, 5), '/PID=') = 0) then
Log('In-app updater switch: ' + Param);
end;
Result := True;
end;

View file

@ -1,9 +1,11 @@
; Sections added to the setup script CPack's Inno Setup generator writes.
;
; Included through CPACK_INNOSETUP_EXTRA_SCRIPTS, which prepends this file to the
; generated script. Only sections the generator never emits may appear here: it writes
; [Files], [Dirs], [Icons], [Run] and [Registry] from the install() rules, and a second
; section of one of those is a compile error. Behaviour belongs in InnoSetup.code.iss.
; generated script. Repeating a section that the generator also writes is not an error: the
; compiler re-tests every [Header] against the section it is collecting and enumerates the
; lines of each occurrence (FoundSection in TSetupCompiler.EnumIniSection,
; Compiler.SetupCompiler.pas), so the [Files] and [InstallDelete] below merge with the ones
; built from the install() rules. Behaviour belongs in InnoSetup.code.iss.
[InstallDelete]
; The previous version's runtime, whatever it was called. Replacing a DLL in place is not
@ -21,3 +23,14 @@ Type: filesandordirs; Name: "{app}\Plugins"
; install (RemoveLegacyNSISRegistration in InnoSetup.code.iss); the binary itself has no
; business staying next to the new one.
Type: files; Name: "{app}\Uninstall.exe"
; The installer-log sender behind the failure hook in InnoSetup.code.iss. dontcopy embeds
; the file in the setup image without installing it, and ExtractTemporaryFile pulls it out
; into the temporary directory only when something went wrong - what the NSIS template did
; by writing the same helper into $PLUGINSDIR. The path arrives from CMake as a public ISCC
; macro defined only for a build that carries a Sentry DSN; without one there is nothing to
; send, so nothing is embedded and the hook compiles out.
#ifdef SentryHelperPath
[Files]
Source: "{#SentryHelperPath}"; Flags: dontcopy
#endif

View file

@ -1,5 +1,5 @@
# Sends the NSIS installer log to Sentry as an envelope carrying one error
# event plus the log as an attachment.
# Sends the installer log, from either installer, to Sentry as an envelope carrying one
# error event plus the log as an attachment.
#
# Generated at configure time from this template by CMake configure_file: the
# CPACK_SENTRY_* placeholders are baked in then, so the real values only ever
@ -44,16 +44,20 @@ try {
}
# --- Abort reason, read from the log itself --------------------------------
# AbortInstall logs "ABORT: ..." first, so the reason travels inside the file
# and nothing reason-shaped crosses the command line (no quoting hazards).
# Select-String yields the matching line alone, so the reason is already one
# physical line for the message; anything else stays in the attached log.
# Non-ASCII paths may garble here; the attachment is byte-exact regardless.
# Each installer records the reason before offering to send, so it travels inside the
# file and nothing reason-shaped crosses the command line (no quoting hazards).
# NSIS writes the line as "ABORT: ..." through CockLog. Inno Setup prefixes every line
# of its log with a timestamp and three spaces, so that prefix is optional here and
# removed together with the marker. Select-String yields the matching line alone, so
# the reason is already one physical line for the message; anything else stays in the
# attached log. Non-ASCII paths may garble here; the attachment is byte-exact
# regardless.
$stamp = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\s+'
$Reason = 'unknown (no ABORT line in log)'
if (Test-Path -LiteralPath $LogPath) {
$abortLine = Select-String -LiteralPath $LogPath -Pattern '^ABORT: ' | Select-Object -Last 1
$abortLine = Select-String -LiteralPath $LogPath -Pattern ('^(' + $stamp + ')?ABORT: ') | Select-Object -Last 1
if ($abortLine) {
$Reason = ($abortLine.Line -replace '^ABORT:\s*', '')
$Reason = ($abortLine.Line -replace ('^(' + $stamp + ')?ABORT:\s*'), '')
}
}