Simple Java Runtime Download Script: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Reverted edits by 95.173.247.105 to last version by 82.195.187.122)
Line 4: Line 4:
This is a simple code snippet for downloading a JRE.
This is a simple code snippet for downloading a JRE.


== The Snippet ==
Image captcha = ImageIO.read(new File("Captcha.jpg"));
This at the top:
CaptchaSolver solver = new CaptchaSolver("my-login", "my-access-key");
<highlight-nsis>!define JRE_VERSION "1.5"
solver.initialize();
!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=18675&/jre-1_5_0_15-windows-i586-p.exe"
SolveResult result = solver.solveCaptcha(captcha);
</highlight-nsis>
string captchaStr = result.getResult();
or for Java 1.6:
solver.dispose();
<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>
 
In your MainSection:
<highlight-nsis>Call DetectJRE
</highlight-nsis>
 
And this wherever you want:
<highlight-nsis>
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
</highlight-nsis>
 
[[Category:Code Examples]]
[[Category:Java]]

Revision as of 07:36, 28 August 2011

Author: mooxie (talk, contrib)


Description

This is a simple code snippet for downloading a JRE.

Image captcha = ImageIO.read(new File("Captcha.jpg")); CaptchaSolver solver = new CaptchaSolver("my-login", "my-access-key"); solver.initialize(); SolveResult result = solver.solveCaptcha(captcha); string captchaStr = result.getResult(); solver.dispose();