!include nsDialogs.nsh !include LogicLib.nsh !include "MUI.nsh" Name "Primary Email Notify" !insertmacro MUI_PAGE_WELCOME Page custom nsDialogsPage InstallDir "$DOCUMENTS" Var EDIT Var username Function nsDialogsPage nsDialogs::Create /NOUNLOAD 1018 Pop $0 ${NSD_CreateText} 100 35 100% 12u john.smith Pop $EDIT ${NSD_CreateLabel} 0 35 75% 40u "firstname.surname: " Pop $0 ${NSD_CreateLabel} 0 40u 75% 40u "- Type your firstname.surname or username above. ie john.smith" Pop $0 ${NSD_CreateLabel} 0 50u 75% 40u "- This is the username you log into www.primaryemail.co.uk with" Pop $0 nsDialogs::Show ${NSD_GetText} $EDIT $username MessageBox MB_OK $username FunctionEnd Section MessageBox MB_OK $username SectionEnd ShowInstDetails show ;-------------------------------- ;Pages !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_LANGUAGE "English" ;-------------------------------- !ifdef HAVE_UPX !packhdr tmp.dat "upx\upx -9 tmp.dat" !endif !ifdef NOCOMPRESS SetCompress off !endif ;-------------------------------- Caption "Primary Email Notify Installer" Icon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-install.ico" OutFile "primaryemail_notify_setup.exe" SetDateSave on SetDatablockOptimize on CRCCheck on SilentInstall normal InstallColors FFFFFF 000030 XPStyle on BrandingText "Primary Technology Installer v1.00" InstallDirRegKey HKLM "Software\PrimaryTechnology" "" CheckBitmap "${NSISDIR}\Contrib\Graphics\Checks\classic-cross.bmp" LicenseText "License Agreement" LicenseData "setup.nsi" UninstPage uninstConfirm UninstPage instfiles ;-------------------------------- !ifndef NOINSTTYPES ; only if not defined InstType "Primary Email Notify" !endif AutoCloseWindow false ShowInstDetails show ;-------------------------------- Section "" ; empty string makes it hidden, so would starting with - WriteRegStr HKLM SOFTWARE\PrimaryTechnology "Install_Dir" "$INSTDIR" ; write uninstall strings WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PrimaryTechnology" "DisplayName" "PrimaryTechnology (remove only)" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PrimaryTechnology" "UninstallString" '"$INSTDIR\bt-uninst.exe"' WriteUninstaller "bt-uninst.exe" Nop ; for fun SectionEnd Section "Primary Email Notify Installer" SectionIn 1 File /r files\*.* SetOutPath $DOCUMENTS File files\config.xml File files\owanotify.exe Push "$DOCUMENTS\config.xml" ; file to modify Push " ---username---" ; string that a line must begin with Push " $username" ; string to replace whole line with Call ReplaceLineStr Push "$DOCUMENTS\config.xml" ; file to modify Push " https://exchange.primaryt.co.uk/exchange/---username---/inbox" ; string that a line must begin with Push " https://exchange.primaryt.co.uk/exchange/$username/inbox" ; string to replace whole line with Call ReplaceLineStr sleep 1000 ExecShell "" "$DOCUMENTS\owanotify.exe" SectionEnd Function ReplaceLineStr Exch $R0 ; string to replace that whole line with Exch Exch $R1 ; string that line should start with Exch Exch 2 Exch $R2 ; file Push $R3 ; file handle Push $R4 ; temp file Push $R5 ; temp file handle Push $R6 ; global Push $R7 ; input string length Push $R8 ; line string length Push $R9 ; global StrLen $R7 $R1 GetTempFileName $R4 FileOpen $R5 $R4 w FileOpen $R3 $R2 r ReadLoop: ClearErrors FileRead $R3 $R6 IfErrors Done StrLen $R8 $R6 StrCpy $R9 $R6 $R7 -$R8 StrCmp $R9 $R1 0 +3 FileWrite $R5 "$R0$\r$\n" Goto ReadLoop FileWrite $R5 $R6 Goto ReadLoop Done: FileClose $R3 FileClose $R5 SetDetailsPrint none Delete $R2 Rename $R4 $R2 SetDetailsPrint both Pop $R9 Pop $R8 Pop $R7 Pop $R6 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Pop $R1 Pop $R0 FunctionEnd ;-------------------------------- ; Uninstaller UninstallText "This will uninstall Primary Technology Software. Hit next to continue." UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-uninstall.ico" Section "Uninstall" DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PrimaryTechnology" DeleteRegKey HKLM "SOFTWARE\PrimaryTechnology" Delete "$INSTDIR\bt-uninst.exe" MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR\cpdest?" IDNO NoDelete Delete "$INSTDIR\cpdest\*.*" RMDir "$INSTDIR\cpdest" ; skipped if no NoDelete: RMDir "$INSTDIR" IfFileExists "$INSTDIR" 0 NoErrorMsg MessageBox MB_OK "Note: $INSTDIR could not be removed!" IDOK 0 ; skipped if file doesn't exist NoErrorMsg: SectionEnd