[Installer] Add an Inno Setup generator next to NSIS.

COCKATRICE_WIN_INSTALLER chooses which tool writes the Windows installer.
NSIS stays the default, so nothing on the existing path changes; InnoSetup
selects CPack's own INNOSETUP generator (CMake >= 3.27) and builds from the
same install() rules. Both can be built from one tree and the resulting
installers compared on an upgrade from 3.1.x.

What the Inno path does differently:

- Installs over the previous version instead of running the old uninstaller
  first, which is what the backup/restore pair in the NSIS template exists
  to survive.
- Closes and restarts a running application through Windows Restart Manager
  (CloseApplications/RestartApplications) instead of the two PowerShell
  process guards the template needed.
- Removes stale runtime with one [InstallDelete] of *.dll and Plugins,
  instead of RetryDllPurge and its diagnostics.
- Writes a log on every run through SetupLogging, instead of CockLog.
- Resolves the install directory from the legacy NSIS registration, and
  deletes that registration after a successful install so the old
  uninstaller (whose blanket directory removal caused the 3.1.x data loss)
  cannot be run after the upgrade.
- Keeps the portable mode the client detects, the C++ runtime bootstrap and
  the /PORTABLE switch.

The in-app updater still passes the NSIS switches (/R, /PID=); the installer
logs them so the first Windows run settles whether Inno Setup accepts them or
the switch-over needs a client version gate.

The installer content check in .ci/compile.sh learns to strip Inno Setup's
{app} prefix from the paths 7-Zip lists, so the required-runtime comparison
works for either archive format.
This commit is contained in:
Lukas Brübach 2026-10-26 07:52:44 +01:00
parent 675e1f7447
commit 2c8e47a0a4
5 changed files with 333 additions and 20 deletions

View file

@ -590,20 +590,22 @@ if [[ $MAKE_PACKAGE ]]; then
fi fi
# 7-Zip writes CRLF on Windows, so the \r has to come off before any # 7-Zip writes CRLF on Windows, so the \r has to come off before any
# whole-line comparison below. Normalize separators to /, and strip the # whole-line comparison below. Normalize separators to /, and strip the
# install-root prefixes an NSIS listing may carry, so the entries can be # install-root prefixes a listing may carry - $INSTDIR/$OUTDIR/$PLUGINSDIR
# compared as exact relative paths. -xF keeps a '.' in a DLL name from # from NSIS, {app} from Inno Setup - so the entries can be compared as exact
# being a wildcard; -i because that is how the installed tree behaves - # relative paths. -xF keeps a '.' in a DLL name from being a wildcard; -i
# the uninstaller clears both $INSTDIR\plugins and $INSTDIR\Plugins. # because that is how the installed tree behaves - the uninstaller clears
# The archive side and the manifest side have to agree on line endings. # both $INSTDIR\plugins and $INSTDIR\Plugins. The archive side and the
# CMake writes required-runtime.txt with the platform's line ending and # manifest side have to agree on line endings. CMake writes
# 7-Zip writes CRLF on Windows, so a trailing \r survives on $entry and # required-runtime.txt with the platform's line ending and 7-Zip writes CRLF
# defeats the whole-line match - every entry then reads as missing even # on Windows, so a trailing \r survives on $entry and defeats the whole-line
# though the listing holds it verbatim. # match - every entry then reads as missing even though the listing holds it
# verbatim.
# [$] rather than \$ so the literal dollar is a bracket expression and the # [$] rather than \$ so the literal dollar is a bracket expression and the
# linter does not read these as unexpanded shell variables (SC2016). # linter does not read these as unexpanded shell variables (SC2016). The
# same goes for the braces of Inno Setup's {app} prefix.
installer_paths="$("$seven_zip" l -slt "$package" | tr -d '\r' | installer_paths="$("$seven_zip" l -slt "$package" | tr -d '\r' |
sed -n 's/^Path = //p' | sed -n 's/^Path = //p' |
sed -e 's|\\|/|g' -e 's|^[$]INSTDIR/||' -e 's|^[$]OUTDIR/||' -e 's|^[$]PLUGINSDIR/||' -e 's|^\./||' -e 's|^/||')" sed -e 's|\\|/|g' -e 's|^[$]INSTDIR/||' -e 's|^[$]OUTDIR/||' -e 's|^[$]PLUGINSDIR/||' -e 's|^[{]app[}]/||' -e 's|^\./||' -e 's|^/||')"
manifest="$(tr -d '\r' <required-runtime.txt)" manifest="$(tr -d '\r' <required-runtime.txt)"
missing="" missing=""
checked=0 checked=0

