Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Add JDK and 64-bit support #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 149 additions & 46 deletions Other/Source/Segments/Java.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,179 @@ ${SegmentFile}
Var UsingJavaExecutable
Var JavaMode
Var JavaDirectory
Var JDKMode

!macro _Java_CheckJavaInstall _t _f
${IfNot} ${Errors}
${AndIf} ${FileExists} $JavaDirectory\bin\java.exe
${AndIf} ${FileExists} $JavaDirectory\bin\javaw.exe
Goto `${_t}`
${Else}
Goto `${_f}`
${EndIf}
!macroend
!macro _Java_FindJava
${If} $Bits = 64
ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\OpenJDK64
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\JDK64
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\OpenJDKJRE64
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java64
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0
${EndIf}

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\OpenJDK
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\JDK
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\OpenJDKJRE
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
ReadRegStr $0 HKLM "Software\JavaSoft\Java Runtime Environment" CurrentVersion
ReadRegStr $JavaDirectory HKLM "Software\JavaSoft\Java Runtime Environment\$0" JavaHome
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
ReadRegStr $0 HKLM "Software\JavaSoft\Java Development Kit" CurrentVersion
ReadRegStr $JavaDirectory HKLM "Software\JavaSoft\Java Development Kit\$0" JavaHome
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
ReadEnvStr $JavaDirectory JAVA_HOME
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

ClearErrors
SearchPath $JavaDirectory java.exe
${GetParent} $JavaDirectory $JavaDirectory
${GetParent} $JavaDirectory $JavaDirectory
!insertmacro _Java_CheckJavaInstall _Java_FindJava_Found 0

StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
${DebugMsg} "Unable to find Java installation"

_Java_FindJava_Found:
!macroend

