summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-06-20 12:22:41 +0800
committerOpportunityLiu <[email protected]>2019-06-20 12:22:41 +0800
commita3229f788ef9b0b1695e5996fc682ac4d0ab016a (patch)
treebe21a7459b01780bbbb228f1f9816cba3d183331 /scripts
parentf36cd220cbf087247254b1f6700dd89c6b62428a (diff)
noamin
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get.ps110
-rw-r--r--scripts/installer.nsi148
2 files changed, 132 insertions, 26 deletions
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index 21646bc7d..27b131d18 100644
--- a/scripts/get.ps1
+++ b/scripts/get.ps1
@@ -102,7 +102,15 @@ function xmakeInstall {
Write-Host 'Start installation... Hope your antivirus doesn''t trouble'
Write-Host "Install to $installdir"
try {
- Start-Process -FilePath $outfile -ArgumentList "/S /D=$installdir" -Wait
+ $installdir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($installdir)
+ $adminflag = "/NOADMIN "
+ try {
+ $tempfolder = New-Item "$installdir-$PID-temp" -ItemType Directory
+ Remove-Item $tempfolder.FullName
+ } catch {
+ $adminflag = ""
+ }
+ Start-Process -FilePath $outfile -ArgumentList "$adminflag/S /D=$installdir" -Wait
} catch {
writeErrorTip 'Install failed!'
writeErrorTip 'Close your antivirus then try again'
diff --git a/scripts/installer.nsi b/scripts/installer.nsi
index 9abeacf17..3dec2f038 100644
--- a/scripts/installer.nsi
+++ b/scripts/installer.nsi
@@ -10,6 +10,8 @@
!include "MUI2.nsh"
!include "WordFunc.nsh"
!include "WinMessages.nsh"
+!include FileFunc.nsh
+!include UAC.nsh
; xmake version Information
!ifndef MAJOR
@@ -45,12 +47,16 @@ OutFile "xmake.exe"
; The default installation directory
!ifdef x64
InstallDir $PROGRAMFILES64\XMake
+ !define HKLM HKLM64
+ !define HKCU HKCU64
!else
InstallDir $PROGRAMFILES\XMake
+ !define HKLM HKLM
+ !define HKCU HKCU
!endif
; Request application privileges for Windows Vista
-RequestExecutionLevel admin
+RequestExecutionLevel user
; Set DPI Aware
ManifestDPIAware true
@@ -63,6 +69,34 @@ ManifestDPIAware true
;--------------------------------
; Icon
!define MUI_ICON "..\core\src\demo\xmake.ico"
+
+;--------------------------------
+; UAC helper
+
+!macro Init thing
+uac_tryagain:
+!insertmacro UAC_RunElevated
+${Switch} $0
+${Case} 0
+ ${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
+ ${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
+ ${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
+ MessageBox mb_YesNo|mb_IconExclamation|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, try again" /SD IDNO IDYES uac_tryagain IDNO 0
+ ${EndIf}
+ ;fall-through and die
+${Case} 1223
+ MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "This ${thing} requires admin privileges, aborting!"
+ Quit
+${Case} 1062
+ MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Logon service not running, aborting!"
+ Quit
+${Default}
+ MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
+ Quit
+${EndSwitch}
+
+SetShellVarContext all
+!macroend
;--------------------------------
; Pages
@@ -102,9 +136,28 @@ VIAddVersionKey /LANG=0 OriginalFilename "xmake-${ARCH}.exe"
VIAddVersionKey /LANG=0 FileVersion ${VERSION_FULL}
VIAddVersionKey /LANG=0 ProductVersion ${VERSION_FULL}
+
+;--------------------------------
+; Reg pathes
+
+!define RegUninstall "Software\Microsoft\Windows\CurrentVersion\Uninstall\XMake"
+!define RegProduct "Software\XMake"
+
;--------------------------------
+Var NOADMIN
+
; Installer
+Function .onInit
+ ${GetOptions} $CMDLINE "/NOADMIN" $NOADMIN
+ ${If} ${Errors}
+ !insertmacro Init "installer"
+ StrCpy $NOADMIN "false"
+ ${Else}
+ StrCpy $NOADMIN "true"
+ ${EndIf}
+FunctionEnd
+
Section "xmake (required)" Installer
SectionIn RO
@@ -120,23 +173,49 @@ Section "xmake (required)" Installer
File "..\*.md"
File "..\core\build\xmake.exe"
File /r /x ".DS_Store" "..\winenv"
-
- ; Write the installation path into the registry
- WriteRegStr HKLM SOFTWARE\NSIS_xmake "Install_Dir" "$INSTDIR"
-
- ; Write the uninstall keys for Windows
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xmake" "DisplayName" "NSIS xmake"
- WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xmake" "UninstallString" '"$INSTDIR\uninstall.exe"'
- WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xmake" "NoModify" 1
- WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xmake" "NoRepair" 1
+
WriteUninstaller "uninstall.exe"
- ; Remove the installation path from the $PATH environment variable first
- ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
- ${WordReplace} $R0 ";$INSTDIR" "" "+" $R1
+ !macro AddReg RootKey
+ ; Write the installation path into the registry
+ WriteRegStr ${RootKey} ${RegProduct} "Install_Dir" "$INSTDIR"
+ ; Write uac info
+ WriteRegStr ${RootKey} ${RegProduct} "NoAdmin" "$NOADMIN"
+
+ ; Write the uninstall keys for Windows
+ WriteRegStr ${RootKey} ${RegUninstall} "DisplayName" "XMake build utility"
+ WriteRegStr ${RootKey} ${RegUninstall} "DisplayIcon" '"$INSTDIR\xmake.exe"'
+ WriteRegStr ${RootKey} ${RegUninstall} "Publisher" "The TBOOX Open Source Group"
+ WriteRegStr ${RootKey} ${RegUninstall} "UninstallString" '"$INSTDIR\uninstall.exe"'
+ WriteRegStr ${RootKey} ${RegUninstall} "QuiteUninstallString" '"$INSTDIR\uninstall.exe" /S'
+ WriteRegStr ${RootKey} ${RegUninstall} "InstallLocation" '"$INSTDIR"'
+ WriteRegStr ${RootKey} ${RegUninstall} "HelpLink" 'https://xmake.io/'
+ WriteRegStr ${RootKey} ${RegUninstall} "URLInfoAbout" 'https://github.com/xmake-io/xmake'
+ WriteRegStr ${RootKey} ${RegUninstall} "URLUpdateInfo" 'https://github.com/xmake-io/xmake/releases'
+ WriteRegDWORD ${RootKey} ${RegUninstall} "VersionMajor" ${MAJOR}
+ WriteRegDWORD ${RootKey} ${RegUninstall} "VersionMinor" ${MINOR}
+ WriteRegStr ${RootKey} ${RegUninstall} "DisplayVersion" ${VERSION_FULL}
+ WriteRegDWORD ${RootKey} ${RegUninstall} "NoModify" 1
+ WriteRegDWORD ${RootKey} ${RegUninstall} "NoRepair" 1
+
+ ;write size to reg
+ ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
+ IntFmt $0 "0x%08X" $0
+ WriteRegDWORD ${RootKey} ${RegUninstall} "EstimatedSize" "$0"
+
+ ; Remove the installation path from the $PATH environment variable first
+ ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
+ ${WordReplace} $R0 ";$INSTDIR" "" "+" $R1
- ; Write the installation path into the $PATH environment variable
- WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1;$INSTDIR"
+ ; Write the installation path into the $PATH environment variable
+ WriteRegExpandStr ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1;$INSTDIR"
+ !macroend
+
+ ${If} $NOADMIN == "false"
+ !insertmacro AddReg ${HKLM}
+ ${Else}
+ !insertmacro AddReg ${HKCU}
+ ${EndIf}
SectionEnd
@@ -155,19 +234,38 @@ LangString DESC_Installer ${LANG_ENGLISH} "A cross-platform build utility based
; Uninstaller
-Section "Uninstall"
+Function un.onInit
+ ; check if we need uac
+ ReadRegStr $NOADMIN ${HKLM} SOFTWARE\XMake "NoAdmin"
+ IfErrors 0 +2
+ ReadRegStr $NOADMIN ${HKCU} SOFTWARE\XMake "NoAdmin"
- ; Remove registry keys
- DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\xmake"
- DeleteRegKey HKLM SOFTWARE\NSIS_xmake
+ ${IfNot} $NOADMIN == "true"
+ !insertmacro Init "uninstaller"
+ ${EndIf}
+
+FunctionEnd
+
+Section "Uninstall"
+
+ !macro RemoveReg RootKey
+ ; Remove registry keys
+ DeleteRegKey ${RootKey} ${RegUninstall}
+ DeleteRegKey ${RootKey} ${RegProduct}
+
+ ; Remove the installation path from the $PATH environment variable
+ ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
+ ${WordReplace} $R0 ";$INSTDIR" "" "+" $R1
+ ; MessageBox MB_OK|MB_USERICON '$R0 - $INSTDIR - $R1 '
+ WriteRegExpandStr ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1"
+ !macroend
; Remove directories used
RMDir /r "$INSTDIR"
-
- ; Remove the installation path from the $PATH environment variable
- ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
- ${WordReplace} $R0 ";$INSTDIR" "" "+" $R1
- ; MessageBox MB_OK|MB_USERICON '$R0 - $INSTDIR - $R1 '
- WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1"
+ ${If} $NOADMIN == "false"
+ !insertmacro RemoveReg ${HKLM}
+ ${Else}
+ !insertmacro RemoveReg ${HKCU}
+ ${EndIf}
SectionEnd