windows: Missed adding 'refresh-sh.nsh'
[fw/altos] / altosui / altos-windows.nsi.in
index e50e1447f728990979b4d86d59b152b229426337..c6da097e1701c2cd5095c94b97335160de9127d9 100644 (file)
@@ -1,17 +1,23 @@
 !addplugindir Instdrv/NSIS/Plugins
-; Definitions for Java 1.6 Detection
-!define JRE_VERSION "1.6"
-!define JRE_ALTERNATE "1.7"
-!define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52247&/jre-6u27-windows-i586-p.exe"
-!define PRODUCT_NAME "Altus Metrum Windows Software"
+!addincludedir Instdrv/NSIS/Includes
+!include x64.nsh
+!include java.nsh
+!include refresh-sh.nsh
 
-Name "Altus Metrum Installer"
+!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 "${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,33 +27,26 @@ RequestExecutionLevel admin
 
 ShowInstDetails Show
 
-ComponentText "Altus Metrum Software and Driver Installer"
-
-Function GetJRE
-        MessageBox MB_OK "${PRODUCT_NAME} uses Java ${JRE_VERSION} 32-bit, it will now \
-                         be downloaded and installed"
+ComponentText "${REG_NAME} Software and Driver Installer"
 
-        StrCpy $2 "$TEMP\Java Runtime Environment.exe"
-        nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2
-        Pop $R0 ;Get the return value
-                StrCmp $R0 "success" +3
-                MessageBox MB_OK "Download failed: $R0"
-                Quit
-        ExecWait $2
-        Delete $2
+Function .onInit
+       DetailPrint "Checking host operating system"
+       ${If} ${RunningX64}
+               DetailPrint "Installer running on 64-bit host"
+               SetRegView 64
+               StrCpy $INSTDIR "$PROGRAMFILES64\AltusMetrum"
+               ${DisableX64FSRedirection}
+       ${EndIf}
 FunctionEnd
 
-
-Function DetectJRE
-  ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \
-             "CurrentVersion"
-  StrCmp $2 ${JRE_VERSION} done
-
-  StrCmp $2 ${JRE_ALTERNATE} done
-
-  Call GetJRE
-
-  done:
+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
@@ -70,24 +69,27 @@ Section "Install Driver" InstDriver
        InstDrv::DeleteOemInfFiles /NOUNLOAD
        InstDrv::CreateDevice /NOUNLOAD
 
-       SetOutPath $TEMP
-       File "../altusmetrum.inf"
-       InstDrv::InstallDriver /NOUNLOAD "$TEMP\altusmetrum.inf"
-
        SetOutPath $INSTDIR
        File "../altusmetrum.inf"
+       File "../altusmetrum.cat"
 
-       SetOutPath $WINDIR\Inf
-       File "../altusmetrum.inf"
+       ${DisableX64FSRedirection}
+       IfFileExists $WINDIR\System32\PnPutil.exe 0 nopnp
+               ${DisableX64FSRedirection}
+               nsExec::ExecToLog '"$WINDIR\System32\PnPutil.exe" -i -a "$INSTDIR\altusmetrum.inf"'
+               Goto done
+nopnp:
+               InstDrv::InstallDriver /NOUNLOAD "$INSTDIR\altusmetrum.inf"
+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"
@@ -102,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"
@@ -118,7 +120,9 @@ Section "TeleMetrum, TeleDongle and TeleBT Firmware"
        File "../src/telemetrum-v1.0/telemetrum-v1.0-${VERSION}.ihx"
        File "../src/telemetrum-v1.1/telemetrum-v1.1-${VERSION}.ihx"
        File "../src/telemetrum-v1.2/telemetrum-v1.2-${VERSION}.ihx"
+       File "../src/telemetrum-v2.0/telemetrum-v2.0-${VERSION}.ihx"
        File "../src/telemini-v1.0/telemini-v1.0-${VERSION}.ihx"
+       File "../src/telegps-v1.0/telegps-v1.0-${VERSION}.ihx"
        File "../src/teledongle-v0.2/teledongle-v0.2-${VERSION}.ihx"
        File "../src/telebt-v1.0/telebt-v1.0-${VERSION}.ihx"
        File "../src/telemega-v1.0/telemega-v1.0-${VERSION}.ihx"
@@ -139,41 +143,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 .inf file
-       Delete "$WINDIR\Inf\altusmetrum.inf"
+       DeleteRegKey   HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${REG_NAME}"
+       DeleteRegKey   HKLM "SOFTWARE\${REG_NAME}"
 
-       ; Remove devices
-       InstDrv::InitDriverSetup /NOUNLOAD {4D36E96D-E325-11CE-BFC1-08002BE10318} AltusMetrumSerial
-       InstDrv::DeleteOemInfFiles /NOUNLOAD
-       InstDrv::RemoveAllDevices
+       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