qgroundcontrol_installer.nsi 5.42 KB
Newer Older
1
!include "MUI2.nsh"
2 3 4
!include LogicLib.nsh
!include Win\COM.nsh
!include Win\Propkey.nsh
5
!include "FileFunc.nsh"
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 38

!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
39

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

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

45 46
SetCompressor /SOLID /FINAL lzma

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

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

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
58

59
!insertmacro MUI_LANGUAGE "English"
60

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

65
  ExecWait "$R0 /S _?=$INSTDIR -LEAVE_DATA=1"
66 67 68
  IntCmp $0 0 doinstall

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

doinstall:
73
  SetOutPath $INSTDIR
74
  File /r /x ${EXENAME}.pdb /x ${EXENAME}.lib /x ${EXENAME}.exp ${DESTDIR}\*.*
Don Gagne's avatar
Don Gagne committed
75
  File deploy\px4driver.msi
76
  WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe
77 78 79 80 81 82
  WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
  WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\${EXENAME}-Uninstall.exe$\""
  SetRegView 64
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpCount" 5 
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpType" 2 
  WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpFolder" "%LOCALAPPDATA%\QGCCrashDumps"
83 84

  ; Only attempt to install the PX4 driver if the version isn't present
85 86 87 88 89
  !define ROOTKEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\434608CF2B6E31F0DDBA5C511053F957B55F098E"

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

found_provider:
92 93 94
  ReadRegStr $0 HKLM "${ROOTKEY}" "DisplayVersion"
  DetailPrint "Checking USB driver version... $0"
  StrCmp     $0 "04/11/2013 2.0.0.4" skip_driver notfound
95 96 97

notfound:
  DetailPrint "USB Driver not found... installing"
Don Gagne's avatar
Don Gagne committed
98
  ExecWait '"msiexec" /i "px4driver.msi"'
99 100 101 102 103
  goto done

skip_driver:
  DetailPrint "USB Driver found... skipping install"
done:
104
  SetRegView lastused
105 106 107
SectionEnd 

Section "Uninstall"
108 109
  ${GetParameters} $R0
  ${GetOptions} $R0 "-LEAVE_DATA=" $R1
110
  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
111
  SetShellVarContext all
Don Gagne's avatar
Don Gagne committed
112
  RMDir /r /REBOOTOK $INSTDIR
113
  RMDir /r /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\"
114
  SetShellVarContext current
115 116 117
  ${If} $R1 != 1
    RMDir /r /REBOOTOK "$APPDATA\${ORGNAME}\"
  ${Endif}
118 119
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe"
120 121 122
SectionEnd

Section "create Start Menu Shortcuts"
123
  SetShellVarContext all
124
  CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
125 126 127 128 129
  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"
130 131
SectionEnd