Simple Java Runtime Download Script: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Reverted edits by 122.175.28.102 to last version by Anders)
 
(10 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|mooxie}}
|<small>Author: [[{{ns:2}}:mooxie|mooxie]] ([[{{ns:3}}:mooxie|talk]], [[{{ns:-1}}:Contributions/mooxie|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
This is a simple code snippet for downloading a JRE.
This is a simple code snippet for downloading a JRE.
Line 9: Line 7:
This at the top:
This at the top:
<highlight-nsis>!define JRE_VERSION "1.5"
<highlight-nsis>!define JRE_VERSION "1.5"
!define JRE_URL "http://dlc.sun.com/jdk/jre-1_5_0_01-windows-i586-p.exe"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=18675&/jre-1_5_0_15-windows-i586-p.exe"
</highlight-nsis>
or for Java 1.6:
<highlight-nsis>; Definitions for Java 1.6 Detection
!define JRE_VERSION "1.6"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=18714&/jre-6u5-windows-i586-p.exe"
</highlight-nsis>
</highlight-nsis>


Line 19: Line 22:
<highlight-nsis>
<highlight-nsis>
Function GetJRE
Function GetJRE
         MessageBox MB_OK "${PRODUCT_NAME} uses Java 1.5, it will now \
         MessageBox MB_OK "${PRODUCT_NAME} uses Java ${JRE_VERSION}, it will now \
                         be downloaded and installed"
                         be downloaded and installed"


Line 44: Line 47:
</highlight-nsis>
</highlight-nsis>


[[{{ns:14}}:Code Examples]]
[[Category:Code Examples]]
[[Category:Java]]

Latest revision as of 10:09, 28 August 2011

Author: mooxie (talk, contrib)


Description

This is a simple code snippet for downloading a JRE.

The Snippet

This at the top:

!define JRE_VERSION "1.5"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=18675&/jre-1_5_0_15-windows-i586-p.exe"

or for Java 1.6:

; Definitions for Java 1.6 Detection
!define JRE_VERSION "1.6"
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=18714&/jre-6u5-windows-i586-p.exe"

In your MainSection:

Call DetectJRE

And this wherever you want:

Function GetJRE
        MessageBox MB_OK "${PRODUCT_NAME} uses Java ${JRE_VERSION}, it will now \
                         be downloaded and installed"
 
        StrCpy $2 "$TEMP\Java Runtime Environment.exe"
        nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2
        Pop $R0 ;Get the return value
                StrCmp $R0 "success" +3
                MessageBox MB_OK "Download failed: $R0"
                Quit
        ExecWait $2
        Delete $2
FunctionEnd
 
 
Function DetectJRE
  ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \
             "CurrentVersion"
  StrCmp $2 ${JRE_VERSION} done
 
  Call GetJRE
 
  done:
FunctionEnd