forked from electron-userland/electron-builder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstaller.nsh
245 lines (189 loc) · 4.94 KB
/
uninstaller.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
Function un.checkAppRunning
!insertmacro CHECK_APP_RUNNING
FunctionEnd
Function un.onInit
SetOutPath $INSTDIR
${LogSet} on
!insertmacro check64BitAndSetRegView
${If} ${Silent}
call un.checkAppRunning
${else}
!ifdef ONE_CLICK
MessageBox MB_OKCANCEL "$(areYouSureToUninstall)" IDOK +2
Quit
# one-click installer executes uninstall section in the silent mode, but we must show message dialog if silent mode was not explicitly set by user (using /S flag)
call un.checkAppRunning
SetSilent silent
!endif
${endIf}
!insertmacro initMultiUser
!ifmacrodef customUnInit
!insertmacro customUnInit
!endif
FunctionEnd
Function un.atomicRMDir
Exch $R0
Push $R1
Push $R2
Push $R3
StrCpy $R3 "$INSTDIR$R0\*.*"
FindFirst $R1 $R2 $R3
loop:
StrCmp $R2 "" break
StrCmp $R2 "." continue
StrCmp $R2 ".." continue
IfFileExists "$INSTDIR$R0\$R2\*.*" isDir isNotDir
isDir:
CreateDirectory "$PLUGINSDIR\old-install$R0\$R2"
Push "$R0\$R2"
Call un.atomicRMDir
Pop $R3
${if} $R3 != 0
Goto done
${endIf}
Goto continue
isNotDir:
ClearErrors
Rename "$INSTDIR$R0\$R2" "$PLUGINSDIR\old-install$R0\$R2"
# Ignore errors when renaming ourselves.
StrCmp "$R0\$R2" "${UNINSTALL_FILENAME}" 0 +2
ClearErrors
IfErrors 0 +3
StrCpy $R3 "$INSTDIR$R0\$R2"
Goto done
continue:
FindNext $R1 $R2
Goto loop
break:
StrCpy $R3 0
done:
FindClose $R1
StrCpy $R0 $R3
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
Function un.restoreFiles
Exch $R0
Push $R1
Push $R2
Push $R3
StrCpy $R3 "$PLUGINSDIR\old-install$R0\*.*"
FindFirst $R1 $R2 $R3
loop:
StrCmp $R2 "" break
StrCmp $R2 "." continue
StrCmp $R2 ".." continue
IfFileExists "$INSTDIR$R0\$R2\*.*" isDir isNotDir
isDir:
CreateDirectory "$INSTDIR$R0\$R2"
Push "$R0\$R2"
Call un.restoreFiles
Pop $R3
Goto continue
isNotDir:
Rename $PLUGINSDIR\old-install$R0\$R2" "$INSTDIR$R0\$R2"
continue:
FindNext $R1 $R2
Goto loop
break:
StrCpy $R0 0
FindClose $R1
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
Section "un.install"
# for assisted installer we check it here to show progress
!ifndef ONE_CLICK
${IfNot} ${Silent}
call un.checkAppRunning
${endIf}
!endif
!insertmacro setLinkVars
# delete the installed files
!ifmacrodef customRemoveFiles
!insertmacro customRemoveFiles
!else
${if} ${isUpdated}
CreateDirectory "$PLUGINSDIR\old-install"
Push ""
Call un.atomicRMDir
Pop $R0
${if} $R0 != 0
DetailPrint "File is busy, aborting: $R0"
# Attempt to restore previous directory
Push ""
Call un.restoreFiles
Pop $R0
Abort `Can't rename "$INSTDIR" to "$PLUGINSDIR\old-install".`
${endif}
${endif}
# Remove all files (or remaining shallow directories from the block above)
RMDir /r $INSTDIR
!endif
${ifNot} ${isKeepShortcuts}
WinShell::UninstAppUserModelId "${APP_ID}"
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
WinShell::UninstShortcut "$oldDesktopLink"
Delete "$oldDesktopLink"
!endif
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
WinShell::UninstShortcut "$oldStartMenuLink"
Delete "$oldStartMenuLink"
ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" MenuDirectory
${ifNot} $R1 == ""
RMDir "$SMPROGRAMS\$R1"
${endIf}
!endif
${endIf}
# refresh the desktop
System::Call 'shell32::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
!ifmacrodef unregisterFileAssociations
!insertmacro unregisterFileAssociations
!endif
Var /GLOBAL isDeleteAppData
StrCpy $isDeleteAppData "0"
ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--delete-app-data" $R1
${if} ${Errors}
!ifdef DELETE_APP_DATA_ON_UNINSTALL
${ifNot} ${isUpdated}
StrCpy $isDeleteAppData "1"
${endif}
!endif
${else}
StrCpy $isDeleteAppData "1"
${endIf}
${if} $isDeleteAppData == "1"
# electron always uses per user app data
${if} $installMode == "all"
SetShellVarContext current
${endif}
RMDir /r "$APPDATA\${APP_FILENAME}"
!ifdef APP_PRODUCT_FILENAME
RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
!endif
# electron use package.json name for cache,indexdb etc.
!ifdef APP_PACKAGE_NAME
RMDir /r "$APPDATA\${APP_PACKAGE_NAME}"
!endif
${if} $installMode == "all"
SetShellVarContext all
${endif}
${endif}
DeleteRegKey SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}"
!ifdef UNINSTALL_REGISTRY_KEY_2
DeleteRegKey SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY_2}"
!endif
DeleteRegKey SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}"
!ifmacrodef customUnInstall
!insertmacro customUnInstall
!endif
!ifdef ONE_CLICK
!insertmacro quitSuccess
!endif
SectionEnd