2424
2525!define AUTOSTART_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Run"
2626
27+ !define NETBIRD_DATA_DIR "$COMMONPROGRAMDATA\Netbird"
28+
2729Unicode True
2830
2931######################################################################
@@ -49,6 +51,10 @@ ShowInstDetails Show
4951
5052######################################################################
5153
54+ !include "MUI2.nsh"
55+ !include LogicLib.nsh
56+ !include "nsDialogs.nsh"
57+
5258!define MUI_ICON "${ICON}"
5359!define MUI_UNICON "${ICON}"
5460!define MUI_WELCOMEFINISHPAGE_BITMAP "${BANNER}"
@@ -58,9 +64,6 @@ ShowInstDetails Show
5864!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
5965######################################################################
6066
61- !include "MUI2.nsh"
62- !include LogicLib.nsh
63-
6467!define MUI_ABORTWARNING
6568!define MUI_UNABORTWARNING
6669
@@ -70,13 +73,16 @@ ShowInstDetails Show
7073
7174!insertmacro MUI_PAGE_DIRECTORY
7275
73- ; Custom page for autostart checkbox
7476Page custom AutostartPage AutostartPageLeave
7577
7678!insertmacro MUI_PAGE_INSTFILES
7779
7880!insertmacro MUI_PAGE_FINISH
7981
82+ !insertmacro MUI_UNPAGE_WELCOME
83+
84+ UninstPage custom un.DeleteDataPage un.DeleteDataPageLeave
85+
8086!insertmacro MUI_UNPAGE_CONFIRM
8187
8288!insertmacro MUI_UNPAGE_INSTFILES
@@ -89,6 +95,10 @@ Page custom AutostartPage AutostartPageLeave
8995Var AutostartCheckbox
9096Var AutostartEnabled
9197
98+ ; Variables for uninstall data deletion option
99+ Var DeleteDataCheckbox
100+ Var DeleteDataEnabled
101+
92102######################################################################
93103
94104; Function to create the autostart options page
@@ -104,8 +114,8 @@ Function AutostartPage
104114
105115 ${NSD_CreateCheckbox} 0 20u 100% 10u "Start ${APP_NAME} UI automatically when Windows starts"
106116 Pop $AutostartCheckbox
107- ${NSD_Check} $AutostartCheckbox ; Default to checked
108- StrCpy $AutostartEnabled "1" ; Default to enabled
117+ ${NSD_Check} $AutostartCheckbox
118+ StrCpy $AutostartEnabled "1"
109119
110120 nsDialogs::Show
111121FunctionEnd
@@ -115,6 +125,30 @@ Function AutostartPageLeave
115125 ${NSD_GetState} $AutostartCheckbox $AutostartEnabled
116126FunctionEnd
117127
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+
118152Function GetAppFromCommand
119153Exch $1
120154Push $2
@@ -176,10 +210,10 @@ ${EndIf}
176210FunctionEnd
177211######################################################################
178212Section -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\\"
183217SectionEnd
184218######################################################################
185219
@@ -225,31 +259,58 @@ SectionEnd
225259Section Uninstall
226260${INSTALL_TYPE}
227261
262+ DetailPrint "Stopping Netbird service..."
228263ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service stop'
264+ DetailPrint "Uninstalling Netbird service..."
229265ExecWait '"$INSTDIR\${MAIN_APP_EXE}" service uninstall'
230266
231- # kill ui client
267+ DetailPrint "Terminating Netbird UI process..."
232268ExecWait `taskkill /im ${UI_APP_EXE}.exe /f`
233269
234270; Remove autostart registry entry
271+ DetailPrint "Removing autostart registry entry if exists..."
235272DeleteRegValue HKCU "${AUTOSTART_REG_KEY}" "${APP_NAME}"
236273
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+
237287# wait the service uninstall take unblock the executable
288+ DetailPrint "Waiting for service handle to be released..."
238289Sleep 3000
290+
291+ DetailPrint "Deleting application files..."
239292Delete "$INSTDIR\${UI_APP_EXE}"
240293Delete "$INSTDIR\${MAIN_APP_EXE}"
241294Delete "$INSTDIR\wintun.dll"
242295Delete "$INSTDIR\opengl32.dll"
296+ DetailPrint "Removing application directory..."
243297RmDir /r "$INSTDIR"
244298
299+ DetailPrint "Removing shortcuts..."
245300SetShellVarContext all
246301Delete "$DESKTOP\${APP_NAME}.lnk"
247302Delete "$SMPROGRAMS\${APP_NAME}.lnk"
248303
304+ DetailPrint "Removing registry keys..."
249305DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
250306DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
307+ DeleteRegKey ${REG_ROOT} "${UI_REG_APP_PATH}"
308+
309+ DetailPrint "Removing application directory from PATH..."
251310EnVar::SetHKLM
252311EnVar::DeleteValue "path" "$INSTDIR"
312+
313+ DetailPrint "Uninstallation finished."
253314SectionEnd
254315
255316
0 commit comments