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