; Installer.nsi ; ; This script will install hw.bat and Apache Tomcat server onto the ; computer of the user and into the directory that the user selects. ;----------------------------------- ;-------------------------------- ; Constants ;-------------------------------- !define GET_JAVA_URL "http://www.java.com" ;-------------------------------- ; Variables ;-------------------------------- Var JAVA_HOME Var JAVA_VER Var JAVA_INSTALLATION_MSG ; The name of the installer Name "Installer" ; The file to write to outfile "Installer.exe" ; The default installation directory InstallDir $PROGRAMFILES\Installer ; Registry key to check for directory (so if you install again, it will ; overwrite the old one automatically). InstallDirRegKey HKLM "Software\NSIS_Installer" "Install_Dir" ;---------------------------------- ; Pages 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 file would be placed File "C:\Revin\helloworld.java" File "C:\Revin\HelloWorld.class" File "C:\Revin\MsgBox.java" File "C:\Revin\test.bat" File "C:\Revin\MsgBox.class" File "C:\Revin\hw.bat" File "C:\Revin\Tomcat\Installer.zip" 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\Installer" "DisplayName" "NSIS Installer" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Installer" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Installer" "NoModify" 1 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Installer" "NoRepair" 1 WriteUninstaller "uninstall.exe" SectionEnd Section "JRE Locate and Set Path and Classpath Section" JRECheckAndEnvSection Call LocateJVM StrCmp "" $JAVA_INSTALLATION_MSG Success OpenBrowserToGetJava Success: Call SetEnv Goto Done OpenBrowserToGetJava: Exec '"explorer.exe" ${GET_JAVA_URL}' Done: SectionEnd ;-------------------------------- Function LocateJVM ;Check for Java version and location 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.4 or newer to run this program." Goto Done CheckJavaVer: ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$JAVA_VER" JavaHome GetFullPathName /SHORT $JAVA_HOME "$0" StrCpy $0 $JAVA_VER 1 0 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 ;MessageBox MB_OK "Found Java: $JAVA_VER at $JAVA_HOME" Goto Done JavaVerNotCorrect: StrCpy $JAVA_INSTALLATION_MSG "The version of Java Runtime Environment installed on your computer is $JAVA_VER. Version 1.4 or newer is required to run this program." Done: Pop $1 Pop $0 FunctionEnd ;-------------------------------- Function SetEnv Push $3 Push $4 FileOpen $4 "$INSTDIR\setEnv.cmd" w StrCpy $3 "Set CLASSPATH=$JAVA_HOME\jre\lib\rt.jar;$JAVA_HOME\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 ; Optional Section (can be disabled by the user) Section "Start Menu Shortcuts" CreateDirectory "$SMPROGRAMS\Installer" CreateShortCut "$SMPROGRAMS\Installer\Hello World (MsgBox).lnk" "$INSTDIR\hw.bat" "" "$INSTDIR\hw.bat" 0 CreateShortCut "$SMPROGRAMS\Installer\Extract Files.lnk" "$INSTDIR\test.bat" "" "$INSTDIR\test.bat" 0 CreateShortCut "$SMPROGRAMS\Installer\Java.lnk" "$INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe" "" "$INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe" 0 CreateShortCut "$SMPROGRAMS\Installer\Apache Tomcat.lnk" "$INSTDIR\Installer.zip" "" "$INSTDIR\Installer.zip" 0 CreateShortCut "$SMPROGRAMS\Installer\Set Environment Variable.lnk" "$INSTDIR\setEnv.cmd" "" "$INSTDIR\setEnv.cmd" 0 CreateShortCut "$SMPROGRAMS\Installer\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 SectionEnd ;------------------------------------------ ;uninstaller Section "Uninstall" ; Remove registry keys DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Installer" DeleteRegKey HKLM SOFTWARE\NSS_Installer ; Remove files and uninstaller Delete $INSTDIR\hw.bat Delete $INSTDIR\helloworld.java Delete $INSTDIR\HelloWorld.class Delete $INSTDIR\MsgBox.java Delete $INSTDIR\MsgBox.class Delete $INSTDIR\startup.bat Delete $INSTDIR\test.bat Delete $INSTDIR\tomcat.exe Delete $INSTDIR\Installer.zip Delete $INSTDIR\jakarta-tomcat-4.1.30 Delete $INSTDIR\META-INF Delete $INSTDIR\setEnv.cmd Delete $INSTDIR\j2sdk-1_4_2_02-windows-i586-p.exe Delete $INSTDIR\uninstall.exe ; Remove shortcuts, if any Delete "$SMPROGRAMS\Installer\*.*" ; Remove directories used RMDir "$SMPROGRAMS\Installer" RMDir "$INSTDIR" SectionEnd