Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Add dedicated windows launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Nov 5, 2015
1 parent 66185b2 commit 4c40812
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions ant/windows/windows-launcher.nsi.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
;------------------
; ${socket.name} Launcher
;------------------
; Creates a ${build.socket.name}.exe launcher which performs automatic JRE detection

!include x64.nsh
!include LogicLib.nsh
!addincludedir "${windows.nsis.addons}/Include"
!include StdUtils.nsh

; Run this exe as non-admin
RequestExecutionLevel user

; Application information
Name "${socket.name}"
Caption "${socket.name}"
Icon "${basedir}\${branding.dir}\${windows.icon}"
OutFile "${build.socket.name}.exe"

SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow

; Full path to jar
!define JAR "$INSTDIR\${build.socket.name}.jar"

Section ""
${If} ${RunningX64}
${DisableX64FSRedirection}
${EndIf}
Call FindJRE
Pop $R0

; change for your purpose (-jar etc.)
StrCpy $0 '"$R0" -jar "${JAR}"'

SetOutPath $EXEDIR

Exec $0
${If} ${RunningX64}
${EnableX64FSRedirection}
${EndIf}
SectionEnd

; FindJRE (find "javaw.exe")
; 1 - Search in .\jre directory (e.g. JRE Installed with application)
; 2 - Search in JAVA_HOME environment variable
; 3 - Search in the native registry
; 4 - Search in the 32-bit registry
; 5 - Fall-back to "javaw.exe" (such as in current dir or PATH)
Function FindJRE
Push $R0
Push $R1

ClearErrors
StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
IfFileExists $R0 JreFound
StrCpy $R0 ""

ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound

ClearErrors
ReadRegStr $R1 HKLM "Software\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "Software\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"

IfErrors 0 JreFound
; Fall-back to 32-bit registry
${If} ${RunningX64}
ReadRegStr $R1 HKLM "Software\Wow6432Node\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "Software\Wow6432Node\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"
${EndIf}

StrCpy $R0 "javaw.exe"

JreFound:
Pop $R1
Exch $R0
FunctionEnd

Function .onInit
${If} ${RunningX64}
; Force 64-bit registry view by default
SetRegView 64
; Default to 64-bit Program Files
StrCpy $INSTDIR "$PROGRAMFILES64\${socket.name}"
${EndIf}
FunctionEnd

1 comment on commit 4c40812

@tresf
Copy link
Contributor Author

@tresf tresf commented on 4c40812 Nov 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#94

Please sign in to comment.