qgroundcontrol_installer.nsi 6.86 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

DonLakeFlyer's avatar
DonLakeFlyer committed
43
InstallDir "$PROGRAMFILES64\${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
DonLakeFlyer's avatar
DonLakeFlyer committed
62 63
  DetailPrint "Checking for 32 bit uninstaller"  
  SetRegView 32
64
  ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString"
DonLakeFlyer's avatar
DonLakeFlyer committed
65
  StrCmp $R0 "" check64BitUninstall doUninstall
66

DonLakeFlyer's avatar
DonLakeFlyer committed
67 68 69 70 71 72 73
check64BitUninstall:
  DetailPrint "Checking for 64 bit  uninstaller"  
  SetRegView 64
  ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString"
  StrCmp $R0 "" doInstall

doUninstall:
74
  DetailPrint "Uninstalling previous version..."  
DonLakeFlyer's avatar
DonLakeFlyer committed
75 76
  ExecWait "$R0 /S -LEAVE_DATA=1"
  IntCmp $0 0 doInstall
77 78

  MessageBox MB_OK|MB_ICONEXCLAMATION \
79
        "Could not remove a previously installed ${APPNAME} version.$\n$\nPlease remove it before continuing."
80 81
  Abort

DonLakeFlyer's avatar
DonLakeFlyer committed
82 83
doInstall:
  SetRegView 64
84
  SetOutPath $INSTDIR
85
  File /r /x ${EXENAME}.pdb /x ${EXENAME}.lib /x ${EXENAME}.exp ${DESTDIR}\*.*
86 87 88 89 90

  ; Driver location is http://firmware.ardupilot.org/Tools/MissionPlanner/driver.msi
  ; Whenever this driver is updated in the repo QGCCURRENTDRIVERVERSION must be bumped by 1
  File deploy\driver.msi

91
  WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe
92 93 94
  WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
  WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$\"$INSTDIR\${EXENAME}-Uninstall.exe$\""
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpCount" 5 
95
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpType" 1
96
  WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpFolder" "%LOCALAPPDATA%\QGCCrashDumps"
97

98 99 100
  ; QGC stores its own driver version key to prevent installation if already up to date
  ; This prevents running the driver install a second time which will start up in repair mode which is confusing
  !define QGCDRIVERVERSIONKEY "SOFTWARE\QGroundControlUAVDrivers"
DonLakeFlyer's avatar
DonLakeFlyer committed
101
  !define QGCCURRENTDRIVERVERSION 2
102

103
  ; If the drivers are already installed the key "HKCU/SOFTWARE\MichaelOborne\driver\installed" will be present and set to 1
104
  SetRegView 64
105
  !define DRIVERKEY "SOFTWARE\MichaelOborne\driver"
106
  ReadRegDWORD $0 HKCU "${DRIVERKEY}" "installed"
107 108 109 110 111
  IntCmp $0 1 driversInstalled driversNotInstalled driversNotInstalled

driversInstalled:
  DetailPrint "UAV Drivers already installed. Checking version..."
  ; Check if the installed drivers are out of date. 
DonLakeFlyer's avatar
DonLakeFlyer committed
112
  ; Missing key also indicates out of date driver install.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  ReadRegDWORD $0 HKCU "${QGCDRIVERVERSIONKEY}" "version"
  IntCmp $0 ${QGCCURRENTDRIVERVERSION} done driversOutOfDate done

driversOutOfDate:
  DetailPrint "UAV Drivers out of date."
  goto installDrivers
  
driversNotInstalled:
  DetailPrint "UAV Drivers not installed."
  ; Delete abandoned possibly out of date version key
  DeleteRegKey HKCU "SOFTWARE\QGroundControlUAVDrivers"

installDrivers:
  DetailPrint "Installing UAV Drivers..."
  ExecWait '"msiexec" /i "driver.msi"'
  ; Set current driver version value
DonLakeFlyer's avatar
DonLakeFlyer committed
129
  WriteRegDWORD HKCU "${QGCDRIVERVERSIONKEY}" "version" ${QGCCURRENTDRIVERVERSION}
130 131 132
  goto done

done:
133
  SetRegView lastused
134 135 136
SectionEnd 

Section "Uninstall"
DonLakeFlyer's avatar
DonLakeFlyer committed
137
  SetRegView 64
138 139
  ${GetParameters} $R0
  ${GetOptions} $R0 "-LEAVE_DATA=" $R1
140
  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
141
  SetShellVarContext all
Don Gagne's avatar
Don Gagne committed
142
  RMDir /r /REBOOTOK $INSTDIR
143
  RMDir /r /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\"
144
  SetShellVarContext current
145 146 147
  ${If} $R1 != 1
    RMDir /r /REBOOTOK "$APPDATA\${ORGNAME}\"
  ${Endif}
148 149
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe"
150
  ; NOTE: We specifically do not delete the driver version key since we need it to persist around uninstalls
151 152 153
SectionEnd

Section "create Start Menu Shortcuts"
DonLakeFlyer's avatar
DonLakeFlyer committed
154
  SetRegView 64
155
  SetShellVarContext all
156
  CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
157 158 159 160 161
  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"
162 163
SectionEnd