Skip to content

Commit 6cf207a

Browse files
committed
packaging/windows: address review feedback — upgrade flow, opt-in user-data removal
Two follow-ups from PR review: * Add CheckPriorInstall — silently runs the old install's Uninstall.exe before staging the new portable tree, so removed files / orphaned DLLs from the older version don't accumulate. Reads prior location from HKLM\Software\aMule\InstallLocation (recorded during the original install). Silent mode respects section defaults: un.SecRemoveUserData is /o (unchecked), so an upgrade preserves %APPDATA%\aMule. * Add un.SecRemoveUserData — opt-in (Section /o, unchecked by default) uninstaller section that nukes %APPDATA%\aMule on explicit request. Default-off matches the common Windows convention of "remove the app, keep my data." MUI_UNPAGE_COMPONENTS shows the checkbox alongside the (RO) main uninstall section. Refs amule-project#740 (comment).
1 parent d978a13 commit 6cf207a

1 file changed

Lines changed: 63 additions & 1 deletion

File tree

packaging/windows/installer.nsi

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Var StartMenuFolder
9191
!insertmacro MUI_PAGE_FINISH
9292

9393
!insertmacro MUI_UNPAGE_CONFIRM
94+
!insertmacro MUI_UNPAGE_COMPONENTS
9495
!insertmacro MUI_UNPAGE_INSTFILES
9596
!insertmacro MUI_UNPAGE_FINISH
9697

@@ -128,6 +129,34 @@ Function CheckRunningInstance
128129
${EndIf}
129130
FunctionEnd
130131

132+
; If a previous install exists at a recorded location, uninstall it
133+
; silently first so stale DLLs / removed files from the older version
134+
; don't linger. NSIS's File /r overwrites but never deletes; without
135+
; this an upgrade leaves orphaned binaries behind.
136+
Function CheckPriorInstall
137+
ReadRegStr $0 HKLM "Software\aMule" "InstallLocation"
138+
${If} $0 != ""
139+
${AndIf} ${FileExists} "$0\Uninstall.exe"
140+
DetailPrint "Removing previous aMule installation at $0..."
141+
; /S = silent; _?=$0 keeps the uninstaller from copying itself to
142+
; %TEMP% and detaching, so ExecWait actually waits and the user
143+
; data prompt is suppressed (silent runs default to the section's
144+
; default state — un.SecRemoveUserData is /o, i.e. unchecked).
145+
ExecWait '"$0\Uninstall.exe" /S _?=$0' $1
146+
${If} $1 != 0
147+
MessageBox MB_OK|MB_ICONSTOP \
148+
"Could not remove the previous aMule installation at $0.$\r$\n\
149+
Please close any running aMule processes and try again, or \
150+
uninstall the previous version manually first."
151+
Abort
152+
${EndIf}
153+
; The uninstaller can't delete its own .exe while running; clean
154+
; up the stub and its parent dir if it's now empty.
155+
Delete "$0\Uninstall.exe"
156+
RMDir "$0"
157+
${EndIf}
158+
FunctionEnd
159+
131160
Function .onInit
132161
; $PROGRAMFILES64 must resolve correctly for both x64 and ARM64
133162
; payloads; the installer always lays out under the 64-bit prefix.
@@ -152,6 +181,7 @@ FunctionEnd
152181
Section "aMule (required)" SecCore
153182
SectionIn RO
154183

184+
Call CheckPriorInstall
155185
Call CheckRunningInstance
156186

157187
SetOutPath "$INSTDIR"
@@ -230,7 +260,13 @@ SectionEnd
230260
; Uninstaller
231261
; --------------------------------------------------------------------
232262

233-
Section "Uninstall"
263+
; The first uninstaller section must be named "Uninstall" — NSIS uses
264+
; that as the entry point. `un.SecUninstall` ID lets the Components
265+
; page reference it for its description; SectionIn RO grays it out so
266+
; it can't be unchecked.
267+
Section "Uninstall" un.SecUninstall
268+
SectionIn RO
269+
234270
; Refuse to uninstall if anything is still running.
235271
${If} ${FileExists} "$INSTDIR\bin\amule.exe"
236272
ClearErrors
@@ -288,6 +324,32 @@ Section "Uninstall"
288324
DeleteRegKey HKLM "Software\aMule"
289325
SectionEnd
290326

327+
; Opt-in: nuke %APPDATA%\aMule. Default off so a normal uninstall is
328+
; "remove the app, keep my data" (the common Windows convention). The
329+
; `un.` ID prefix associates this with the uninstaller block.
330+
;
331+
; SetShellVarContext current here resolves $APPDATA to the elevated
332+
; user's profile, NOT All Users (the latter is wrong for per-user
333+
; config). On a single-admin machine the elevated context IS the user
334+
; who installed; multi-user machines need each user to run the
335+
; uninstaller themselves to clean their own profile (unavoidable, no
336+
; way for an elevated process to enumerate every desktop session).
337+
Section /o "Remove user data (config, ED2K servers, Kad nodes, partfiles)" un.SecRemoveUserData
338+
SetShellVarContext current
339+
${If} ${FileExists} "$APPDATA\aMule"
340+
DetailPrint "Removing user data at $APPDATA\aMule..."
341+
RMDir /r "$APPDATA\aMule"
342+
${EndIf}
343+
SetShellVarContext all
344+
SectionEnd
345+
346+
!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
347+
!insertmacro MUI_DESCRIPTION_TEXT ${un.SecUninstall} \
348+
"Remove aMule application files, Start Menu / desktop shortcuts, autostart Run-key entry, and Add/Remove Programs entry (required)."
349+
!insertmacro MUI_DESCRIPTION_TEXT ${un.SecRemoveUserData} \
350+
"Permanently delete %APPDATA%\aMule for the current user (aMule.conf, ED2K server list, Kad nodes, partfiles, IP filters, friends list). Leave unchecked to keep your settings."
351+
!insertmacro MUI_UNFUNCTION_DESCRIPTION_END
352+
291353
; Tiny substring helper — returns the match position on the stack or
292354
; empty string when needle isn't present. Used by the autostart-cleanup
293355
; guard to confirm the HKCU Run value still points inside $INSTDIR.

0 commit comments

Comments
 (0)