Skip to content

Commit 983b301

Browse files
committed
Add uninstall option
1 parent 08b524f commit 983b301

File tree

1 file changed

+177
-7
lines changed

1 file changed

+177
-7
lines changed

NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi

+177-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ setcompressor /SOLID lzma
3535
!define VC_VERSION "VC143"
3636

3737
; Use Modern UI
38-
!include "MUI.nsh"
38+
!include "MUI2.nsh"
3939
ICON "install-ocs.ico"
4040
; MUI Settings
4141
!define MUI_HEADERIMAGE
@@ -66,8 +66,10 @@ Page custom AskLocalInventory ValidateLocalInventory ""
6666
!define MUI_FINISHPAGE_RUN_TEXT "Start OCS Inventory NG Systray Applet"
6767
!define MUI_FINISHPAGE_RUN "$INSTDIR\OcsSystray.exe"
6868
!insertmacro MUI_PAGE_FINISH
69-
; Confirl before uninstall
69+
70+
UninstPage custom un.AskUninstallOptions un.ValidateUninstallOptions ""
7071
!insertmacro MUI_UNPAGE_INSTFILES
72+
7173
; Language files
7274
!insertmacro MUI_LANGUAGE "English"
7375
!insertmacro MUI_LANGUAGE "French"
@@ -110,7 +112,12 @@ var /GLOBAL OcsNoSplash ; To store if setup must display spash screen (FALSE) or
110112
var /GLOBAL OcsUpgrade ; To store if /UPGRADE option used (TRUE) or not (FALSE)
111113
var /GLOBAL installSatus ; To store installation status
112114
var /GLOBAL OcsLocal ; To store folder where to write local inventory file
113-
115+
; handle uninstall variables
116+
var /GLOBAL hCtl
117+
var /GLOBAL hCtl_uninstalloptions
118+
var /GLOBAL hCtl_clean
119+
var /GLOBAL hCtl_Label1
120+
var /GLOBAL uninstallOption ; To store the uninstall option
114121
#####################################################################
115122
# GetParameters
116123
# input, none
@@ -322,6 +329,121 @@ done:
322329
Exch $R1
323330
FunctionEnd
324331

332+
Function un.GetParameters
333+
Push $R0
334+
Push $R1
335+
Push $R2
336+
Push $R3
337+
338+
StrCpy $R2 1
339+
StrLen $R3 $CMDLINE
340+
341+
;Check for quote or space
342+
StrCpy $R0 $CMDLINE $R2
343+
StrCmp $R0 '"' 0 +3
344+
StrCpy $R1 '"'
345+
Goto loop
346+
StrCpy $R1 " "
347+
348+
loop:
349+
IntOp $R2 $R2 + 1
350+
StrCpy $R0 $CMDLINE 1 $R2
351+
StrCmp $R0 $R1 get
352+
StrCmp $R2 $R3 get
353+
Goto loop
354+
355+
get:
356+
IntOp $R2 $R2 + 1
357+
StrCpy $R0 $CMDLINE 1 $R2
358+
StrCmp $R0 " " get
359+
StrCpy $R0 $CMDLINE "" $R2
360+
361+
Pop $R3
362+
Pop $R2
363+
Pop $R1
364+
Exch $R0
365+
FunctionEnd
366+
367+
Function un.GetParameterValue
368+
Exch $R0 ; get the top of the stack(default parameter) into R0
369+
Exch ; exchange the top of the stack(default) with
370+
; the second in the stack(parameter to search for)
371+
Exch $R1 ; get the top of the stack(search parameter) into $R1
372+
373+
;Preserve on the stack the registers used in this function
374+
Push $R2
375+
Push $R3
376+
Push $R4
377+
Push $R5
378+
379+
Strlen $R2 $R1 ; store the length of the search string into R2
380+
381+
Call un.GetParameters ; get the command line parameters
382+
Pop $R3 ; store the command line string in R3
383+
384+
# search for quoted search string
385+
StrCpy $R5 '"' ; later on we want to search for a open quote
386+
Push $R3 ; push the 'search in' string onto the stack
387+
Push '"$R1' ; push the 'search for'
388+
Call un.StrStr ; search for the quoted parameter value
389+
Pop $R4
390+
StrCpy $R4 $R4 "" 1 ; skip over open quote character, "" means no maxlen
391+
StrCmp $R4 "" "" next ; if we didn't find an empty string go to next
392+
393+
# search for non-quoted search string
394+
StrCpy $R5 ' ' ; later on we want to search for a space since we
395+
; didn't start with an open quote '"' we shouldn't
396+
; look for a close quote '"'
397+
Push $R3 ; push the command line back on the stack for searching
398+
Push '$R1' ; search for the non-quoted search string
399+
Call un.StrStr
400+
Pop $R4
401+
402+
; $R4 now contains the parameter string starting at the search string,
403+
; if it was found
404+
next:
405+
StrCmp $R4 "" check_for_switch ; if we didn't find anything then look for
406+
; usage as a command line switch
407+
# copy the value after $R1 by using StrCpy with an offset of $R2,
408+
# the length of 'OUTPUT'
409+
StrCpy $R0 $R4 "" $R2 ; copy commandline text beyond parameter into $R0
410+
# search for the next parameter so we can trim this extra text off
411+
Push $R0
412+
Push $R5 ; search for either the first space ' ', or the first
413+
; quote '"'
414+
; if we found '"/output' then we want to find the
415+
; ending ", as in '"/output=somevalue"'
416+
; if we found '/output' then we want to find the first
417+
; space after '/output=somevalue'
418+
Call un.StrStr ; search for the next parameter
419+
Pop $R4
420+
StrCmp $R4 "" done ; if 'somevalue' is missing, we are done
421+
StrLen $R4 $R4 ; get the length of 'somevalue' so we can copy this
422+
; text into our output buffer
423+
StrCpy $R0 $R0 -$R4 ; using the length of the string beyond the value,
424+
; copy only the value into $R0
425+
goto done ; if we are in the parameter retrieval path skip over
426+
; the check for a command line switch
427+
428+
; See if the parameter was specified as a command line switch, like '/output'
429+
check_for_switch:
430+
Push $R3 ; push the command line back on the stack for searching
431+
Push '$R1' ; search for the non-quoted search string
432+
Call un.StrStr
433+
Pop $R4
434+
StrCmp $R4 "" done ; if we didn't find anything then use the default
435+
StrCpy $R0 "" ; otherwise copy in an empty string since we found the
436+
; parameter, just didn't find a value
437+
438+
done:
439+
Pop $R5
440+
Pop $R4
441+
Pop $R3
442+
Pop $R2
443+
Pop $R1
444+
Exch $R0 ; put the value in $R0 at the top of the stack
445+
FunctionEnd
446+
325447
#####################################################################
326448
# This function write content of logBuffer variable in log file in
327449
# a log file OcsAgentSetup.log located in install directory
@@ -580,7 +702,7 @@ ParseCmd_NoSystray_End:
580702
WriteINIStr "$PLUGINSDIR\agent.ini" "Field 9" "State" "0"
581703
goto ParseCmd_Now_End
582704
ParseCmd_Now:
583-
; Immediately maunch inventory
705+
; Immediately launch inventory
584706
WriteINIStr "$PLUGINSDIR\agent.ini" "Field 9" "State" "1"
585707
ParseCmd_Now_End:
586708
; Remove parsed arg from command line
@@ -1397,6 +1519,39 @@ FunctionEnd
13971519
Function ValidateAgent2Options
13981520
FunctionEnd
13991521

