qgroundcontrol_installer.nsi 6.87 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..."
  ExecWait "$R0 /S -LEAVE_DATA=1 _?=$INSTDIR"
DonLakeFlyer's avatar
DonLakeFlyer committed
75
  IntCmp $0 0 doInstall
76 77

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

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

  ; 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
88
  File ${DRIVER_MSI}
89

90
  WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe
91 92 93
  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 
94
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpType" 1
95
  WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpFolder" "%LOCALAPPDATA%\QGCCrashDumps"
96

97 98 99
  ; 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
100
  !define QGCCURRENTDRIVERVERSION 2
101

102
  ; If the drivers are already installed the key "HKCU/SOFTWARE\MichaelOborne\driver\installed" will be present and set to 1
103
  SetRegView 64
104
  !define DRIVERKEY "SOFTWARE\MichaelOborne\driver"
105
  ReadRegDWORD $0 HKCU "${DRIVERKEY}" "installed"
106 107 108 109 110
  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
111
  ; Missing key also indicates out of date driver install.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  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
128
  WriteRegDWORD HKCU "${QGCDRIVERVERSIONKEY}" "version" ${QGCCURRENTDRIVERVERSION}
129 130 131
  goto done

done:
132
  SetRegView lastused
133 134 135
SectionEnd 

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

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