View file

@ -327,6 +327,22 @@ if(UNIX)
endif() endif()
endif() endif()
elseif(WIN32) elseif(WIN32)
# Which tool writes the installer. NSIS is the incumbent and stays the default;
# InnoSetup selects CPack's own Inno Setup generator (see cmake/InnoSetup.cmake). Both
# consume the same install() rules, so this is a packaging choice, never a build change,
# and the two installers can be built from one tree and compared on a real upgrade.
set(COCKATRICE_WIN_INSTALLER
"NSIS"
CACHE STRING "Windows installer generator: NSIS (incumbent) or InnoSetup"
)
set_property(CACHE COCKATRICE_WIN_INSTALLER PROPERTY STRINGS NSIS InnoSetup)
if(NOT COCKATRICE_WIN_INSTALLER MATCHES "^(NSIS|InnoSetup)$")
message(FATAL_ERROR "COCKATRICE_WIN_INSTALLER must be NSIS or InnoSetup, not '${COCKATRICE_WIN_INSTALLER}'")
endif()
if(COCKATRICE_WIN_INSTALLER STREQUAL "InnoSetup")
include(${COCKATRICE_CMAKE_PATH}/InnoSetup.cmake)
else()
set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR})
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TRICE_IS_64_BIT 1) set(TRICE_IS_64_BIT 1)
@ -336,6 +352,7 @@ elseif(WIN32)
# Configure file with custom definitions for NSIS. # Configure file with custom definitions for NSIS.
configure_file("${COCKATRICE_CMAKE_PATH}/NSIS.definitions.nsh.in" "${PROJECT_BINARY_DIR}/NSIS.definitions.nsh") configure_file("${COCKATRICE_CMAKE_PATH}/NSIS.definitions.nsh.in" "${PROJECT_BINARY_DIR}/NSIS.definitions.nsh")
endif()
# Installer-log sender for the AbortInstall Sentry hook (values parsed out of COCKATRICE_SENTRY_DSN in # Installer-log sender for the AbortInstall Sentry hook (values parsed out of COCKATRICE_SENTRY_DSN in
# cmake/CrashReporting.cmake). Generated only when a DSN was parsed: cmake/NSIS.template.in embeds it under # cmake/CrashReporting.cmake). Generated only when a DSN was parsed: cmake/NSIS.template.in embeds it under
@ -379,7 +396,9 @@ elseif(WIN32)
# is available to CMake, requiring the vcpkg half would mean guessing names # is available to CMake, requiring the vcpkg half would mean guessing names
# again, which is what produced this bug report in the first place. So assert # again, which is what produced this bug report in the first place. So assert
# what is derived from the build's own link lists and leave the rest to the # what is derived from the build's own link lists and leave the rest to the
# purge in cmake/NSIS.template.in, which removes every DLL regardless of name. # installer's own delete: the purge in cmake/NSIS.template.in and the
# install-delete section in cmake/InnoSetup.install.iss both remove every DLL
# regardless of name.
set(_required_runtime "") set(_required_runtime "")
foreach(_qt_module IN LISTS COCKATRICE_QT_MODULES SERVATRICE_QT_MODULES ORACLE_QT_MODULES) foreach(_qt_module IN LISTS COCKATRICE_QT_MODULES SERVATRICE_QT_MODULES ORACLE_QT_MODULES)
get_target_property(_qt_module_type ${_qt_module} TYPE) get_target_property(_qt_module_type ${_qt_module} TYPE)
@ -395,7 +414,7 @@ elseif(WIN32)
string(REPLACE ";" "\n" _required_runtime "${_required_runtime}") string(REPLACE ";" "\n" _required_runtime "${_required_runtime}")
file(WRITE "${PROJECT_BINARY_DIR}/required-runtime.txt" "${_required_runtime}\n") file(WRITE "${PROJECT_BINARY_DIR}/required-runtime.txt" "${_required_runtime}\n")
# include vcredist into the package; NSIS will take care of running it # include vcredist into the package; both installers run it after the payload
if(VCREDISTRUNTIME_FOUND) if(VCREDISTRUNTIME_FOUND)
install(FILES "${VCREDISTRUNTIME_FILE}" DESTINATION ./) install(FILES "${VCREDISTRUNTIME_FILE}" DESTINATION ./)
endif() endif()

