qgroundcontrol_installer.nsi 5.24 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
  DetailPrint "Uninstalling previous version..."  
66
  ExecWait "$R0 /S _?=$INSTDIR -LEAVE_DATA=1"
67 68 69
  IntCmp $0 0 doinstall

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

doinstall:
74
  SetOutPath $INSTDIR
75
  File /r /x ${EXENAME}.pdb /x ${EXENAME}.lib /x ${EXENAME}.exp ${DESTDIR}\*.*
Don Gagne's avatar
Don Gagne committed
76
  File deploy\px4driver.msi
77
  WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe
78 79 80 81
  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 
82
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpType" 1
83
  WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpFolder" "%LOCALAPPDATA%\QGCCrashDumps"
84 85

  ; Only attempt to install the PX4 driver if the version isn't present
86
  !define DRIVERKEY "SOFTWARE\MichaelOborne\driver"
87 88

  SetRegView 64
89 90
  ReadRegDWORD $0 HKCU "${DRIVERKEY}" "installed"
  IntCmp $0 1 found_provider notfound notfound
91 92

found_provider:
93 94
  DetailPrint "USB Drivers already installed"
  goto done
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
  goto done

done:
102
  SetRegView lastused
103 104 105
SectionEnd 

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

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