windows installer: Create file associations for Windows.
[fw/altos] / micropeak / micropeak-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 "MicroPeak"
8 !define PROG_ID "org.altusmetrum.micropeak.1"
9 !define FAT_NAME "micropeak-fat.jar"
10 !define ICO_ICO "micro-peak.ico"
11 !define ICO_EXE "micro-peak.exe"
12
13 Name "${REG_NAME} Installer"
14
15 ; Default install directory
16 InstallDir "$PROGRAMFILES\AltusMetrum"
17
18 ; Tell the installer where to re-install a new version
19 InstallDirRegKey HKLM "Software\${REG_NAME}" "Install_Dir"
20
21 LicenseText "GNU General Public License Version 2"
22 LicenseData "../COPYING"
23
24 ; Need admin privs for Vista or Win7
25 RequestExecutionLevel admin
26
27 ShowInstDetails Show
28
29 ComponentText "${REG_NAME} Software and Driver Installer"
30
31 Function .onInit
32         DetailPrint "Checking host operating system"
33         ${If} ${RunningX64}
34                 DetailPrint "Installer running on 64-bit host"
35                 SetRegView 64
36                 StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
37                 ${DisableX64FSRedirection}
38         ${EndIf}
39 FunctionEnd
40
41 Function un.onInit
42         DetailPrint "Checking host operating system"
43         ${If} ${RunningX64}
44                 DetailPrint "Installer running on 64-bit host"
45                 SetRegView 64
46                 StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
47                 ${DisableX64FSRedirection}
48         ${EndIf}
49 FunctionEnd
50
51 ; Pages to present
52
53 Page license
54 Page components
55 Page directory
56 Page instfiles
57
58 UninstPage uninstConfirm
59 UninstPage instfiles
60
61 ; And the stuff to install
62
63 Section "FTDI USB Driver"
64         SetOutPath $INSTDIR
65
66         File "CDM20824_Setup.exe"
67
68         StrCpy $2 "$INSTDIR\CDM20824_Setup.exe"
69         ExecWait $2
70 SectionEnd
71
72 Section "${REG_NAME} Application"
73         Call DetectJRE
74
75         SetOutPath $INSTDIR
76
77         File "${FAT_NAME}"
78         File "altoslib_@ALTOSLIB_VERSION@.jar"
79         File "altosuilib_@ALTOSUILIB_VERSION@.jar"
80         File "jfreechart.jar"
81         File "jcommon.jar"
82
83         File "*.dll"
84
85         File "../icon/${ICO_ICO}"
86
87         CreateShortCut "$SMPROGRAMS\${REG_NAME}.lnk" "$SYSDIR\javaw.exe" "-jar ${FAT_NAME}" "$INSTDIR\${ICO_ICO}"
88 SectionEnd
89
90 Section "${REG_NAME} Desktop Shortcut"
91         CreateShortCut "$DESKTOP\${REG_NAME}.lnk" "$INSTDIR\${FAT_NAME}"  "" "$INSTDIR\${ICO_ICO}"
92 SectionEnd
93
94 Section "Documentation"
95
96         SetOutPath $INSTDIR
97
98         File "../doc/micropeak.pdf"
99 SectionEnd
100
101 Section "File Associations"
102
103         SetOutPath $INSTDIR
104
105         File "../icon/${ICO_EXE}"
106
107         ; application elements
108         
109         WriteRegStr HKCR "${PROG_ID}"                   ""                              "MicroPeak Data File"
110         WriteRegStr HKCR "${PROG_ID}"                   "FriendlyTypeName"              "MicroPeak Data File"
111         WriteRegStr HKCR "${PROG_ID}\CurVer"            ""                              "${PROG_ID}"
112         WriteRegStr HKCR "${PROG_ID}\DefaultIcon"       ""                              '"$INSTDIR\${ICO_EXE}",-101'
113   WriteRegExpandStr HKCR "${PROG_ID}\shell\play\command" ""                             '"%SYSTEMROOT%\System32\javaw.exe" -Djava.library.path="$INSTDIR" -jar "$INSTDIR\${FAT_NAME}" "%1"'
114
115         ; .mpd elements
116
117         WriteRegStr HKCR ".mpd"                         ""                              "${PROG_ID}"
118         WriteRegStr HKCR ".mpd"                         "PerceivedType"                 "MicroPeak Data File"
119         WriteRegStr HKCR ".mpd"                         "Content Type"                  "application/micropeak"
120
121         WriteRegStr HKCR ".mpd\OpenWithProgids"         "${PROG_ID}"                    ""
122         WriteRegStr HKCR ".mpd\${PROG_ID}"              ""                              "${REG_NAME}"
123
124         Call RefreshShellIcons
125 SectionEnd
126         
127 Section "Uninstaller"
128
129         ; Deal with the uninstaller
130
131         ${DisableX64FSRedirection}
132         SetOutPath $INSTDIR
133
134         ; Write the install path to the registry
135         WriteRegStr HKLM "SOFTWARE\${REG_NAME}" "Install_Dir" "$INSTDIR"
136
137         ; Write the uninstall keys for windows
138         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "DisplayName" "${REG_NAME}"
139         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "UninstallString" '"$INSTDIR\uninstall-${REG_NAME}.exe"'
140         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoModify" "1"
141         WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoRepair" "1"
142
143         WriteUninstaller "uninstall-${REG_NAME}.exe"
144 SectionEnd
145
146 Section "Uninstall"
147
148         ${DisableX64FSRedirection}
149
150         DeleteRegKey   HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}"
151         DeleteRegKey   HKLM "SOFTWARE\${REG_NAME}"
152
153         DetailPrint "Delete uninstall reg entries"
154
155         DeleteRegKey   HKCR "${PROG_ID}"
156
157         DeleteRegKey   HKCR ".mpd\${PROG_ID}"
158         DeleteRegValue HKCR ".mpd\OpenWithProgids" "${PROG_ID}"
159
160         Delete "$INSTDIR\${FAT_NAME}"
161         Delete "$INSTDIR\uninstall-${REG_NAME}.exe"
162
163         Delete "$INSTDIR\${ICO_ICO}"
164         Delete "$INSTDIR\${ICO_EXE}"
165
166         ; Remove shortcuts, if any
167         Delete "$SMPROGRAMS\${REG_NAME}.lnk"
168         Delete "$DESKTOP\${REG_NAME}.lnk"
169         
170         Call un.RefreshShellIcons
171 SectionEnd