1522+
Function un.AskUninstallOptions
1523+
; === test (type: Dialog) ===
1524+
nsDialogs::Create 1018
1525+
Pop $hCtl
1526+
${If} $hCtl == error
1527+
Abort
1528+
${EndIf}
1529+
!insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent uninstaller" "You are about to uninstall OCS Inventory NG Agent ${PRODUCT_VERSION}, select uninstall option below..."
1530+
1531+
; === uninstalloptions (type: GroupBox) ===
1532+
${NSD_CreateGroupBox} 8u 7u 280u 126u "Uninstall option"
1533+
Pop $hCtl_uninstalloptions
1534+
1535+
; === clean (type: DropList) ===
1536+
${NSD_CreateDropList} 12u 41u 195u 13u "NONE"
1537+
Pop $hCtl_clean
1538+
${NSD_CB_AddString} $hCtl_clean "NONE"
1539+
${NSD_CB_AddString} $hCtl_clean "ONLY CONFIGURATION FILES"
1540+
${NSD_CB_AddString} $hCtl_clean "ALL FILES"
1541+
${NSD_CB_SelectString} $hCtl_clean "NONE"
1542+
1543+
; === Label1 (type: Label) ===
1544+
${NSD_CreateLabel} 12u 25u 205u 14u "Do you want to remove persistent files from OCS Inventory ?"
1545+
Pop $hCtl_Label1
1546+
1547+
nsDialogs::Show
1548+
FunctionEnd
1549+
1550+
Function un.ValidateUninstallOptions
1551+
${NSD_GetText} $hCtl_clean $0
1552+
StrCpy $uninstallOption "$0"
1553+
FunctionEnd
1554+
14001555
Function AskLocalInventory
14011556
${If} ${SectionIsSelected} 4 ; Index of Local inventory section
14021557
!insertmacro MUI_HEADER_TEXT "OCS Inventory Agent for Windows" "Choose folder to save inventory result..."
@@ -1994,8 +2149,6 @@ Function un.onInit
19942149
Pop $R9
19952150
StrLen $0 $R9
19962151
IntCmp $0 2 unOnInit_silent 0 unOnInit_silent
1997-
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure to uninstall $(^Name)?" IDYES +2
1998-
Abort
19992152
unOnInit_silent:
20002153
FunctionEnd
20012154

@@ -2033,6 +2186,23 @@ Section Uninstall
20332186
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
20342187
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${OLD_PRODUCT_UNINST_KEY}"
20352188
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
2189+
; Get clean paramater
2190+
Push "/CLEAN=" ; push the search string onto the stack
2191+
Push "NONE" ; push a default value onto the stack
2192+
Call un.GetParameterValue
2193+
Pop $2
2194+
2195+
${If} $2 == "ALL"
2196+
${OrIf} $uninstallOption == "ALL FILES"
2197+
RMDir /r /REBOOTOK "$APPDATA\OCS Inventory NG"
2198+
${EndIf}
2199+
2200+
${If} $2 == "FILES"
2201+
${OrIf} $uninstallOption == "ONLY CONFIGURATION FILES"
2202+
RMDir /r /REBOOTOK "$APPDATA\OCS Inventory NG\Agent\Download"
2203+
Delete /REBOOTOK "$APPDATA\OCS Inventory NG\Agent\ocsinventory.ini"
2204+
${EndIf}
2205+
20362206
SetAutoClose true
20372207
SectionEnd
20382208

@@ -2053,4 +2223,4 @@ Function un.onUninstSuccess
20532223
unOnUninstSuccess_silent:
20542224
StrCpy $logBuffer "${PRODUCT_NAME} ${PRODUCT_VERSION} was successfully uninstalled."
20552225
Call un.Write_Log
2056-
FunctionEnd
2226+
FunctionEnd

0 commit comments

Comments
 (0)