qgroundcontrol_installer.nsi 4.8 KB
Newer Older
1
!include "MUI2.nsh"
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
!include LogicLib.nsh
!include Win\COM.nsh
!include Win\Propkey.nsh

!macro DemoteShortCut target
    !insertmacro ComHlpr_CreateInProcInstance ${CLSID_ShellLink} ${IID_IShellLink} r0 ""
    ${If} $0 <> 0
            ${IUnknown::QueryInterface} $0 '("${IID_IPersistFile}",.r1)'
            ${If} $1 P<> 0
                    ${IPersistFile::Load} $1 '("${target}",1)'
                    ${IUnknown::Release} $1 ""
            ${EndIf}
            ${IUnknown::QueryInterface} $0 '("${IID_IPropertyStore}",.r1)'
            ${If} $1 P<> 0
                    System::Call '*${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_StartPinOption})p.r2'
                    System::Call '*${SYSSTRUCT_PROPVARIANT}(${VT_UI4},,&i4 ${APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL})p.r3'
                    ${IPropertyStore::SetValue} $1 '($2,$3)'

                    ; Reuse the PROPERTYKEY & PROPVARIANT buffers to set another property
                    System::Call '*$2${SYSSTRUCT_PROPERTYKEY}(${PKEY_AppUserModel_ExcludeFromShowInNewInstall})'
                    System::Call '*$3${SYSSTRUCT_PROPVARIANT}(${VT_BOOL},,&i2 ${VARIANT_TRUE})'
                    ${IPropertyStore::SetValue} $1 '($2,$3)'

                    System::Free $2
                    System::Free $3
                    ${IPropertyStore::Commit} $1 ""
                    ${IUnknown::Release} $1 ""
            ${EndIf}
            ${IUnknown::QueryInterface} $0 '("${IID_IPersistFile}",.r1)'
            ${If} $1 P<> 0
                    ${IPersistFile::Save} $1 '("${target}",1)'
                    ${IUnknown::Release} $1 ""
            ${EndIf}
            ${IUnknown::Release} $0 ""
    ${EndIf}
!macroend
38

39
Name "${APPNAME}"
40
Var StartMenuFolder
41

42
InstallDir "$PROGRAMFILES\${APPNAME}"
43

44 45
SetCompressor /SOLID /FINAL lzma

46
!define MUI_HEADERIMAGE
47 48 49
!define MUI_HEADERIMAGE_BITMAP "${HEADER_BITMAP}";
!define MUI_ICON "${INSTALLER_ICON}";
!define MUI_UNICON "${INSTALLER_ICON}";
50 51 52 53 54 55 56

!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
57

58
!insertmacro MUI_LANGUAGE "English"
59

60
Section
61
  ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString"
62 63
  StrCmp $R0 "" doinstall

64
  ExecWait "$R0 /S _?=$INSTDIR"
65 66 67
  IntCmp $0 0 doinstall

  MessageBox MB_OK|MB_ICONEXCLAMATION \
68
        "Could not remove a previously installed ${APPNAME} version.$\n$\nPlease remove it before continuing."
69 70 71
  Abort

doinstall:
72
  SetOutPath $INSTDIR
73
  File /r /x ${EXENAME}.pdb /x ${EXENAME}.lib /x ${EXENAME}.exp ${DESTDIR}\*.*
Don Gagne's avatar
Don Gagne committed
74
  File deploy\px4driver.msi
75 76 77
  WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\${EXENAME}-Uninstall.exe$\""
78 79

  ; Only attempt to install the PX4 driver if the version isn't present
80 81 82 83 84
  !define ROOTKEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\434608CF2B6E31F0DDBA5C511053F957B55F098E"

  SetRegView 64
  ReadRegStr $0 HKLM "${ROOTKEY}" "Publisher"
  StrCmp     $0 "3D Robotics" found_provider notfound
85 86

found_provider:
87 88 89
  ReadRegStr $0 HKLM "${ROOTKEY}" "DisplayVersion"
  DetailPrint "Checking USB driver version... $0"
  StrCmp     $0 "04/11/2013 2.0.0.4" skip_driver notfound
90 91 92

notfound:
  DetailPrint "USB Driver not found... installing"
Don Gagne's avatar
Don Gagne committed
93
  ExecWait '"msiexec" /i "px4driver.msi"'
94 95 96 97 98
  goto done

skip_driver:
  DetailPrint "USB Driver found... skipping install"
done:
99
  SetRegView lastused
100 101 102
SectionEnd 

Section "Uninstall"
103
  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
104
  SetShellVarContext all
Don Gagne's avatar
Don Gagne committed
105
  RMDir /r /REBOOTOK $INSTDIR
106
  RMDir /r /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\"
107
  SetShellVarContext current
108 109
  RMDir /r /REBOOTOK "$APPDATA\${ORGNAME}\"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
110 111 112
SectionEnd

Section "create Start Menu Shortcuts"
113
  SetShellVarContext all
114
  CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
115 116 117 118 119
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${APPNAME}.lnk" "$INSTDIR\${EXENAME}.exe" "" "$INSTDIR\${EXENAME}.exe" 0
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${APPNAME} (GPU Compatibility Mode).lnk" "$INSTDIR\${EXENAME}.exe" "-angle" "$INSTDIR\${EXENAME}.exe" 0
  !insertmacro DemoteShortCut "$SMPROGRAMS\$StartMenuFolder\${APPNAME} (GPU Compatibility Mode).lnk"
  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${APPNAME} (GPU Safe Mode).lnk" "$INSTDIR\${EXENAME}.exe" "-swrast" "$INSTDIR\${EXENAME}.exe" 0
  !insertmacro DemoteShortCut "$SMPROGRAMS\$StartMenuFolder\${APPNAME} (GPU Safe Mode).lnk"
120 121
SectionEnd