windows installer: Create file associations for Windows.
[fw/altos] / altosui / altos-windows.nsi.in
index ab5ac4530ecf8ee9493f904d53ac317998e9d287..da36ad90bc7c683fb05b5e16e03ccbee7245a00c 100644 (file)
@@ -2,16 +2,22 @@
 !addincludedir Instdrv/NSIS/Includes
 !include x64.nsh
 !include java.nsh
+!include refresh-sh.nsh
 
-!define PRODUCT_NAME "Altus Metrum Windows Software"
+!define REG_NAME "Altus Metrum"
+!define PROG_ID             "org.altusmetrum.altosui.1"
+!define PROG_ALTOSUI "org.altusmetrum.altosui.1"
+!define FAT_NAME "altosui-fat.jar"
+!define ICO_ICO "altus-metrum.ico"
+!define ICO_EXE "altus-metrum.exe"
 
-Name "Altus Metrum Installer"
+Name "${REG_NAME} Installer"
 
 ; Default install directory
 InstallDir "$PROGRAMFILES\AltusMetrum"
 
 ; Tell the installer where to re-install a new version
-InstallDirRegKey HKLM "Software\AltusMetrum" "Install_Dir"
+InstallDirRegKey HKLM "Software\${REG_NAME}" "Install_Dir"
 
 LicenseText "GNU General Public License Version 2"
 LicenseData "../COPYING"
@@ -21,7 +27,7 @@ RequestExecutionLevel admin
 
 ShowInstDetails Show
 
-ComponentText "Altus Metrum Software and Driver Installer"
+ComponentText "${REG_NAME} Software and Driver Installer"
 
 Function .onInit
        DetailPrint "Checking host operating system"
@@ -33,6 +39,16 @@ Function .onInit
        ${EndIf}
 FunctionEnd
 
+Function un.onInit
+       DetailPrint "Checking host operating system"
+       ${If} ${RunningX64}
+               DetailPrint "Installer running on 64-bit host"
+               SetRegView 64
+               StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
+               ${DisableX64FSRedirection}
+       ${EndIf}
+FunctionEnd
+
 ; Pages to present
 
 Page license
@@ -68,12 +84,12 @@ done:
 
 SectionEnd
 
-Section "AltosUI Application"
+Section "${REG_NAME} Application"
        Call DetectJRE
 
        SetOutPath $INSTDIR
 
-       File "altosui-fat.jar"
+       File "${FAT_NAME}"
        File "altoslib_@ALTOSLIB_VERSION@.jar"
        File "altosuilib_@ALTOSUILIB_VERSION@.jar"
        File "cmudict04.jar"
@@ -88,13 +104,13 @@ Section "AltosUI Application"
 
        File "*.dll"
 
-       File "../icon/*.ico"
+       File "../icon/${ICO_ICO}"
 
-       CreateShortCut "$SMPROGRAMS\AltusMetrum.lnk" "$SYSDIR\javaw.exe" "-jar altosui-fat.jar" "$INSTDIR\altus-metrum.ico"
+       CreateShortCut "$SMPROGRAMS\${REG_NAME}.lnk" "$SYSDIR\javaw.exe" "-jar ${FAT_NAME}" "$INSTDIR\${ICO_ICO}"
 SectionEnd
 
-Section "AltosUI Desktop Shortcut"
-       CreateShortCut "$DESKTOP\AltusMetrum.lnk" "$INSTDIR\altosui-fat.jar"  "" "$INSTDIR\altus-metrum.ico"
+Section "${REG_NAME} Desktop Shortcut"
+       CreateShortCut "$DESKTOP\${REG_NAME}.lnk" "$INSTDIR\${FAT_NAME}"  "" "$INSTDIR\${ICO_ICO}"
 SectionEnd
 
 Section "TeleMetrum, TeleDongle and TeleBT Firmware"
@@ -126,38 +142,88 @@ Section "Documentation"
        File "../doc/telemini.pdf"
 SectionEnd
 
