micropeak: Deal with 64-bit windows
[fw/altos] / micropeak / micropeak-windows.nsi.in
1 !addplugindir Instdrv/NSIS/Plugins
2 !include x64.nsh
3 ; Definitions for Java 1.7 Detection
4 !define JRE_VERSION "1.7"
5 !define JRE_ALTERNATE "1.6"
6 !define JRE32_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=83383&/jre-7u51-windows-i586.exe"
7 !define JRE64_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=83385&/jre-7u51-windows-x64.exe"
8 !define PRODUCT_NAME "Altus Metrum Windows Software"
9
10 Name "Altus Metrum MicroPeak Installer"
11
12 ; Default install directory
13 InstallDir "$PROGRAMFILES\AltusMetrum"
14
15 ; Tell the installer where to re-install a new version
16 InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir"
17
18 LicenseText "GNU General Public License Version 2"
19 LicenseData "../COPYING"
20
21 ; Need admin privs for Vista or Win7
22 RequestExecutionLevel admin
23
24 ShowInstDetails Show
25
26 ComponentText "Altus Metrum MicroPeak Software Installer"
27
28 Function .onInit
29         DetailPrint "Checking host operating system"
30         ${If} ${RunningX64}
31                 DetailPrint "Installer running on 64-bit host"
32                 SetRegView 64
33                 StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
34                 ${DisableX64FSRedirection}
35         ${EndIf}
36 FunctionEnd
37
38 Var JavaDownload
39 Var JavaBits
40
41 Function GetJRE
42         ${If} ${RunningX64}
43            StrCpy $JavaDownload ${JRE64_URL}
44            StrCpy $JavaBits "64"
45         ${Else}
46            StrCpy $JavaDownload ${JRE32_URL}
47            StrCpy $JavaBits "32"
48         ${EndIf}
49
50         MessageBox MB_OK "${PRODUCT_NAME} uses Java ${JRE_VERSION}, \
51                         $JavaBits bits, it will now \
52                         be downloaded and installed"
53
54         StrCpy $2 "$TEMP\Java Runtime Environment.exe"
55         nsisdl::download /TIMEOUT=30000 $JavaDownload $2
56         Pop $R0 ;Get the return value
57                 StrCmp $R0 "success" +3
58                 MessageBox MB_OK "Download failed: $R0"
59                 Quit
60         ExecWait $2
61         Delete $2
62 FunctionEnd
63
64 Function DetectJRE
65   ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \
66              "CurrentVersion"
67   StrCmp $2 ${JRE_VERSION} done
68
69   StrCmp $2 ${JRE_ALTERNATE} done
70
71   Call GetJRE
72
73   done:
74 FunctionEnd
75
76 ; Pages to present
77
78 Page license
79 Page components
80 Page directory
81 Page instfiles
82
83 UninstPage uninstConfirm
84 UninstPage instfiles
85
86 ; And the stuff to install
87
88 Section "MicroPeak Application"
89         Call DetectJRE
90
91         SetOutPath $INSTDIR
92
93         File "micropeak-fat.jar"
94         File "altoslib_@ALTOSLIB_VERSION@.jar"
95         File "altosuilib_@ALTOSUILIB_VERSION@.jar"
96         File "jfreechart.jar"
97         File "jcommon.jar"
98
99         File "*.dll"
100
101         File "../icon/*.ico"
102
103         CreateShortCut "$SMPROGRAMS\MicroPeak.lnk" "$SYSDIR\javaw.exe" "-jar micropeak-fat.jar" "$INSTDIR\micro-peak.ico"
104 SectionEnd
105
106 Section "FTDI USB Driver"
107         SetOutPath $INSTDIR
108
109         File "CDM20824_Setup.exe"
110
111         StrCpy $2 "$INSTDIR\CDM20824_Setup.exe"
112         ExecWait $2
113 SectionEnd
114
115 Section "MicroPeak Desktop Shortcut"
116         CreateShortCut "$DESKTOP\MicroPeak.lnk" "$INSTDIR\micropeak-fat.jar"  "" "$INSTDIR\micro-peak.ico"
117 SectionEnd
118
119 Section "Documentation"
120
121         SetOutPath $INSTDIR
122
123         File "../doc/micropeak.pdf"
124 SectionEnd
125
126 Section "Uninstaller"
127
128         ; Deal with the uninstaller
129
130         SetOutPath $INSTDIR
131
132         ; Write the install path to the registry
133         WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR"
134
135         ; Write the uninstall keys for windows
136         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum"
137         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"'
138         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1"
139         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1"
140
141         WriteUninstaller "uninstall.exe"
142 SectionEnd
143
144 Section "Uninstall"
145         DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum"
146         DeleteRegKey HKLM "Software\AltusMetrum"
147
148         Delete "$INSTDIR\*.*"
149         RMDir "$INSTDIR"
150
151         ; Remove shortcuts, if any
152         Delete "$SMPROGRAMS\MicroPeak.lnk"
153         Delete "$DESKTOP\MicroPeak.lnk"
154         
155 SectionEnd