; This installer will install the file named projects.zip. It will then extract the ; contents of projects.zip into c:\. ; ; It will also check for the availability of J2SE. If it is not available on the system ; or if the version of the J2SDK is lower than J2SDK 1.2 then it will automatically ; launch the J2SDK intallation wizard. ; ; This installer will also automatically add environment variables without having ; the user to do it manually. ;------------------------- ;Variables ;------------------------- Var JAVA_HOME Var JAVA_VER Var JAVA_INSTALLATION_MSG ;------------------------- ;The name of the installer ;------------------------- Name "SMSQInterface" ;------------------------- ;The file to write to ;------------------------- Outfile "SMSQInterface.exe" ;------------------------- ;The default installation directory ;------------------------- InstallDir $PROGRAMFILES\Project ;------------------------- ;Registry key to check for the directory (so if you install again, it will ;overwrite the old one automatically). ;------------------------- InstallDirRegKey HKLM "Software\NSIS_Project " "Install_Dir" ;------------------------- ;The pages of the installer ;------------------------- Page components Page directory Page instfiles UninstPage uninstConfirm UninstPage instfiles ;------------------------- ;The stuff to install ;------------------------- Section "Installer (required)" SectionIn RO ;Set output path to the installation directory SetOutPath $INSTDIR ;Where the files would be placed ;Place the files that you want to be included in the installer here File "C:\j2sdk-1_4_2_02-windows-i586-p.exe" ;Write the uninstall keys for the uninstaller WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Project" "DisplayName" "NSIS Project " WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Project" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Project" "NoModify" 1 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Project" "NoRepair" 1 WriteUninstaller "uninstall.exe" SectionEnd ;------------------------- ;This section will check for the Java version and it's location ;------------------------- Section "JRE Locate and Set Path and Classpath Section" JRECheckAndEnvSection Call LocateJVM Call LocateJDK StrCmp "" $JAVA_INSTALLATION_MSG Success Success: Call SetEnv Goto Done Done: SectionEnd ;------------------------- ;Function to check for the existance of JVM and the version ;------------------------- Function LocateJVM Push $0 Push $1 ReadRegStr $JAVA_VER HKLM "SOFTWARE\JavaSoft\Java Runtime Environment"CurrentVersion StrCmp "" "$JAVA_VER" JavaNotPresent CheckJavaVer JavaNotPresent: StrCpy $JAVA_INSTALLATION_MSG "Java Runtime Environment is not installed on your computer. You need version 1.2 or newer to run this program." ExecWait "$INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe" $0 Goto Done CheckJavaVer: ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$JAVA_VER" JavaHome GetFullPathName /SHORT $JAVA_HOME "$0" MessageBox MB_OK "The Java Version found on the system is: $Java_Ver" StrCpy $1 $JAVA_VER 1 2 StrCpy $JAVA_VER "$0$1" IntCmp 14 $JAVA_VER FoundCorrectJavaVer FoundCorrectJavaVer JavaVerNotCorrect FoundCorrectJavaVer: IfFileExists "$JAVA_HOME\bin\javaw.exe" 0 JavaNotPresent Goto Done JavaVerNotCorrect: StrCpy $JAVA_INSTALLATION_MSG "The version of Java Runtime Environment installed on your computer is $JAVA_VER. Version 1.2 or newer is required to run this program." Done: Pop $1 Pop $0 FunctionEnd ;------------------------- ;Function to set the environment variables automatically ;------------------------- Function SetEnv Push $3 Push $4 FileOpen $4 "$INSTDIR\setEnv.cmd" w StrCpy $3 "Set Classpath=$JAVA_HOME\jre\lib\rt.jar;$JAVA_HOME\jre\lib\dt.jar;%CLASSPATH%" FileWrite $4 "$3" FileWriteByte $4 "13" FileWriteByte $4 "10" StrCpy $3 "Set PATH=$JAVA_HOME\bin;%PATH%" FileWrite $4 "$3" FileClose $4 Pop $4 Pop $3 FunctionEnd ;------------------------- ;The function to locate the JDK and to verify the version of the JDK ;------------------------- Function LocateJDK Push $0 ClearErrors ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion" ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome" IfErrors 0 NoAbort MessageBox MB_OK "Couldn't find a Java Development Kit installed. Setup will exit now." Goto JavaNotPresent JavaNotPresent: StrCpy $JAVA_INSTALLATION_MSG "Java Runtime Environment is not installed on your computer. You need version 1.2 or newer to run this program." ExecWait "$INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe" $0 Goto Done NoAbort: MessageBox MB_OK "Found JDK in path $2" Done: Pop $0 FunctionEnd ;------------------------- ;Section to append to the existing environment variable ;------------------------- Section "Append Env Var" ReadEnvStr $0 "PATH" Push "PATH" Push "$0;c:\Example" Call WriteEnvStr SectionEnd ;------------------------- ;Funtion to write the environment variables (testing only...not too sure if it will work) ;------------------------- !include WinMessages.nsh !ifdef ALL_USERS !define WriteEnvStr_RegKey \ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' !else !define WriteEnvStr_RegKey 'HKCU "Environment"' !endif # # WriteEnvStr - Writes an environment variable # Note: Win9x systems requires reboot # # Example: # Push "HOMEDIR" # name # Push "C:\New Home Dir\" # value # Call WriteEnvStr # Function WriteEnvStr Exch $1 ; $1 has environment variable value Exch Exch $0 ; $0 has environment variable name Push $2 Call IsNT Pop $2 StrCmp $2 1 WriteEnvStr_NT ; Not on NT StrCpy $2 $WINDIR 2 ; Copy drive of windows (c:) FileOpen $2 "$2\autoexec.bat" a FileSeek $2 0 End FileWrite $2 "$\r$\nSET $0=$1$\r$\n" FileClose $2 SetRebootFlag true Goto WriteEnvStr_done WriteEnvStr_NT: WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \ 0 "STR:Environment" /TIMEOUT=5000 WriteEnvStr_done: Pop $2 Pop $1 Pop $0 FunctionEnd ;------------------------- ;Section to remove the Environment Variable ;------------------------- Section uninstall # remove the variable Push MyEnvVar Call un.DeleteEnvStr SectionEnd ;------------------------- ;Function to remove the environment variable ;------------------------- Function un.DeleteEnvStr Exch $0 ; $0 has the name of the variable Push $1 Push $2 Push $3 Push $4 Push $5 Call un.IsNT Pop $1 StrCmp $1 1 DeleteEnvStr_NT ; Not on NT StrCpy $1 $WINDIR 2 FileOpen $1 "$1\autoexec.bat" r GetTempFileName $4 FileOpen $2 $4 w StrCpy $0 "SET $0=" SetRebootFlag true DeleteEnvStr_dosLoop: FileRead $1 $3 StrLen $5 $0 StrCpy $5 $3 $5 StrCmp $5 $0 DeleteEnvStr_dosLoop StrCmp $5 "" DeleteEnvStr_dosLoopEnd FileWrite $2 $3 Goto DeleteEnvStr_dosLoop DeleteEnvStr_dosLoopEnd: FileClose $2 FileClose $1 StrCpy $1 $WINDIR 2 Delete "$1\autoexec.bat" CopyFiles /SILENT $4 "$1\autoexec.bat" Delete $4 Goto DeleteEnvStr_done DeleteEnvStr_NT: DeleteRegValue ${WriteEnvStr_RegKey} $0 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \ 0 "STR:Environment" /TIMEOUT=5000 DeleteEnvStr_done: Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd ;------------------------- ;Section Add to Path ;------------------------- Section "Add to path" Push $INSTDIR Call AddToPath SectionEnd ;------------------------- ;Function in the flesh ;------------------------- !verbose 3 !include "WinMessages.NSH" !verbose 4 ;AddToPath - Adds the given dir to the search path. ; Input - head of the stack ; Note - Win9x systems requires reboot ;------------------------- ;Function for AddToPath ;------------------------- Function AddToPath Exch $0 Push $1 Push $2 Push $3 # don't add if the path does not exist IfFileExists $0 "" AddToPath_done ReadEnvStr $1 PATH Push "$1;" Push "$0;" Call StrStr Pop $2 StrCmp $2 "" "" AddToPath_done Push "$1;" Push "$0\;" Call StrStr Pop $2 StrCmp $2 "" "" AddToPath_done GetFullPathName /SHORT $3 $0 Push "$1;" Push "$3;" Call StrStr Pop $2 StrCmp $2 "" "" AddToPath_done Call IsNT Pop $1 StrCmp $1 1 AddToPath_NT ; Not on NT StrCpy $1 $WINDIR 2 FileOpen $1 "$1\autoexec.bat" a FileSeek $1 -1 END FileReadByte $1 $2 IntCmp $2 26 0 +2 +2 # DOS EOF FileSeek $1 -1 END # write over EOF FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n" FileClose $1 SetRebootFlag true Goto AddToPath_done AddToPath_NT: ReadRegStr $1 HKCU "Environment" "PATH" StrCpy $2 $1 1 -1 # copy last char StrCmp $2 ";" 0 +2 # if last char == ; StrCpy $1 $1 -1 # remove last char StrCmp $1 "" AddToPath_NTdoIt StrCpy $0 "$1;$0" AddToPath_NTdoIt: WriteRegExpandStr HKCU "Environment" "PATH" $0 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment"/TIMEOUT=5000 AddToPath_done: Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd ;------------------------- ;Function to RemoveFromPath - Remove a given dir from the path ; Input: head of stack ;------------------------- Function un.RemoveFromPath Exch $0 Push $1 Push $2 Push $3 Push $4 Push $5 Push $6 IntFmt $6 "%c" 26 # DOS EOF Call un.IsNT Pop $1 StrCmp $1 1 unRemoveFromPath_NT ; Not on NT StrCpy $1 $WINDIR 2 FileOpen $1 "$1\autoexec.bat" r GetTempFileName $4 FileOpen $2 $4 w GetFullPathName /SHORT $0 $0 StrCpy $0 "SET PATH=%PATH%;$0" Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoop: FileRead $1 $3 StrCpy $5 $3 1 -1 # read last char StrCmp $5 $6 0 +2 # if DOS EOF StrCpy $3 $3 -1 # remove DOS EOF so we can compare StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine StrCmp $3 "" unRemoveFromPath_dosLoopEnd FileWrite $2 $3 Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoopRemoveLine: SetRebootFlag true Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoopEnd: FileClose $2 FileClose $1 StrCpy $1 $WINDIR 2 Delete "$1\autoexec.bat" CopyFiles /SILENT $4 "$1\autoexec.bat" Delete $4 Goto unRemoveFromPath_done unRemoveFromPath_NT: ReadRegStr $1 HKCU "Environment" "PATH" StrCpy $5 $1 1 -1 # copy last char StrCmp $5 ";" +2 # if last char != ; StrCpy $1 "$1;" # append Push $1 Push "$0;" Call un.StrStr ; Find `$0;` in $1 Pop $2 ; position of our dir StrCmp $2 "" unRemoveFromPath_done ; else, it is in the path # $0 - path to add # $1 - path var StrLen $3 "$0;" StrLen $4 $2 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove StrCpy $3 $5$6 StrCpy $5 $3 1 -1 # copy last char StrCmp $5 ";" 0 +2 # if last char == ; StrCpy $3 $3 -1 # remove last char WriteRegExpandStr HKCU "Environment" "PATH" $3 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment"/TIMEOUT=5000 unRemoveFromPath_done: Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd # # [un.] IsNT - Pushes 1 if running on NT, 0 if not # #Example: # Call IsNT # Pop $0 # StrCmp $0 1 +3 # MessageBox MB_OK "Not running on NT!" # Goto +2 # MessageBox MB_OK "Running on NT!" # !macro IsNT UN Function ${UN}IsNT Push $0 ReadRegStr $0 HKLM \ "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion StrCmp $0 "" 0 IsNT_yes ; we are not NT. Pop $0 Push 0 Return IsNT_yes: ; NT!!! Pop $0 Push 1 FunctionEnd !macroend !insertmacro IsNT "" !insertmacro IsNT "un." ;------------------------- ;StrStr portion ;------------------------- !macro StrStr un Function ${un}StrStr Exch $R1 ; st=haystack,old$R1, $R1=needle Exch Exch $R2 Push $R3 Push $R4 Push $R5 StrLen $R3 $R1 StrCpy $R4 0 loop: StrCpy $R5 $R2 $R3 $R4 StrCmp $R5 $R1 done StrCmp $R5 "" done IntOp $R4 $R4 + 1 Goto loop done: StrCpy $R1 $R2 "" $R4 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 FunctionEnd !macroend !insertmacro StrStr "" !insertmacro StrStr "un." ;------------------------- ;Optional Section (can be disabled by the user) ;------------------------- Section "Start Menu Shortcuts" CreateDirectory "$SMPROGRAMS\Project" CreateShortCut "$SMPROGRAMS\Project\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 ;To create the shortcuts for the start menu. SectionEnd ;------------------------- ;The uninstaller section ;------------------------- Section "Uninstall" ;Remove Registry Keys DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Project " DeleteRegKey HKLM SOFTWARE\NSIS_Project ;Remove files and the uninstaller Delete $INSTDIR\uninstall.exe Delete $INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe Delete $INSTDIR\setEnv.cmd ;More files here Push $INSTDIR Call un.RemoveFromPath ;Remove shortcuts, if any Delete "$SMPROGRAMS\Project\*.*" ;Remove directories used RMDir "$SMPROGRAMS\Project" RMDir "$INSTDIR" SectionEnd ;------------------------- ;EOF ;-------------------------