+Section "File Associations"
+
+       SetOutPath $INSTDIR
+
+       File "../icon/${ICO_EXE}"
+
+       ; application elements
+       
+       WriteRegStr HKCR "${PROG_ID}"                   ""                              "Altus Metrum Data File"
+       WriteRegStr HKCR "${PROG_ID}"                   "FriendlyTypeName"              "Altus Metrum Data File"
+       WriteRegStr HKCR "${PROG_ID}\CurVer"            ""                              "${PROG_ID}"
+       WriteRegStr HKCR "${PROG_ID}\DefaultIcon"       ""                              '"$INSTDIR\${ICO_EXE}",-101'
+  WriteRegExpandStr HKCR "${PROG_ID}\shell\play\command" ""                            '"%SYSTEMROOT%\System32\javaw.exe" -Djava.library.path="$INSTDIR" -jar "$INSTDIR\${FAT_NAME}" "%1"'
+
+       ; .eeprom elements
+
+       WriteRegStr HKCR ".eeprom"                      ""                              "${PROG_ALTOSUI}"
+       WriteRegStr HKCR ".eeprom"                      "PerceivedType"                 "Altus Metrum Log File"
+       WriteRegStr HKCR ".eeprom"                      "Content Type"                  "application/altosui"
+
+       WriteRegStr HKCR ".eeprom\OpenWithProgids"      "${PROG_ID}"                    ""
+       WriteRegStr HKCR ".eeprom\${PROG_ID}"           ""                              "${REG_NAME}"
+       
+       ; .telem elements
+       
+       WriteRegStr HKCR ".telem"                       ""                              "${PROG_ALTOSUI}"
+       WriteRegStr HKCR ".telem"                       "PerceivedType"                 "Altus Metrum Telemetry File"
+       WriteRegStr HKCR ".telem"                       "Content Type"                  "application/altosui"
+
+       WriteRegStr HKCR ".telem\OpenWithProgids"       "${PROG_ID}"                    ""
+       WriteRegStr HKCR ".telem\${PROG_ID}"            ""                              "${REG_NAME}"
+
+       Call RefreshShellIcons
+SectionEnd
+       
 Section "Uninstaller"
 
        ; Deal with the uninstaller
 
+       ${DisableX64FSRedirection}
        SetOutPath $INSTDIR
 
        ; Write the install path to the registry
-       WriteRegStr HKLM SOFTWARE\AltusMetrum "Install_Dir" "$INSTDIR"
+       WriteRegStr HKLM "SOFTWARE\${REG_NAME}" "Install_Dir" "$INSTDIR"
 
        ; Write the uninstall keys for windows
-       WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "DisplayName" "Altus Metrum"
-       WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "UninstallString" '"$INSTDIR\uninstall.exe"'
-       WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoModify" "1"
-       WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum" "NoRepair" "1"
+       WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "DisplayName" "${REG_NAME}"
+       WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "UninstallString" '"$INSTDIR\uninstall-${REG_NAME}.exe"'
+       WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoModify" "1"
+       WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}" "NoRepair" "1"
 
-       WriteUninstaller "uninstall.exe"
+       WriteUninstaller "uninstall-${REG_NAME}.exe"
 SectionEnd
 
 Section "Uninstall"
-       DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AltusMetrum"
-       DeleteRegKey HKLM "Software\AltusMetrum"
 
-       Delete "$INSTDIR\*.*"
-       RMDir "$INSTDIR"
+       ${DisableX64FSRedirection}
 
-       ; Remove devices
-       InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} AltusMetrumSerial
-       InstDrv::DeleteOemInfFiles /NOUNLOAD
-       InstDrv::RemoveAllDevices
+       DeleteRegKey   HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}"
+       DeleteRegKey   HKLM "SOFTWARE\${REG_NAME}"
+
+       DetailPrint "Delete uninstall reg entries"
+
+       DeleteRegKey   HKCR "${PROG_ID}"
+
+       DeleteRegKey   HKCR ".eeprom\${PROG_ID}"
+       DeleteRegValue HKCR ".eeprom\OpenWithProgids" "${PROG_ID}"
+
+       DeleteRegKey   HKCR ".telem\${PROG_ID}"
+       DeleteRegValue HKCR ".telem\OpenWithProgids" "${PROG_ID}"
+
+       DetailPrint "Delete file association reg entries"
+
+       Delete "$INSTDIR\${FAT_NAME}"
+       Delete "$INSTDIR\uninstall-${REG_NAME}.exe"
+
+       Delete "$INSTDIR\${ICO_ICO}"
+       Delete "$INSTDIR\${ICO_EXE}"
 
        ; Remove shortcuts, if any
-       Delete "$SMPROGRAMS\AltusMetrum.lnk"
-       Delete "$DESKTOP\AltusMetrum.lnk"
+       Delete "$SMPROGRAMS\${REG_NAME}.lnk"
+       Delete "$DESKTOP\${REG_NAME}.lnk"
        
+       Call un.RefreshShellIcons
 SectionEnd