Advertisement
Guest User

Java.nsh (patched for JDK support)

a guest
Jun 4th, 2011
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ${SegmentFile}
  2.  
  3. Var UsingJavaExecutable
  4. Var JavaMode
  5. Var JavaDirectory
  6. Var JDKMode
  7. Var JDKDirectory
  8.  
  9. ${SegmentInit}
  10.     ; If [Activate]:Java=find|require, search for Java in the following
  11.     ; locations (in order):
  12.     ;
  13.     ;  - PortableApps.com CommonFiles (..\CommonFiles\Java)
  14.     ;  - Registry (HKLM\Software\JavaSoft\Java Runtime Environment)
  15.     ;  - %JAVA_HOME%
  16.     ;  - Anywhere in %PATH% (with SearchPath)
  17.     ;  - %WINDIR%\Java (from Windows 98, probably obsolete now we don't it)
  18.     ;
  19.     ; If it's in none of those, give up. [Activate]:Java=require will then
  20.     ; abort, [Activate]:Java=find will set it to the non-existent CommonFiles
  21.     ; location. %JAVA_HOME% is then set to the location.
  22.     ClearErrors
  23.     ${ReadLauncherConfig} $JavaMode Activate Java
  24.     ${If} $JavaMode == find
  25.     ${OrIf} $JavaMode == require
  26.         StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
  27.         ${IfNot} ${FileExists} $JavaDirectory
  28.             ClearErrors
  29.             ReadRegStr $0 HKLM "Software\JavaSoft\Java Runtime Environment" CurrentVersion
  30.             ReadRegStr $JavaDirectory HKLM "Software\JavaSoft\Java Runtime Environment\$0" JavaHome
  31.             ${If} ${Errors}
  32.             ${OrIfNot} ${FileExists} $JavaDirectory\bin\java.exe
  33.             ${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
  34.                 ClearErrors
  35.                 ReadEnvStr $JavaDirectory JAVA_HOME
  36.                 ${If} ${Errors}
  37.                 ${OrIfNot} ${FileExists} $JavaDirectory\bin\java.exe
  38.                 ${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
  39.                     ClearErrors
  40.                     SearchPath $JavaDirectory java.exe
  41.                     ${IfNot} ${Errors}
  42.                         ${GetParent} $JavaDirectory $JavaDirectory
  43.                         ${GetParent} $JavaDirectory $JavaDirectory
  44.                     ${Else}
  45.                         StrCpy $JavaDirectory $WINDIR\Java
  46.                         ${IfNot} ${FileExists} $JavaDirectory\bin\java.exe
  47.                         ${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
  48.                             StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
  49.                             ${DebugMsg} "Unable to find Java installation."
  50.                         ${EndIf}
  51.                     ${EndIf}
  52.                 ${EndIf}
  53.             ${EndIf}
  54.         ${EndIf}
  55.  
  56.                 ; Also, if [Activate]:JDK=find|require is set as well (Java must also be set),
  57.                 ; search for the JDK in these locations (in order):
  58.                 ;
  59.                 ;  - JDK_HOME user setting in the AppNamePortable.ini file
  60.                 ;  - [Java]:JDK_HOME
  61.                 ;  - PortableApps.com CommonFiles (..\CommonFiles\JDK)
  62.                 ;  - Registry (HKLM\Software\JavaSoft\Java Development Kit)
  63.                 ;  - %JDK_HOME%
  64.                 ;
  65.                 ; As above, [Activate]:JDK=require will abort if the JDK hasn't been found.
  66.                 ; Note that, the [Java]:JDK_HOME option can be set a custom location on a
  67.                 ; per application basis. The user can override this setting by setting
  68.                 ; JDK_HOME in the AppNamePortable.ini file.
  69.                 ; Then populate %JDK_HOME% with the JDK location.
  70.         ${ReadLauncherConfig} $JDKMode Activate JDK
  71.         ${If} $JDKMode == find
  72.                 ${OrIf} $JDKMode == require
  73.                         ; Set the Default JDKDirectory
  74.                         StrCpy $JDKDirectory $PortableAppsDirectory\CommonFiles\JDK
  75.                         ; Read the settings
  76.                         ${ReadUserConfig} $0 JDK_HOME
  77.                         ${ReadLauncherConfig} $1 Java JDK_HOME
  78.                         ; Reset JDKDirectory according to those settings
  79.                         ${IfNot} $0 == ''
  80.                             StrCpy $JDKDirectory $0
  81.                         ${ElseIfNot} $1 == ''
  82.                                 StrCpy $JDKDirectory $1
  83.                         ${EndIf}
  84.                        
  85.                         ${IfNot} ${FileExists} $JDKDirectory
  86.                     ClearErrors
  87.                     ReadRegStr $0 HKLM "Software\JavaSoft\Java Development Kit" CurrentVersion
  88.                     ReadRegStr $JDKDirectory HKLM "Software\JavaSoft\Java Development Kit\$0" JavaHome
  89.                     ${If} ${Errors}
  90.                     ${OrIfNot} ${FileExists} $JDKDirectory\bin\java.exe
  91.                         ClearErrors
  92.                         ReadEnvStr $JDKDirectory JDK_HOME
  93.                         ${If} ${Errors}
  94.                         ${OrIfNot} ${FileExists} $JDKDirectory\bin\java.exe
  95.                         StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\JDK
  96.                         ${DebugMsg} "Unable to find JDK installation."
  97.                         ${EndIf}
  98.                     ${EndIf}
  99.                 ${EndIf}
  100.                 ${ElseIfNot} ${Errors}
  101.                         ${InvalidValueError} [Activate]:JDK $JDKMode
  102.                 ${EndIf}
  103.                
  104.         ; If Java is required and not found, quit; if it is, check if
  105.         ; [Launch]:ProgramExecutable is java.exe or javaw.exe.
  106.         ${If} $JavaMode == require
  107.             ${IfNot} ${FileExists} $JavaDirectory
  108.                 ;=== Java Portable is missing
  109.                 MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
  110.                 Quit
  111.             ${EndIf}
  112.             ${IfThen} $ProgramExecutable == java.exe ${|} StrCpy $UsingJavaExecutable true ${|}
  113.             ${IfThen} $ProgramExecutable == javaw.exe ${|} StrCpy $UsingJavaExecutable true ${|}
  114.             ${If} $UsingJavaExecutable == true
  115.             ${AndIfNot} ${FileExists} $JavaDirectory\bin\$ProgramExecutable
  116.                 ;=== The required Java binary (java.exe or javaw.exe) is missing.
  117.                 MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
  118.                 Quit
  119.             ${EndIf}
  120.         ${EndIf}
  121.         ; If JDK is required and not found, quit. (Reuses the LauncherNoJava error message)
  122.         ${If} $JDKMode == require
  123.             ${IfNot} ${FileExists} $JDKDirectory
  124.                 ;=== JDK Portable is missing
  125.                 MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
  126.                 Quit
  127.             ${EndIf}
  128.         ${EndIf}
  129.  
  130.         ; Now set %JAVA_HOME% to the path (still may not exist)
  131.         ${DebugMsg} "Selected Java path: $JavaDirectory"
  132.         ${SetEnvironmentVariablesPath} JAVA_HOME $JavaDirectory
  133.         ; Now set %JDK_HOME% to the path (still may not exist)
  134.         ${DebugMsg} "Selected JDK path: $JDKDirectory"
  135.         ${SetEnvironmentVariablesPath} JDK_HOME $JDKDirectory
  136.     ${ElseIfNot} ${Errors}
  137.         ${InvalidValueError} [Activate]:Java $JavaMode
  138.     ${EndIf}
  139. !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement