@@ -8,6 +8,7 @@ Unicode true
88!include FileFunc.nsh
99!include LogicLib.nsh
1010!addplugindir " NSIS\Plugins\x86-unicode"
11+ !addplugindir " NSIS\Plugin"
1112!define MUI_ICON " ..\..\resources\images\icon.ico"
1213!define MUI_UNICON " ..\..\resources\images\icon.ico"
1314
@@ -22,9 +23,10 @@ Unicode true
2223!define outfile_prefix " swift-console"
2324!define installer_dir " py39-dist"
2425!define company_name " Swift Navigation"
25- !define old_uninstaller " $PROGRAMFILES\${company_name}\${app_name}\Uninstall.exe"
2626!define old_shortcut " ${app_name} (Old).lnk"
2727
28+ var Checkbox
29+
2830!define vc_redist_url " https://aka.ms/vs/17/release/vc_redist.x64.exe"
2931
3032ManifestDPIAware true
@@ -82,6 +84,7 @@ FunctionEnd
8284
8385 !define UninstallMsg " Warning! By clicking $\" Next$\" , this installer will uninstall any previous versions of the Swift Console.$\n$\n \
8486If this is not desired, please exit the installer now."
87+ !define OldUninstallMsg " Also uninstall the previous generation of Swift Console (versions lower than v4.0.0)"
8588
8689 Function uninstallOldVersionsPage
8790 !insertmacro MUI_HEADER_TEXT " Uninstall Previous Version" " This installer will uninstall any previous versions."
@@ -95,10 +98,25 @@ If this is not desired, please exit the installer now."
9598 ${NSD_CreateLabel} 0 0 100 % 40u " ${UninstallMsg}"
9699 Pop $0
97100
101+ ${NSD_CreateCheckbox} 10u 110u 100 % 10u " ${OldUninstallMsg}"
102+ Pop $Checkbox
103+ ${NSD_Check} $Checkbox
104+
98105 nsDialogs::Show
99106 FunctionEnd
100107
101108 Function uninstallOldVersionsPageLeave
109+ ${NSD_GetState} $Checkbox $0
110+ ${If} $0 <> ${BST_UNCHECKED}
111+ SetShellVarContext current
112+ RMDir /r " $PROGRAMFILES\Swift Navigation\Swift Console\*.*"
113+ Delete " $DESKTOP\Swift Console.lnk"
114+ Delete " $DESKTOP\${old_shortcut}"
115+ Delete " $SMPROGRAMS\Swift Navigation\Swift Console.lnk"
116+ Delete " $SMPROGRAMS\Swift Navigation\Uninstall.lnk"
117+ RMDir " $SMPROGRAMS\Swift Navigation"
118+ SetShellVarContext all
119+ ${EndIf}
102120 Call Uninstall
103121 FunctionEnd
104122
@@ -160,6 +178,7 @@ If this is not desired, please exit the installer now."
160178
161179Function MoveOldShtct
162180 SetShellVarContext current
181+ IfFileExists " $DESKTOP\${old_shortcut}" +2 0
163182 Rename " $DESKTOP\${app_name}.lnk" " $DESKTOP\${old_shortcut}"
164183 SetShellVarContext all
165184FunctionEnd
@@ -230,9 +249,23 @@ Function LaunchAsNonAdmin
230249 Exec ' "$WINDIR\explorer.exe" "$InstDir\${app_executable}"'
231250FunctionEnd
232251
252+ !macro CloseAppIfRunning Prefix
253+ Function ${Prefix} CloseAppIfRunning
254+ nsProcess::_FindProcess " ${app_executable}"
255+ Pop $R0
256+ ${If} $R0 == 0
257+ nsProcess::_CloseProcess " ${app_executable}"
258+ Sleep 2000
259+ ${EndIf}
260+ nsProcess::_Unload
261+ FunctionEnd
262+ !macroend
263+ !insertmacro CloseAppIfRunning " "
264+ !insertmacro CloseAppIfRunning " un."
265+
233266!macro Uninstall Prefix
234267Function ${Prefix} Uninstall
235- Exec ' "${old_uninstaller}" "/AllUsers /S" '
268+ Call ${Prefix} CloseAppIfRunning
236269 RMDir /r " $InstDir"
237270 Delete " $DESKTOP\${app_name}.lnk"
238271 Delete " $SMPROGRAMS\${app_name}.lnk"
0 commit comments