${SegmentInit}
; If [Activate]:Java=find|require, search for Java in the following
; locations (in order):
; If appinfo.ini\[Dependencies]:UsesJava=yes|optional, search for Java
; in the following locations (in order):
;
; - PortableApps.com CommonFiles (..\CommonFiles\Java)
; - PortableApps.com CommonFiles (..\CommonFiles\OpenJDK) {64 bit version first on 64 bit system}
; - PortableApps.com CommonFiles (..\CommonFiles\JDK) {64 bit version first on 64 bit system}
; - PortableApps.com CommonFiles (..\CommonFiles\OpenJDKJRE) {64 bit version first on 64 bit system}
; - PortableApps.com CommonFiles (..\CommonFiles\Java) {64 bit version first on 64 bit system}
; - Registry (HKLM\Software\JavaSoft\Java Runtime Environment)
; - Registry (HKLM\Software\JavaSoft\JAVA Development Kit}
; - %JAVA_HOME%
; - Anywhere in %PATH% (with SearchPath)
; - %WINDIR%\Java (from Windows 98, probably obsolete now we don't it)
;
; If it's in none of those, give up. [Activate]:Java=require will then
; abort, [Activate]:Java=find will set it to the non-existent CommonFiles
; If it's in none of those, give up. UsesJava=yes will then abort,
; UsesJava=optional will set it to the non-existentCommonFiles
; location. %JAVA_HOME% is then set to the location.
;
; Compatibility mappings:
; launcher.ini\[Activate]:Java=find -> optional
; launcher.ini\[Activate]:Java=require -> yes
; launcher.ini\[Activate]:JDK=find -> optional
; launcher.ini\[Activate]:JDK=require -> yes
; appinfo.ini\[Dependencies]:UsesJava=true -> yes
; appinfo.ini\[Dependencies]:UsesJava=false -> no

ClearErrors
${ReadLauncherConfig} $JavaMode Activate Java
${If} $JavaMode == find
${OrIf} $JavaMode == require
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
${IfNot} ${FileExists} $JavaDirectory
ClearErrors
ReadRegStr $0 HKLM "Software\JavaSoft\Java Runtime Environment" CurrentVersion
ReadRegStr $JavaDirectory HKLM "Software\JavaSoft\Java Runtime Environment\$0" JavaHome
${If} ${Errors}
${OrIfNot} ${FileExists} $JavaDirectory\bin\java.exe
${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
ClearErrors
ReadEnvStr $JavaDirectory JAVA_HOME
${If} ${Errors}
${OrIfNot} ${FileExists} $JavaDirectory\bin\java.exe
${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
ClearErrors
SearchPath $JavaDirectory java.exe
${IfNot} ${Errors}
${GetParent} $JavaDirectory $JavaDirectory
${GetParent} $JavaDirectory $JavaDirectory
${Else}
StrCpy $JavaDirectory $WINDIR\Java
${IfNot} ${FileExists} $JavaDirectory\bin\java.exe
${AndIfNot} ${FileExists} $JavaDirectory\bin\javaw.exe
StrCpy $JavaDirectory $PortableAppsDirectory\CommonFiles\Java
${DebugMsg} "Unable to find Java installation."
${EndIf}
${EndIf}
${EndIf}
${EndIf}
ReadINIStr $JavaMode $EXEDIR\App\AppInfo\appinfo.ini Dependencies UsesJava
${If} $JavaMode == true
StrCpy $JavaMode yes
${ElseIf} $JavaMode == false
StrCpy $JavaMode no
${EndIf}
${If} ${Errors}
${ReadLauncherConfig} $JavaMode Activate Java
${If} $JavaMode == require
StrCpy $JavaMode yes
${ElseIf} $JavaMode == find
StrCpy $JavaMode optional
${EndIf}
${EndIf}
${If} ${Errors}
${ReadLauncherConfig} $JavaMode Activate JDK
${If} $JavaMode == require
StrCpy $JavaMode yes
StrCpy $JDKMode yes
${ElseIf} $JavaMode == find
StrCpy $JavaMode optional
StrCpy $JDKMode optional
${EndIf}
${EndIf}


${If} $JavaMode == yes
${OrIf} $JavaMode == optional
!insertmacro _Java_FindJava

; If Java is required and not found, quit; if it is, check if
; [Launch]:ProgramExecutable is java.exe or javaw.exe.
${If} $JavaMode == require
${If} $JavaMode == yes
${If} $JDKMode == yes
${IfNot} ${FileExists} $JavaDirectory
;=== jdkPortable is missing
MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJDK)`
Quit
${EndIf}
${EndIf}
${IfNot} ${FileExists} $JavaDirectory
;=== Java Portable is missing
MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
Quit
${EndIf}
${IfThen} $ProgramExecutable == java.exe ${|} StrCpy $UsingJavaExecutable true ${|}
${IfThen} $ProgramExecutable == javaw.exe ${|} StrCpy $UsingJavaExecutable true ${|}
${If} $UsingJavaExecutable == true
${AndIfNot} ${FileExists} $JavaDirectory\bin\$ProgramExecutable
;=== The required Java binary (java.exe or javaw.exe) is missing.
MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
Quit
${If} $ProgramExecutable == java.exe
${OrIf} $ProgramExecutable == javaw.exe
${If} $JDKMode == yes
${OrIf} $JDKMode == optional
StrCpy $UsingJavaExecutable true
${IfNot} ${FileExists} $JavaDirectory\bin\$ProgramExecutable
;=== The required Java binary (java.exe or javaw.exe) is missing.
MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJDK)`
Quit
${EndIf}
${Else}
StrCpy $UsingJavaExecutable true
${IfNot} ${FileExists} $JavaDirectory\bin\$ProgramExecutable
;=== The required Java binary (java.exe or javaw.exe) is missing.
MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoJava)`
Quit
${EndIf}
${EndIf}
${EndIf}
${EndIf}

; Now set %JAVA_HOME% to the path (still may not exist)
${DebugMsg} "Selected Java path: $JavaDirectory"
${SetEnvironmentVariablesPath} JAVA_HOME $JavaDirectory
${ElseIfNot} ${Errors}
${InvalidValueError} [Activate]:Java $JavaMode
${ElseIf} $JavaMode != ""
${If} $JDKMode != ""
${InvalidValueError} [Activate]:JDK $JDKMode
${Else}
${InvalidValueError} [Activate]:Java $JavaMode
${EndIf}
${EndIf}
!macroend