first commit with new 2.2 release
[debian/jabref.git] / src / windows / nsis / launcher.nsi
1 ;
2 ; JabRef Application launcher
3 ;
4 ; Script based upon:
5 ; Jelude launcher - http://www.sfu.ca/~tyuen/jelude/ 
6 ; Java Launcher http://nsis.sourceforge.net/archive/nsisweb.php?page=326&instances=0,64
7 ;
8 ; Christopher Oezbek - oezi@oezi.de - 2006
9
10 ;--------- CONFIGURATION ---------
11 !define APPNAME "JabRef"
12 !ifndef JARFILE
13     !define JARFILE "JabRef.jar"
14 !endif
15 !ifdef APPICON
16     Icon "${APPICON}"
17 !endif
18 Name "${APPNAME}"
19 Caption "${APPNAME}"
20 OutFile "dist\${APPNAME}.exe"
21 ;-------- END CONFIGURATION ------
22
23 SilentInstall silent
24 XPStyle on
25
26 Section ""
27
28   Call GetJRE
29   Pop $R0
30
31   StrCpy $R1 ""
32   Call GetParameters
33   Pop $R1
34
35   StrCpy $R0 '"$R0" -jar "${JARFILE}" $R1'
36  
37   SetOutPath $EXEDIR
38   Exec "$R0"
39
40   Quit
41 SectionEnd
42
43 Function GetParameters
44   Push $R0
45   Push $R1
46   Push $R2
47   StrCpy $R0 $CMDLINE 1
48   StrCpy $R1 '"'
49   StrCpy $R2 1
50   StrCmp $R0 '"' loop
51   StrCpy $R1 ' '
52   loop:
53     StrCpy $R0 $CMDLINE 1 $R2
54     StrCmp $R0 $R1 loop2
55     StrCmp $R0 "" loop2
56     IntOp $R2 $R2 + 1
57     Goto loop
58   loop2:
59     IntOp $R2 $R2 + 1
60     StrCpy $R0 $CMDLINE 1 $R2
61     StrCmp $R0 " " loop2
62   StrCpy $R0 $CMDLINE "" $R2
63   Pop $R2
64   Pop $R1
65   Exch $R0
66 FunctionEnd
67
68 Function GetJRE
69 ;
70 ;  Find JRE (Java.exe)
71 ;  1 - in .\jre directory (JRE Installed with application)
72 ;  2 - in JAVA_HOME environment variable
73 ;  3 - in the registry
74 ;  4 - assume java.exe in current dir or PATH
75   Push $R0
76   Push $R1
77
78   ClearErrors
79   StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
80   IfFileExists $R0 JreFound
81   StrCpy $R0 ""
82
83   ClearErrors
84   ReadEnvStr $R0 "JAVA_HOME"
85   StrCpy $R0 "$R0\bin\javaw.exe"
86   IfErrors 0 JreFound
87
88   ClearErrors
89   ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
90   ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
91   StrCpy $R0 "$R0\bin\javaw.exe"
92
93   IfErrors 0 JreFound
94   Sleep 800
95   MessageBox MB_ICONEXCLAMATION|MB_YESNO \
96                'Could not find a Java Runtime Environment installed on your computer. \
97                $\nWithout it you cannot run "${APPNAME}". \
98                $\n$\nWould you like to visit the Java website to download it?' \
99                IDNO +2
100   ExecShell open "http://java.sun.com/getjava"
101   Quit
102         
103  JreFound:
104   Pop $R1
105   Exch $R0
106 FunctionEnd