92
cmake/InnoSetup.cmake Normal file
View file

@ -0,0 +1,92 @@
# 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.
#
# 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
# what the generator has no opinion about: upgrade identity, closure behaviour for a
# running application, the stale-runtime [InstallDelete], and the migration off the NSIS
# installation (both script fragments below).
# The generator itself arrived in 3.27; cmake_minimum_required() here would reset the
# policies the top level already selected, so it is refused at the include site instead.
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.
if(NOT "InnoSetup" IN_LIST CPACK_GENERATOR)
set(CPACK_GENERATOR InnoSetup ${CPACK_GENERATOR})
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPACK_INNOSETUP_ARCHITECTURE x64)
else()
set(CPACK_INNOSETUP_ARCHITECTURE x86)
endif()
# Shortcuts and the finish-page run entry come from the executables CPack already knows.
# Only the client is offered: oracle.exe and servatrice.exe are tools, and the NSIS
# installer never created shortcuts for them either.
set(CPACK_PACKAGE_EXECUTABLES "cockatrice" "Cockatrice")
set(CPACK_INNOSETUP_RUN_EXECUTABLES "cockatrice")
set(CPACK_INNOSETUP_USE_MODERN_WIZARD ON)
set(CPACK_INNOSETUP_PROGRAM_MENU_FOLDER "Cockatrice")
set(CPACK_INNOSETUP_ICON_FILE "${PROJECT_SOURCE_DIR}/cockatrice/resources/appicon.ico")
set(CPACK_INNOSETUP_IGNORE_README_PAGE ON)
# The uninstall entry is the only place a user sees the version they have after an update
# that replaced the folder, so keep it and give it the icon.
set(CPACK_INNOSETUP_CREATE_UNINSTALL_LINK ON)
# Upgrade identity. Never change this value: it is what makes a new build an upgrade of the
# previous one (same uninstall entry, same "previous app path", same tasks) instead of a
# second, parallel installation. No braces: a literal { in an .iss script opens a constant,
# and a GUID here buys nothing that this string does not already do.
set(CPACK_INNOSETUP_SETUP_AppId "Cockatrice-6F1C5B2A-9D84-4E37-B0A5-2C7E9A31D4F8")
set(CPACK_INNOSETUP_SETUP_AppName "Cockatrice")
set(CPACK_INNOSETUP_SETUP_DefaultGroupName "Cockatrice")
# An NSIS install registers nothing under Inno's own keys, so the default directory is
# resolved from the legacy registration instead of guessed. See GetDefaultInstallDir in
# cmake/InnoSetup.code.iss.
set(CPACK_INNOSETUP_SETUP_DefaultDirName "{code:GetDefaultInstallDir}")
set(CPACK_INNOSETUP_SETUP_Compression "lzma2/max")
set(CPACK_INNOSETUP_SETUP_SolidCompression ON)
# Replaces the CockLog/CockLogListing machinery: every run writes a log to %TEMP% without
# any script support, which is what a failed upgrade on a user's machine needs to be
# diagnosable after the fact.
set(CPACK_INNOSETUP_SETUP_SetupLogging ON)
set(CPACK_INNOSETUP_SETUP_PrivilegesRequired "admin")
# Users without administrator rights get a working installation instead of a dead end;
# /CURRENTUSER covers the same choice when driven by a package manager or the updater.
set(CPACK_INNOSETUP_SETUP_PrivilegesRequiredOverridesAllowed "dialog commandline")
# Restart Manager, not a PowerShell process scan. Setup detects the applications holding
# the files it is about to replace, closes them, and starts them again afterwards. This is
# the whole of what WaitForAppToClose/GuardAppsNotRunning/ForceCloseApps approximated in
# the NSIS template, including the uninstaller copies that had to repeat it.
set(CPACK_INNOSETUP_SETUP_CloseApplications ON)
set(CPACK_INNOSETUP_SETUP_RestartApplications ON)
# The payload is built for one architecture only; refuse to install it on a system that
# cannot run it. x64 (not x64compatible) keeps this valid on every Inno Setup 6.x.
if(CPACK_INNOSETUP_ARCHITECTURE STREQUAL "x64")
set(CPACK_INNOSETUP_SETUP_ArchitecturesAllowed "x64")
set(CPACK_INNOSETUP_SETUP_ArchitecturesInstallIn64BitMode "x64")
endif()
set(CPACK_INNOSETUP_SETUP_UninstallDisplayIcon "{app}\\cockatrice.exe")
# Sections the generator does not emit (the stale-runtime deletes), and the behaviour it
# cannot express (legacy migration, portable marker, C++ runtime bootstrap).
set(CPACK_INNOSETUP_EXTRA_SCRIPTS "${COCKATRICE_CMAKE_PATH}/InnoSetup.install.iss")
set(CPACK_INNOSETUP_CODE_FILES "${COCKATRICE_CMAKE_PATH}/InnoSetup.code.iss")
message(STATUS "Windows installer: Inno Setup (CPack InnoSetup generator, ${CPACK_INNOSETUP_ARCHITECTURE})")

