24
24
25
25
!define AUTOSTART_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Run"
26
26
27
+ !define NETBIRD_DATA_DIR "$COMMONPROGRAMDATA\Netbird"
28
+
27
29
Unicode True
28
30
29
31
######################################################################
@@ -49,6 +51,10 @@ ShowInstDetails Show
49
51
50
52
######################################################################
51
53
54
+ !include "MUI2.nsh"
55
+ !include LogicLib.nsh
56
+ !include "nsDialogs.nsh"
57
+
52
58
!define MUI_ICON "${ICON}"
53
59
!define MUI_UNICON "${ICON}"
54
60
!define MUI_WELCOMEFINISHPAGE_BITMAP "${BANNER}"
@@ -58,9 +64,6 @@ ShowInstDetails Show
58
64
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
59
65
######################################################################
60
66
61
- !include "MUI2.nsh"
62
- !include LogicLib.nsh
63
-
64
67
!define MUI_ABORTWARNING
65
68
!define MUI_UNABORTWARNING
66
69
@@ -70,13 +73,16 @@ ShowInstDetails Show
70
73
71
74
!insertmacro MUI_PAGE_DIRECTORY
72
75
73
- ; Custom page for autostart checkbox
74
76
Page custom AutostartPage AutostartPageLeave
75
77
76
78
!insertmacro MUI_PAGE_INSTFILES
77
79
78
80
!insertmacro MUI_PAGE_FINISH
79
81
82
+ !insertmacro MUI_UNPAGE_WELCOME
83
+
84
+ UninstPage custom un.DeleteDataPage un.DeleteDataPageLeave
85
+
80
86
!insertmacro MUI_UNPAGE_CONFIRM
81
87
82
88
!insertmacro MUI_UNPAGE_INSTFILES
@@ -89,6 +95,10 @@ Page custom AutostartPage AutostartPageLeave
89
95
Var AutostartCheckbox
90
96
Var AutostartEnabled
91
97
98
+ ; Variables for uninstall data deletion option
99
+ Var DeleteDataCheckbox
100
+ Var DeleteDataEnabled
101
+
92
102
######################################################################
93
103
94
104
; Function to create the autostart options page
@@ -104,8 +114,8 @@ Function AutostartPage
104
114
105
115
${NSD_CreateCheckbox} 0 20u 100% 10u "Start ${APP_NAME} UI automatically when Windows starts"
106
116
Pop $AutostartCheckbox
107
- ${NSD_Check} $AutostartCheckbox ; Default to checked
108
- StrCpy $AutostartEnabled "1" ; Default to enabled
117
+ ${NSD_Check} $AutostartCheckbox
118
+ StrCpy $AutostartEnabled "1"
109
119
110
120
nsDialogs::Show
111
121
FunctionEnd
@@ -115,6 +125,30 @@ Function AutostartPageLeave
115
125
${NSD_GetState} $AutostartCheckbox $AutostartEnabled
116
126
FunctionEnd
117
127
128
+ ; Function to create the uninstall data deletion page
129
+ Function un.DeleteDataPage
130
+ !insertmacro MUI_HEADER_TEXT "Uninstall Options" "Choose whether to delete ${APP_NAME} data."
131
+
132
+ nsDialogs::Create 1018
133
+ Pop $0
134
+
135
+ ${If} $0 == error
136
+ Abort
137
+ ${EndIf}
138
+
139
+ ${NSD_CreateCheckbox} 0 20u 100% 10u "Delete all ${APP_NAME} configuration and state data (${NETBIRD_DATA_DIR})"
140
+ Pop $DeleteDataCheckbox
141
+ ${NSD_Uncheck} $DeleteDataCheckbox
142
+ StrCpy $DeleteDataEnabled "0"
143
+
144
+ nsDialogs::Show
145
+ FunctionEnd
146
+
147
+ ; Function to handle leaving the data deletion page
148
+ Function un.DeleteDataPageLeave
149
+ ${NSD_GetState} $DeleteDataCheckbox $DeleteDataEnabled
150
+ FunctionEnd
151
+
118
152
Function GetAppFromCommand
119
153
Exch $1
120
154
Push $2
@@ -176,10 +210,10 @@ ${EndIf}
176
210
FunctionEnd
177
211
######################################################################
178
212
Section -MainProgram
179
- ${INSTALL_TYPE}
180
- # SetOverwrite ifnewer
181
- SetOutPath "$INSTDIR"
182
- File /r "..\\dist\\netbird_windows_amd64\\"
213
+ ${INSTALL_TYPE}
214
+ # SetOverwrite ifnewer
215
+ SetOutPath "$INSTDIR"
216
+ File /r "..\\dist\\netbird_windows_amd64\\"
183
217
SectionEnd
184
218
######################################################################
185
219
@@ -225,31 +259,58 @@ SectionEnd
225
259
Section Uninstall
226
260
${INSTALL_TYPE}
227
261
262
+ DetailPrint "Stopping Netbird service..."
228
263
ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service stop'
264
+ DetailPrint "Uninstalling Netbird service..."
229
265
ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service uninstall'
230
266
231
- # kill ui client
267
+ DetailPrint "Terminating Netbird UI process..."
232
268
ExecWait `taskkill /im ${UI_APP_EXE}.exe /f`
233
269
234
270
; Remove autostart registry entry
271
+ DetailPrint "Removing autostart registry entry if exists..."
235
272
DeleteRegValue HKCU "${AUTOSTART_REG_KEY}" "${APP_NAME}"
236
273
274
+ ; Handle data deletion based on checkbox
275
+ DetailPrint "Checking if user requested data deletion..."
276
+ ${If} $DeleteDataEnabled == "1"
277
+ DetailPrint "User opted to delete Netbird data. Removing ${NETBIRD_DATA_DIR}..."
278
+ ClearErrors
279
+ RMDir /r "${NETBIRD_DATA_DIR}"
280
+ IfErrors 0 +2 ; If no errors, jump over the message
281
+ DetailPrint "Error deleting Netbird data directory. It might be in use or already removed."
282
+ DetailPrint "Netbird data directory removal complete."
283
+ ${Else}
284
+ DetailPrint "User did not opt to delete Netbird data."
285
+ ${EndIf}
286
+
237
287
# wait the service uninstall take unblock the executable
288
+ DetailPrint "Waiting for service handle to be released..."
238
289
Sleep 3000
290
+
291
+ DetailPrint "Deleting application files..."
239
292
Delete "$INSTDIR\${UI_APP_EXE}"
240
293
Delete "$INSTDIR\${MAIN_APP_EXE}"
241
294
Delete "$INSTDIR\wintun.dll"
242
295
Delete "$INSTDIR\opengl32.dll"
296
+ DetailPrint "Removing application directory..."
243
297
RmDir /r "$INSTDIR"
244
298
299
+ DetailPrint "Removing shortcuts..."
245
300
SetShellVarContext all
246
301
Delete "$DESKTOP\${APP_NAME}.lnk"
247
302
Delete "$SMPROGRAMS\${APP_NAME}.lnk"
248
303
304
+ DetailPrint "Removing registry keys..."
249
305
DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
250
306
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
307
+ DeleteRegKey ${REG_ROOT} "${UI_REG_APP_PATH}"
308
+
309
+ DetailPrint "Removing application directory from PATH..."
251
310
EnVar::SetHKLM
252
311
EnVar::DeleteValue "path" "$INSTDIR"
312
+
313
+ DetailPrint "Uninstallation finished."
253
314
SectionEnd
254
315
255
316
0 commit comments