Windows MSI: notify Explorer of the PDF association so PdfCraft shows under Open with (#1080)

The MSI already registers PdfCraft.Document in .pdf\OpenWithProgids, Capabilities and
RegisteredApplications, but Windows Installer never sends SHCNE_ASSOCCHANGED, so Explorer's
cached Open with list can miss PdfCraft until sign-out. Send it after install and uninstall
from an immediate, ignore-result custom action; test-msi.ps1 checks the action and its order.
This commit is contained in:
Mara Johnson committed 2026-10-11 23:23:37 -04:00
1 parent 84a75eae1b
commit d812cf8a5c
2 files changed
+22

No files matched your search

+13
View File
@@ -53,11 +53,24 @@
</StandardDirectory>
<StandardDirectory Id="ProgramMenuFolder" />
<StandardDirectory Id="DesktopFolder" />
<StandardDirectory Id="SystemFolder" />
<Feature Id="Main" Title="PdfCraft" Level="1">
<ComponentGroupRef Id="PdfcraftFiles" />
<ComponentGroupRef Id="PdfcraftModels" />
</Feature>
<!-- #1080: Windows Installer writes the PDF handler keys but never tells the shell, so Explorer's
cached "Open with" list misses PdfCraft until sign-out. Windows requires
SHChangeNotify(SHCNE_ASSOCCHANGED) after association changes; send it after install and
uninstall. Immediate (user's session, where Explorer runs); failure must not fail setup.
SystemFolder's PowerShell is always 32-bit (SysWOW64 on 64-bit Windows), so int fits the
pointer arguments. [\[] and [\]] escape [ and ]; Target is capped at 255 characters. -->
<CustomAction Id="NotifyAssociationsChanged" Directory="SystemFolder" Execute="immediate" Return="ignore"
ExeCommand="&quot;[SystemFolder]WindowsPowerShell\v1.0\powershell.exe&quot; -NoP -W Hidden -C (Add-Type -PassThru -Name N -MemberDefinition '[\[]DllImport(\&quot;shell32\&quot;)[\]]public static extern void SHChangeNotify(int e,int f,int a,int b);')::SHChangeNotify(0x8000000,0,0,0)" />
<InstallExecuteSequence>
<Custom Action="NotifyAssociationsChanged" After="InstallFinalize" />
</InstallExecuteSequence>
</Package>
<Fragment>
+9
View File
@@ -148,6 +148,15 @@ if ($pdfCheckbox[2] -notmatch 'Edit with PdfCraft') { throw "Welcome PDF context
$pdfChecked = Read-Row 'SELECT `Value` FROM `CheckBox` WHERE `Property` = ''INSTALLPDFCONTEXTMENU''' 1
Assert-Equal $pdfChecked[0] '1' 'Welcome PDF context-menu value'
Assert-NoRow 'SELECT `Registry` FROM `Registry` WHERE `Key` = ''Software\Classes\.pdf'' AND `Name` IS NULL' '.pdf default app'
# #1080: Explorer is told the associations changed (SHCNE_ASSOCCHANGED) after install/uninstall,
# without ever failing setup. 34 = exe in a directory; 64 = ignore its exit code.
$notify = Read-Row 'SELECT `Type`, `Source`, `Target` FROM `CustomAction` WHERE `Action` = ''NotifyAssociationsChanged''' 3
Assert-Equal $notify[0] '98' 'Association notify action type'
Assert-Equal $notify[1] 'SystemFolder' 'Association notify directory'
if ($notify[2] -notmatch 'SHChangeNotify\(0x8000000,0,0,0\)' -or $notify[2].Length -gt 255) { throw "Association notify command: '$($notify[2])'" }
$after = Read-Row 'SELECT `Sequence` FROM `InstallExecuteSequence` WHERE `Action` = ''NotifyAssociationsChanged''' 1
$finalize = Read-Row 'SELECT `Sequence` FROM `InstallExecuteSequence` WHERE `Action` = ''InstallFinalize''' 1
if ([int] $after[0] -le [int] $finalize[0]) { throw 'Association notify must run after InstallFinalize' }
# Negative sequences are Windows Installer's success/user-exit/failure paths. Only full UI
# shows these dialogs: an unattended /qn or /qb install must never wait for a Finish click.