!include Sections.nsh !include "MUI2.nsh" !include "LogicLib.nsh" !define MUI_ICON "blue.ico" Name "APS Setup Test" OutFile "APS Install.exe" InstallDir "C:\APS_Dashboard" !define PROG1_InstDir "C:\PROG1" !define PROG2_InstDir "C:\PROG2" !define PROG3_InstDir "C:\APS_Services" !define PROG3_BinInstDir "C:\APS_Services\bin" !macro BackupFile FILE_DIR FILE BACKUP_TO IfFileExists "${BACKUP_TO}\*.*" +2 CreateDirectory "${BACKUP_TO}" IfFileExists "${FILE_DIR}\${FILE}" 0 +2 Rename "${FILE_DIR}\${FILE}" "${BACKUP_TO}\${FILE}" !macroend !macro RestoreFile BUP_DIR FILE RESTORE_TO IfFileExists "${BUP_DIR}\${FILE}" 0 +2 Rename "${BUP_DIR}\${FILE}" "${RESTORE_TO}\${FILE}" !macroend !macro "RemoveDBBackup" Delete "$3\nsi-backup\APSBusinessLayer.dll" Delete "$3\nsi-backup\APSDashboard.exe" Delete "$3\nsi-backup\APSDashboard.exe.config" Delete "$3\nsi-backup\MPSRNG.dll" Delete "$3\nsi-backup\RichTextBoxPrintCtrl.dll" RMDir "$3\nsi-backup" !macroEnd !macro "RemoveClientBackup" Delete "$4\nsi-backup\APS_DBClient_110a.exe" RMDir "$4\nsi-backup" !macroEnd !macro "RemoveLegacySoapBackup" Delete "C:\APS_Services\nsi-backup\APSSOAPService.exe" RMDir "C:\APS_Services\nsi-backup" !macroEnd !macro "RemoveIISSoapBackup" Delete "C:\APS_Services\nsi-backup\APSSoap.asmx" Delete "C:\APS_Services\nsi-backup\Web.config" RMDir "C:\APS_Services\nsi-backup" Delete "C:\APS_Services\bin\nsi-backup\APSSOAPService.dll" RMDir "C:\APS_Services\bin\nsi-backup" !macroEnd !macro "SuccessfulInstall" !insertmacro RemoveDBBackup !insertmacro RemoveClientBackup !insertmacro RemoveLegacySoapBackup !insertmacro RemoveIISSoapBackup !macroEnd !macro "UninstallDash" #Remove installed copy Delete "$3\APSBusinessLayer.dll" Delete "$3\APSDashboard.exe" Delete "$3\APSDashboard.exe.config" Delete "$3\MPSRNG.dll" Delete "$3\RichTextBoxPrintCtrl.dll" #Restore old copy StrCpy $INSTDIR $3 !insertmacro RestoreFile "$3\nsi-backup" "APSBusinessLayer.dll" "$3" !insertmacro RestoreFile "$3\nsi-backup" "APSDashboard.exe" "$3" !insertmacro RestoreFile "$3\nsi-backup" "APSDashboard.exe.config" "$3" !insertmacro RestoreFile "$3\nsi-backup" "MPSRNG.dll" "$3" !insertmacro RestoreFile "$3\nsi-backup" "RichTextBoxPrintCtrl.dll" "$3" !insertmacro RemoveDBBackup !macroEnd !macro "UnistallClient" Delete "$4\APS_DBClient_110a.exe" !insertmacro RestoreFile "$4\nsi-backup" "APS_DBClient_110a.exe" "$4" !insertmacro "UninstallDash" !insertmacro RemoveClientBackup !macroEnd !macro "uninstallIISService" Delete "${PROG3_InstDir}\APSSoap.asmx" Delete "${PROG3_InstDir}\Web.config" !insertmacro RestoreFile "$Prog3_InstDir\nsi-backup" "APSSoap.asmx" "$PROG3_InstDir" !insertmacro RestoreFile "$Prog3_InstDir\nsi-backup" "Web.config" "$PROG3_InstDir" !insertmacro RemoveIISSoapBackup !macroEnd !macro "uninstallIISServiceBin" Delete "${PROG3_BinInstDir}\APSSOAPService.dll" !insertmacro RestoreFile "$Prog3_BinInstDir\nsi-backup" "APSSOAPService.dll" "$PROG3_BinInstDir" !macroEnd !macro "uninstallSoapService" Delete "${PROG3_InstDir}\APSSOAPService.exe" !insertmacro RestoreFile "$Prog3_InstDir\nsi-backup" "APSSoapService.exe" "$PROG3_InstDir" !insertmacro RemoveLegacySoapBackup !macroEnd !define MUI_ABORTWARNING !define MUI_WELCOMEFINISHPAGE_BITMAP "aps-logo3.bmp" !define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH !define MUI_PAGE_HEADER_TEXT "APS Installation Software" !define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_Dashboard)" !define MUI_HEADERIMAGE !define MUI_HEADERIMAGE_BITMAP "aps-logo2.bmp" !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallSQL !define MUI_WELCOMEPAGE_TITLE "Run SQL Install" !define MUI_WELCOMEPAGE_TEXT "Click next to run the SQL installation" !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "SQL installed successfully" !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_INSTFILES !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallDB !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Dashboard Installed Successfully" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_DashBboardClient)" !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallClient !insertmacro MUI_PAGE_DIRECTORY !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "Dashboard Client Installed Successfully" !insertmacro MUI_PAGE_INSTFILES !define MUI_INSTFILESPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_Service)" !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallService !define MUI_WELCOMEPAGE_TITLE "Install the APS Service" !define MUI_WELCOMEPAGE_TEXT "Click next to install the APS Service \r\nThe Service will automatically be stopped and restarted" !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "APS Service Installed Successfully" !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_INSTFILES !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallIISService !define MUI_WELCOMEPAGE_TITLE "Install the APS IIS Web Service" !define MUI_WELCOMEPAGE_TEXT "Click next to install the APS IIS Web Service \r\nThe Web Service will automatically be stopped and restarted" !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT "APS IIS Web Service Installed Successfully" !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_INSTFILES LangString MUI_DIRECTORYPAGE_TEXT_TOP_Dashboard ${LANG_ENGLSH} "Setup will install the APS Dashboard" LangString MUI_DIRECTORYPAGE_TEXT_TOP_DashBboardClient ${LANG_ENGLSH} "Setup will install the APS Dashboard Client" !define MUI_CUSTOMFUNCTION_ABORT MyOnUserAbort !insertmacro MUI_LANGUAGE "English" SectionGroup /e "Dashboard" Dashboard Section "Dashboard Install" SecDash StrCmp $5 '0' '' NoDBInstall ReadINIStr $R0 "$PLUGINSDIR\test.ini" "Field 1" "State" StrCpy $3 $INSTDIR SetOutPath $INSTDIR !insertmacro BackupFile "$INSTDIR" "APSBusinessLayer.dll" "$INSTDIR\nsi-backup" !insertmacro BackupFile "$INSTDIR" "APSDashboard.exe" "$INSTDIR\nsi-backup" !insertmacro BackupFile "$INSTDIR" "APSDashboard.exe.config" "$INSTDIR\nsi-backup" !insertmacro BackupFile "$INSTDIR" "MPSRNG.dll" "$INSTDIR\nsi-backup" !insertmacro BackupFile "$INSTDIR" "RichTextBoxPrintCtrl.dll" "$INSTDIR\nsi-backup" ClearErrors file APSBusinessLayer.dll file APSDashboard.exe file APSDashboard.exe.config file MPSRNG.dll file RichTextBoxPrintCtrl.dll IfErrors notPossible possible notPossible: MessageBox MB_OK "Error occurred installing APS Dashboard" !insertmacro UninstallDash Abort possible: ;WriteRegStr HKLM APSDashboard InstallSource "$EXEDIR" NoDBInstall: SectionEnd Section "Other" SEC2 SectionEND SectionGroupEnd SectionGroup /e "DashboardClient" dClient Section "Dashboard Client Install" secClient StrCmp $5 '1' '' NoClientInstall ReadINIStr $R0 "$PLUGINSDIR\test.ini" "Field 1" "State" StrCpy $4 $INSTDIR SetOutPath $INSTDIR !insertmacro BackupFile "$INSTDIR" "APS_DBClient_110a.exe" "$INSTDIR\nsi-backup" ClearErrors file "APS_DBClient_110a.exe" IfErrors notPossible possible notPossible: MessageBox MB_OK "Error occurred installing APS Dashboard Client" !insertmacro UnistallClient !insertmacro UninstallDash Abort possible: !insertMacro SuccessfulInstall NoClientInstall: StrCpy $INSTDIR "C:\APS_Client" SectionEnd Section "Other" SEC3 SectionEND SectionGroupEnd SectionGroup /e "SQL" SQLUpdate Section "SQL Update" secSQL StrCmp $5 '4' '' NoSqlUpdate StrCpy $INSTDIR ${PROG3_INSTDIR} SetOutPath $INSTDIR ;ExecWait "notepad.exe" $R8 ExecWait "$INSTDIR\command.exe" $R8 IntCmp $R8 0 NoFail FailSQL FailSQL: MessageBox MB_OK "An error occurred updating the SQL Database" Abort NoFail: StrCpy $INSTDIR "C:\APS_Dashboard" noSqlUpdate: SectionEnd Section "Other" SEC6 SectionEND SectionGroupEnd SectionGroup /e "Service" SoapService Section "APSSoapService Install" secService StrCmp $5 '2' '' NoServiceInstall StrCpy $INSTDIR ${PROG3_INSTDIR} SetOutPath $INSTDIR !insertmacro BackupFile "$INSTDIR" "APSSOAPService.exe" "$INSTDIR\nsi-backup" ClearErrors SimpleSC::ServiceIsRunning "MyService" Pop $0 ; returns an errorcode (<>0) otherwise success (0) Pop $1 ; return 1 (service is running) - return 0 (service is not running) IntCmp $0 0 '' Fail SimpleSC::StopService "APSService" Fail: Pop $0 ; returns an errorcode (<>0) otherwise success (0) file "APSSoapService.exe" ; Start a service SimpleSC::StartService "APSService" "" Pop $0 ; returns an errorcode (<>0) otherwise success (0) IfErrors notPossible possible notPossible: MessageBox MB_OK "Error occurred installing APSSoapService" !insertmacro uninstallSoapService !insertmacro unistallClient !insertmacro uninstallDash Abort possible: NoServiceInstall: SectionEnd Section "Other" SEC4 SectionEND SectionGroupEnd SectionGroup /e "IISService" iisService Section "ISS Service Install" secIISService StrCmp $5 '3' '' NoIISServiceInstall StrCpy $INSTDIR ${PROG3_INSTDIR} SetOutPath $INSTDIR !insertMacro BackupFile "$INSTDIR" "APSSOAP.asmx" "$INSTDIR\nsi-backup" !insertMacro BackupFile "$INSTDIR" "Web.config" "$INSTDIR\nsi-backup" ClearErrors file "APSSoap.asmx" file "Web.config" ;ExecWait '"cscript" %WinDir%\System32\iisweb.vbs /stop "APSSoap"' ;ExecWait '"cscript" %WinDir%\System32\iisweb.vbs /start "APSSoap"' ifErrors notPossible possible notPossible: MessageBox MB_OK "Error installing the IIS Soap Service" !insertmacro uninstallIISService !insertmacro uninstallSoapService !insertmacro unistallClient !insertmacro uninstallDash possible: StrCpy $INSTDIR ${PROG3_BinINSTDIR} SetOutPath $INSTDIR !insertMacro BackupFile "$INSTDIR" "APSSOAPService.dll" "$INSTDIR\nsi-backup" ClearErrors file "bin\APSSOAPService.dll" ifErrors notPossible2 possible2 notPossible2: MessageBox MB_OK "Error installing the IIS Soap Service" !insertmacro uninstallIISServiceBin !insertmacro uninstallIISService !insertmacro uninstallSoapService !insertmacro unistallClient !insertmacro uninstallDash possible2: NoIISServiceInstall: SectionEnd Section "Other" SEC5 SectionEnd SectionGroupEnd !define PROG1_StartIndex ${secDash} !define PROG1_EndIndex ${SEC2} !define PROG2_StartIndex ${secClient} !define PROG2_EndIndex ${SEC3} !define PROG3_StartIndex ${secService} !define PROG3_EndIndex ${SEC4} !define PROG4_StartIndex ${secIISService} !define PROG4_EndIndex ${SEC5} !define PROG5_StartIndex ${secSQL} !define PROG5_EndIndex ${SEC6} Function .onInit InitPluginsDir FunctionEnd Function InstallDB StrCpy $5 '0' StrCpy $R0 ${PROG1_StartIndex} # Group 1 start Loop: IntOp $R0 $R0 + 1 StrCmp $R0 ${PROG1_EndIndex} 0 Loop FunctionEND Function InstallClient StrCpy $5 '1' StrCpy $R0 ${PROG2_StartIndex} # Group 2 start Loop: IntOp $R0 $R0 + 1 StrCmp $R0 ${PROG2_EndIndex} 0 Loop FunctionEND Function InstallService StrCpy $5 '2' StrCpy $R0 ${PROG3_StartIndex} # Group 3 start Loop: IntOp $R0 $R0 + 1 StrCmp $R0 ${PROG3_EndIndex} 0 Loop FunctionEND Function InstallIISService StrCpy $5 '3' StrCpy $R0 ${PROG4_StartIndex} # Group 3 start Loop: IntOp $R0 $R0 + 1 StrCmp $R0 ${PROG4_EndIndex} 0 Loop FunctionEND Function InstallSQL StrCpy $5 '4' StrCpy $R0 ${PROG5_StartIndex} # Group 3 start Loop: IntOp $R0 $R0 + 1 StrCmp $R0 ${PROG5_EndIndex} 0 Loop FunctionEND Function MyOnUserAbort MessageBox MB_OK "Installation has been canceled, and will be rolled back" StrCmp $5 '0' '' Next ;dashbaord !insertmacro uninstallDash Next: StrCmp $5 '1' '' Next1 ;client !insertmacro unistallClient !insertmacro uninstallDash Next1: StrCmp $5 '2' '' Next2 ;legacysoap !insertmacro uninstallSoapService !insertmacro unistallClient !insertmacro uninstallDash Next2: StrCmp $5 '3' '' Next3 ;iis service !insertmacro uninstallIISService !insertmacro uninstallSoapService !insertmacro unistallClient !insertmacro uninstallDash Next3: FunctionEnd ;LangString DESC_SecDummy ${LANG_ENGLISH} "A test section." ;Assign language strings to sections ; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN ; !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy) ;!insertmacro MUI_FUNCTION_DESCRIPTION_END