177
cmake/InnoSetup.code.iss Normal file
View file

@ -0,0 +1,177 @@
// Behaviour for the Windows installer written by CPack's Inno Setup generator.
//
// Included through CPACK_INNOSETUP_CODE_FILES, which places this file inside the generated
// script's code section. Everything here is something the generator cannot express as
// data: the migration off the NSIS installation, the portable marker, and the C++ runtime
// bootstrap. Comments use Pascal braces, so the install-directory constant is spelled out
// as ExpandConstant rather than written inside prose.
const
// Written by every NSIS build up to and including 3.1.x: HKLM in the 64-bit view for a
// 64-bit installer, and in the 32-bit view by the older 32-bit ones.
LegacyUninstallKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Cockatrice';
var
PortablePage: TCustomPage;
PortableCheck: TNewCheckBox;
// 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.
function HasSwitch(const Name: String): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Name) = 0 then
begin
Result := True;
Exit;
end;
end;
// The install directory recorded by the NSIS installer, or an empty string when this
// machine has no such installation. Read-only access to HKLM, so it works unelevated.
function ReadLegacyInstallDir(): String;
var
Value: String;
begin
Result := '';
if RegQueryStringValue(HKLM64, LegacyUninstallKey, 'InstallLocation', Value) then
Result := Value
else if RegQueryStringValue(HKLM32, LegacyUninstallKey, 'InstallLocation', Value) then
Result := Value;
end;
// Scripted constant behind the DefaultDirName directive. An NSIS installation keeps no
// Inno-style "previous app path", so without this an upgrade of a user who picked a custom
// folder in 3.1.x would land in the default folder and leave the old copy behind.
function GetDefaultInstallDir(Param: String): String;
var
Legacy: String;
begin
Legacy := ReadLegacyInstallDir();
if (Legacy <> '') and DirExists(Legacy) then
begin
Result := Legacy;
Log('Default install directory follows the NSIS installation: ' + Result);
end
else
Result := ExpandConstant('{autopf}\Cockatrice');
end;
procedure InitializeWizard();
begin
PortablePage := CreateCustomPage(wpSelectDir, 'Installation mode',
'Cockatrice keeps settings, decks and downloaded pictures in your user profile by default. '
+ 'Portable mode keeps them in the install folder instead.');
PortableCheck := TNewCheckBox.Create(PortablePage);
PortableCheck.Parent := PortablePage.Surface;
PortableCheck.Left := 0;
PortableCheck.Top := 0;
PortableCheck.Width := PortablePage.SurfaceWidth;
PortableCheck.Height := ScaleY(32);
PortableCheck.WordWrap := True;
PortableCheck.Caption := 'Portable: keep settings and decks in the install folder';
PortableCheck.Checked := HasSwitch('/PORTABLE');
end;
function PortableRequested(): Boolean;
begin
Result := (Assigned(PortableCheck) and PortableCheck.Checked) or HasSwitch('/PORTABLE');
end;
// The client decides portable mode by the presence of this file next to the executable
// (cache_settings.cpp and logger.cpp), not by its contents.
procedure WritePortableMarker();
var
Lines: TArrayOfString;
begin
if not PortableRequested() then
Exit;
SetArrayLength(Lines, 1);
Lines[0] := 'Portable install: settings, decks and pictures live beside the executable.';
if not SaveStringsToFile(ExpandConstant('{app}\portable.dat'), Lines, False) then
MsgBox('Could not write portable.dat into the install folder. Portable mode will not be'
+ ' active until it exists.', mbError, MB_OK);
end;
// Runs the Visual C++ redistributable the payload carries, when it carries one. The file
// name differs between the VS 2017 and VS 2022 layouts, so it is matched rather than named.
// A failure is logged and ignored: the redistributable is usually already present, and the
// application is what reports a real problem.
procedure InstallVCRedist();
var
FindRec: TFindRec;
ResultCode: Integer;
Redist: String;
begin
if not FindFirst(ExpandConstant('{app}\vc*redist*.exe'), FindRec) then
Exit;
try
repeat
if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
Redist := ExpandConstant('{app}\') + FindRec.Name;
Log('Installing the C++ runtime: ' + Redist);
if Exec(Redist, '/install /quiet /norestart', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
Log('C++ runtime installer exited with ' + IntToStr(ResultCode));
DeleteFile(Redist);
end
else
Log('Could not start the C++ runtime installer: ' + Redist);
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
// Removes the Add/Remove Programs entry the NSIS installer left behind. Without this the
// user sees two entries for Cockatrice and can still run the old uninstaller, whose
// blanket removal of the install directory is the data loss the 3.1.x backup pair was
// written to survive. Deleting the registration is what makes that uninstaller
// unreachable; the binary next to it is removed earlier by the install-delete section.
procedure RemoveLegacyNSISRegistration();
var
Uninstaller: String;
begin
if not (RegQueryStringValue(HKLM64, LegacyUninstallKey, 'UninstallString', Uninstaller)
or RegQueryStringValue(HKLM32, LegacyUninstallKey, 'UninstallString', Uninstaller)) then
Exit;
RegDeleteKeyIncludingSubkeys(HKLM64, LegacyUninstallKey);
RegDeleteKeyIncludingSubkeys(HKLM32, LegacyUninstallKey);
Log('Removed the legacy NSIS uninstall registration: ' + Uninstaller);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
InstallVCRedist();
WritePortableMarker();
RemoveLegacyNSISRegistration();
end;
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.
function InitializeSetup(): Boolean;
var
I: Integer;
Param: String;
begin
Log('Setup command line: ' + GetCmdTail());
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);
end;
Result := True;
end;

View file

@ -0,0 +1,23 @@
; 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.
[InstallDelete]
; The previous version's runtime, whatever it was called. Replacing a DLL in place is not
; enough: a module the payload no longer carries (Qt6Multimedia.dll while it was still
; shared, Qt6QuickWidgets.dll) would survive the install and then be loaded next to the new
; executable, which is the "procedure entry point ... could not be located" failure after
; an update. Removing every DLL and letting the payload put its own back is what the NSIS
; RetryDllPurge did with 250 lines of retry and diagnostics; with CloseApplications on,
; Restart Manager has already released the handles, so one pass is enough.
Type: files; Name: "{app}\*.dll"
; Plugins are loaded by name from this directory, so a stale one is just as fatal and is
; not covered by the payload's own file list.
Type: filesandordirs; Name: "{app}\Plugins"
; The NSIS uninstaller. Its Add/Remove Programs registration is deleted after a successful
; install (RemoveLegacyNSISRegistration in InnoSetup.code.iss); the binary itself has no
; business staying next to the new one.
Type: files; Name: "{app}\Uninstall.exe"