windows installer: Create file associations for Windows.
[fw/altos] / telegps / telegps-windows.nsi.in
1 !addplugindir ../altosui/Instdrv/NSIS/Plugins
2 !addincludedir ../altosui/Instdrv/NSIS/Includes
3 !include x64.nsh
4 !include java.nsh
5 !include refresh-sh.nsh
6
7 !define REG_NAME "TeleGPS"
8 !define PROG_ID "org.altusmetrum.telegps.1"
9 !define PROG_ALTOSUI "org.altusmetrum.altosui.1"
10 !define FAT_NAME "telegps-fat.jar"
11 !define ICO_ICO "telegps.ico"
12 !define ICO_EXE "telegps.exe"
13
14 Name "${REG_NAME} Installer"
15
16 ; Default install directory
17 InstallDir "$PROGRAMFILES\AltusMetrum"
18
19 ; Tell the installer where to re-install a new version
20 InstallDirRegKey HKLM "Software\${REG_NAME}" "Install_Dir"
21
22 LicenseText "GNU General Public License Version 2"
23 LicenseData "../COPYING"
24
25 ; Need admin privs for Vista or Win7
26 RequestExecutionLevel admin
27
28 ShowInstDetails Show
29
30 ComponentText "${REG_NAME} Software and Driver Installer"
31
32 Function .onInit
33         DetailPrint "Checking host operating system"
34         ${If} ${RunningX64}
35                 DetailPrint "Installer running on 64-bit host"
36                 SetRegView 64
37                 StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
38                 ${DisableX64FSRedirection}
39         ${EndIf}
40 FunctionEnd
41
42 Function un.onInit
43         DetailPrint "Checking host operating system"
44         ${If} ${RunningX64}
45                 DetailPrint "Installer running on 64-bit host"
46                 SetRegView 64
47                 StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
48                 ${DisableX64FSRedirection}
49         ${EndIf}
50 FunctionEnd
51
52 ; Pages to present
53
54 Page license
55 Page components
56 Page directory
57 Page instfiles
58
59 UninstPage uninstConfirm
60 UninstPage instfiles
61
62 ; And the stuff to install
63
64 Section "Install Driver" InstDriver
65
66         InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} AltusMetrumSerial
67         Pop $0
68         DetailPrint "InitDriverSetup: $0"
69         InstDrv::DeleteOemInfFiles /NOUNLOAD
70         InstDrv::CreateDevice /NOUNLOAD
71
72         SetOutPath $INSTDIR
73         File "../altusmetrum.inf"
74         File "../altusmetrum.cat"
75
76         ${DisableX64FSRedirection}
77         IfFileExists $WINDIR\System32\PnPutil.exe 0 nopnp
78                 ${DisableX64FSRedirection}
79                 nsExec::ExecToLog '"$WINDIR\System32\PnPutil.exe" -i -a "$INSTDIR\altusmetrum.inf"'
80                 Goto done
81 nopnp:
82                 InstDrv::InstallDriver /NOUNLOAD "$INSTDIR\altusmetrum.inf"
83 done:
84
85 SectionEnd
86
87 Section "${REG_NAME} Application"
88         Call DetectJRE
89
90         SetOutPath $INSTDIR
91
92         File "${FAT_NAME}"
93         File "altoslib_@ALTOSLIB_VERSION@.jar"
94         File "altosuilib_@ALTOSUILIB_VERSION@.jar"
95         File "cmudict04.jar"
96         File "cmulex.jar"
97         File "cmu_time_awb.jar"
98         File "cmutimelex.jar"
99         File "cmu_us_kal.jar"
100         File "en_us.jar"
101         File "freetts.jar"
102         File "jfreechart.jar"
103         File "jcommon.jar"
104
105         File "*.dll"
106
107         File "../icon/${ICO_ICO}"
108
109         CreateShortCut "$SMPROGRAMS\${REG_NAME}.lnk" "$SYSDIR\javaw.exe" "-jar ${FAT_NAME}" "$INSTDIR\${ICO_ICO}"
110 SectionEnd
111
112 Section "${REG_NAME} Desktop Shortcut"
113         CreateShortCut "$DESKTOP\${REG_NAME}.lnk" "$INSTDIR\${FAT_NAME}"  "" "$INSTDIR\${ICO_ICO}"
114 SectionEnd
115
116 Section "TeleGPS, TeleDongle and TeleBT Firmware"
117
118         SetOutPath $INSTDIR
119
120         File "../src/telegps-v1.0/telegps-v1.0-${VERSION}.ihx"
121         File "../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx"
122         File "../src/telebt-v1.0/telebt-v1.0-${VERSION}.ihx"
123
124 SectionEnd
125
126 Section "Documentation"
127
128         SetOutPath $INSTDIR
129
130         File "../doc/telegps.pdf"
131         File "../doc/altos.pdf"
132         File "../doc/telemetry.pdf"
133 SectionEnd
134
135 Section "File Associations"
136
137         SetOutPath $INSTDIR
138
139         File "../icon/${ICO_EXE}"
140
141         ; application elements
142         
143         WriteRegStr HKCR "${PROG_ID}"                   ""                              "Altus Metrum Data File"
144         WriteRegStr HKCR "${PROG_ID}"                   "FriendlyTypeName"              "Altus Metrum Data File"
145         WriteRegStr HKCR "${PROG_ID}\CurVer"            ""                              "${PROG_ID}"
146         WriteRegStr HKCR "${PROG_ID}\DefaultIcon"       ""                              '"$INSTDIR\${ICO_EXE}",-101'
147   WriteRegExpandStr HKCR "${PROG_ID}\shell\play\command" ""                             '"%SYSTEMROOT%\System32\javaw.exe" -Djava.library.path="$INSTDIR" -jar "$INSTDIR\${FAT_NAME}" "%1"'
148
149         ; .eeprom elements
150
151         WriteRegStr HKCR ".eeprom"                      ""                              "${PROG_ALTOSUI}"
152         WriteRegStr HKCR ".eeprom"                      "PerceivedType"                 "Altus Metrum Log File"
153         WriteRegStr HKCR ".eeprom"                      "Content Type"                  "application/altosui"
154
155         WriteRegStr HKCR ".eeprom\OpenWithProgids"      "${PROG_ID}"                    ""
156         WriteRegStr HKCR ".eeprom\${PROG_ID}"           ""                              "${REG_NAME}"
157         
158         ; .telem elements
159         
160         WriteRegStr HKCR ".telem"                       ""                              "${PROG_ALTOSUI}"
161         WriteRegStr HKCR ".telem"                       "PerceivedType"                 "Altus Metrum Telemetry File"
162         WriteRegStr HKCR ".telem"                       "Content Type"                  "application/altosui"
163
164         WriteRegStr HKCR ".telem\OpenWithProgids"       "${PROG_ID}"                    ""
165         WriteRegStr HKCR ".telem\${PROG_ID}"            ""                              "${REG_NAME}"
166
167         Call RefreshShellIcons
168 SectionEnd
169         
170 Section "Uninstaller"
171
172         ; Deal with the uninstaller
173
174         ${DisableX64FSRedirection}
175         SetOutPath $INSTDIR
176
177         ; Write the install path to the registry
178         WriteRegStr HKLM "SOFTWARE\${REG_NAME}" "Install_Dir" "$INSTDIR"
179
180         ; Write the uninstall keys for windows
181         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "DisplayName" "${REG_NAME}"
182         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "UninstallString" '"$INSTDIR\uninstall-${REG_NAME}.exe"'
183         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoModify" "1"
184         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoRepair" "1"
185
186         WriteUninstaller "uninstall-${REG_NAME}.exe"
187 SectionEnd
188
189 Section "Uninstall"
190
191         ${DisableX64FSRedirection}
192
193         DeleteRegKey   HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}"
194         DeleteRegKey   HKLM "SOFTWARE\${REG_NAME}"
195
196         DetailPrint "Delete uninstall reg entries"
197
198         DeleteRegKey   HKCR "${PROG_ID}"
199
200         DeleteRegKey   HKCR ".eeprom\${PROG_ID}"
201         DeleteRegValue HKCR ".eeprom\OpenWithProgids" "${PROG_ID}"
202
203         DeleteRegKey   HKCR ".telem\${PROG_ID}"
204         DeleteRegValue HKCR ".telem\OpenWithProgids" "${PROG_ID}"
205
206         DetailPrint "Delete file association reg entries"
207
208         Delete "$INSTDIR\${FAT_NAME}"
209         Delete "$INSTDIR\uninstall-${REG_NAME}.exe"
210
211         Delete "$INSTDIR\${ICO_ICO}"
212         Delete "$INSTDIR\${ICO_EXE}"
213
214         ; Remove shortcuts, if any
215         Delete "$SMPROGRAMS\${REG_NAME}.lnk"
216         Delete "$DESKTOP\${REG_NAME}.lnk"
217         
218         Call un.RefreshShellIcons
219 SectionEnd