From a3229f788ef9b0b1695e5996fc682ac4d0ab016a Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 12:22:41 +0800 Subject: noamin --- .appveyor.yml | 3 + scripts/get.ps1 | 10 ++- scripts/installer.nsi | 150 ++++++++++++++++++++++++++++++++++-------- xmake/actions/update/main.lua | 6 +- 4 files changed, 141 insertions(+), 28 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 144fd6438..2f8e11dbd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,9 +15,12 @@ install: # NSIS - ps: Invoke-WebRequest "https://svwh.dl.sourceforge.net/project/nsis/NSIS 3/3.04/nsis-3.04.zip" -UseBasicParsing -OutFile ./nsis.zip - ps: Invoke-WebRequest "https://svwh.dl.sourceforge.net/project/nsis/NSIS 3/3.04/nsis-3.04-strlen_8192.zip" -UseBasicParsing -OutFile ./nsis-longstr.zip + - ps: Invoke-WebRequest "https://nsis.sourceforge.io/mediawiki/images/8/8f/UAC.zip" -UseBasicParsing -OutFile ./nsis-uac.zip - ps: Expand-Archive ./nsis.zip -DestinationPath ./nsis - ps: Move-Item ./nsis/*/* ./nsis - ps: Expand-Archive ./nsis-longstr.zip -DestinationPath ./nsis -Force + - ps: Expand-Archive ./nsis-uac.zip -DestinationPath ./nsis -Force + - ps: Move-Item ./nsis/UAC.nsh ./nsis/Include/ # unzip - ps: Invoke-WebRequest "https://svwh.dl.sourceforge.net/project/gnuwin32/unzip/5.51-1/unzip-5.51-1-bin.zip" -UseBasicParsing -OutFile .\unzip.zip - ps: Expand-Archive ./unzip.zip -DestinationPath ./unzip 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 + WriteUninstaller "uninstall.exe" - ; Write the installation path into the $PATH environment variable - WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1;$INSTDIR" + !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 ${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 diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index ab17ef135..2ad5ac647 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -154,10 +154,14 @@ function _install(sourcedir) if os.isfile(win_installer_name) then -- /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported. local params = ("/D=" .. os.programdir()):split("%s", { strict = true }) + local testfile = path.join(os.programdir(), "temp-install") + local no_admin = os.trymv(path.join(os.programdir(), "scripts", "run.vbs"), testfile) + os.tryrm(testfile) + if no_admin then table.insert(params, 1, "/NOADMIN") end if not option.get("verbose") then table.insert(params, 1, "/S") end -- need UAC? if winos:version():gt("winxp") then - _run_win_v(win_installer_name, params, true) + _run_win_v(win_installer_name, params, not no_admin) else _run_win_v(win_installer_name, params, false) end -- cgit v1.3.1 From cd777f095cedf5872968797facaf56d69348f36b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 12:25:49 +0800 Subject: fix --- xmake/actions/update/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 2ad5ac647..8ef60b5cb 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -155,7 +155,7 @@ function _install(sourcedir) -- /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported. local params = ("/D=" .. os.programdir()):split("%s", { strict = true }) local testfile = path.join(os.programdir(), "temp-install") - local no_admin = os.trymv(path.join(os.programdir(), "scripts", "run.vbs"), testfile) + local no_admin = os.trycp(path.join(os.programdir(), "scripts", "run.vbs"), testfile) os.tryrm(testfile) if no_admin then table.insert(params, 1, "/NOADMIN") end if not option.get("verbose") then table.insert(params, 1, "/S") end -- cgit v1.3.1 From b9b81a72c8f9b3c06048bb6db461641a86e36a96 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 15:36:34 +0800 Subject: add desc for add to path --- scripts/installer.nsi | 88 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/scripts/installer.nsi b/scripts/installer.nsi index 3dec2f038..e79baef87 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -74,48 +74,49 @@ ManifestDPIAware true ; 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 + 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 +; Install Pages +!insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "..\LICENSE.md" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES - -!insertmacro MUI_UNPAGE_CONFIRM -!insertmacro MUI_UNPAGE_INSTFILES - -;-------------------------------- -; Finish Pages - !define MUI_FINISHPAGE_LINK "Donate $$5" !define MUI_FINISHPAGE_LINK_LOCATION "https://xmake.io/pages/donation.html#donate" !insertmacro MUI_PAGE_FINISH +;-------------------------------- +; Uninstall Pages + +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES +!insertmacro MUI_UNPAGE_FINISH + ;-------------------------------- ; Languages @@ -158,7 +159,7 @@ Function .onInit ${EndIf} FunctionEnd -Section "xmake (required)" Installer +Section "XMake (required)" InstallExeutable SectionIn RO @@ -185,6 +186,7 @@ Section "xmake (required)" Installer ; Write the uninstall keys for Windows WriteRegStr ${RootKey} ${RegUninstall} "DisplayName" "XMake build utility" WriteRegStr ${RootKey} ${RegUninstall} "DisplayIcon" '"$INSTDIR\xmake.exe"' + WriteRegStr ${RootKey} ${RegUninstall} "Comments" "A cross-platform build utility based on Lua" WriteRegStr ${RootKey} ${RegUninstall} "Publisher" "The TBOOX Open Source Group" WriteRegStr ${RootKey} ${RegUninstall} "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegStr ${RootKey} ${RegUninstall} "QuiteUninstallString" '"$INSTDIR\uninstall.exe" /S' @@ -202,7 +204,19 @@ Section "xmake (required)" Installer ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 IntFmt $0 "0x%08X" $0 WriteRegDWORD ${RootKey} ${RegUninstall} "EstimatedSize" "$0" + !macroend + ${If} $NOADMIN == "false" + !insertmacro AddReg ${HKLM} + ${Else} + !insertmacro AddReg ${HKCU} + ${EndIf} + +SectionEnd + +Section "Add to PATH" InstallPath + + !macro AddRegPATH RootKey ; Remove the installation path from the $PATH environment variable first ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" ${WordReplace} $R0 ";$INSTDIR" "" "+" $R1 @@ -212,22 +226,24 @@ Section "xmake (required)" Installer !macroend ${If} $NOADMIN == "false" - !insertmacro AddReg ${HKLM} + !insertmacro AddRegPATH ${HKLM} ${Else} - !insertmacro AddReg ${HKCU} + !insertmacro AddRegPATH ${HKCU} ${EndIf} - + SectionEnd ;-------------------------------- ; Descriptions ; Language strings -LangString DESC_Installer ${LANG_ENGLISH} "A cross-platform build utility based on Lua" +LangString DESC_InstallExeutable ${LANG_ENGLISH} "A cross-platform build utility based on Lua" +LangString DESC_InstallPath ${LANG_ENGLISH} "Add xmake to PATH" ; Assign language strings to sections !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN -!insertmacro MUI_DESCRIPTION_TEXT ${Installer} $(DESC_Installer) +!insertmacro MUI_DESCRIPTION_TEXT ${InstallExeutable} $(DESC_InstallExeutable) +!insertmacro MUI_DESCRIPTION_TEXT ${InstallPath} $(DESC_InstallPath) !insertmacro MUI_FUNCTION_DESCRIPTION_END ;-------------------------------- -- cgit v1.3.1 From 1f7c29466107709a76f66113458561b998e072d1 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 15:46:26 +0800 Subject: fix --- scripts/get.ps1 | 329 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 166 insertions(+), 163 deletions(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 27b131d18..75b05efe3 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -10,193 +10,196 @@ param ( [string]$installdir = "" ) -function writeErrorTip($msg) { - Write-Host $msg -BackgroundColor Red -ForegroundColor White -} - -if (-not $env:CI) { - $logo = @( - ' _ ' - ' __ ___ __ __ __ _| | ______ ' - ' \ \/ / | \/ |/ _ | |/ / __ \ ' - ' > < | \__/ | /_| | < ___/ ' - ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' - ' ' - ' ') - Write-Host $([string]::Join("`n", $logo)) -BackgroundColor White -ForegroundColor DarkBlue -} +& { -if ($IsLinux -or $IsMacOS) { - writeErrorTip 'Install on *nix is not supported, try ' - writeErrorTip '(Use curl) "bash <(curl -fsSL https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh)"' - writeErrorTip 'or' - writeErrorTip '(Use wget) "bash <(wget https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh -O -)"' - throw 'Unsupported platform' -} - -$temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0] -[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - -if ($null -eq $installdir -or $installdir -match '^\s*$') { - $installdir = & { - # Install to old xmake path - $oldXmake = Get-Command xmake -CommandType Application -ErrorAction SilentlyContinue - if ($oldXmake) { - return Split-Path $oldXmake.Path -Parent - } - if ($HOME) { - return Join-Path $HOME 'xmake' - } - if ($env:APPDATA) { - return Join-Path $env:APPDATA 'xmake' - } - if ($env:ProgramFiles) { - return Join-Path $env:ProgramFiles 'xmake' - } - return 'C:\xmake' + function writeErrorTip($msg) { + Write-Host $msg -BackgroundColor Red -ForegroundColor White } -} -if ($null -eq $version -or $version -match '^\s*$') { - $v = 'master' -} else { - $v = $version.Trim() - if ($v.Contains('.')) { - $v = [version]::Parse($version) - $v = New-Object -TypeName version -ArgumentList $v.Major, $v.Minor, $v.Build + if (-not $env:CI) { + $logo = @( + ' _ ' + ' __ ___ __ __ __ _| | ______ ' + ' \ \/ / | \/ |/ _ | |/ / __ \ ' + ' > < | \__/ | /_| | < ___/ ' + ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' + ' ' + ' ') + Write-Host $([string]::Join("`n", $logo)) -BackgroundColor White -ForegroundColor DarkBlue } -} -function checkTempAccess { - $outfile = Join-Path $temppath "$pid.tmp" - try { - Write-Output $pid | Out-File -FilePath $outfile - Remove-Item $outfile - } catch { - writeErrorTip 'Cannot write to temp path' - writeErrorTip 'Please set environment var "TMP" to another path' - throw + + if ($IsLinux -or $IsMacOS) { + writeErrorTip 'Install on *nix is not supported, try ' + writeErrorTip '(Use curl) "bash <(curl -fsSL https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh)"' + writeErrorTip 'or' + writeErrorTip '(Use wget) "bash <(wget https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh -O -)"' + throw 'Unsupported platform' } -} -function xmakeInstall { - $outfile = Join-Path $temppath "$pid-xmake-installer.exe" - $x64arch = @('AMD64', 'IA64', 'ARM64') - $arch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'x64' } else { 'x86' } - $url = if ($v -is [version]) { - if ($v -gt "2.2.6") { - "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?tag=v$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" - } else { - "https://github.com/xmake-io/xmake/releases/download/v$v/xmake-v$v.exe" + $temppath = ($env:TMP, $env:TEMP, "$(Get-Location)" -ne $null)[0] + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + if ($null -eq $installdir -or $installdir -match '^\s*$') { + $installdir = & { + # Install to old xmake path + $oldXmake = Get-Command xmake -CommandType Application -ErrorAction SilentlyContinue + if ($oldXmake) { + return Split-Path $oldXmake.Path -Parent + } + if ($HOME) { + return Join-Path $HOME 'xmake' + } + if ($env:APPDATA) { + return Join-Path $env:APPDATA 'xmake' + } + if ($env:ProgramFiles) { + return Join-Path $env:ProgramFiles 'xmake' + } + return 'C:\xmake' } - } else { - "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" } - Write-Host "Start downloading $url .." - try { - Invoke-Webrequest $url -OutFile $outfile -UseBasicParsing - } catch { - writeErrorTip 'Download failed!' - writeErrorTip 'Check your network or... the news of S3 break' - throw + $installdir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($installdir) + + if ($null -eq $version -or $version -match '^\s*$') { + $v = 'master' + } else { + $v = $version.Trim() + if ($v.Contains('.')) { + $v = [version]::Parse($version) + $v = New-Object -TypeName version -ArgumentList $v.Major, $v.Minor, $v.Build + } } - Write-Host 'Start installation... Hope your antivirus doesn''t trouble' - Write-Host "Install to $installdir" - try { - $installdir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($installdir) - $adminflag = "/NOADMIN " + function checkTempAccess { + $outfile = Join-Path $temppath "$pid.tmp" try { - $tempfolder = New-Item "$installdir-$PID-temp" -ItemType Directory - Remove-Item $tempfolder.FullName + Write-Output $pid | Out-File -FilePath $outfile + Remove-Item $outfile } catch { - $adminflag = "" + writeErrorTip 'Cannot write to temp path' + writeErrorTip 'Please set environment var "TMP" to another path' + throw } - Start-Process -FilePath $outfile -ArgumentList "$adminflag/S /D=$installdir" -Wait - } catch { - writeErrorTip 'Install failed!' - writeErrorTip 'Close your antivirus then try again' - throw - } finally { - Remove-Item $outfile -ErrorAction SilentlyContinue - } - Write-Host 'Adding to PATH... almost done' - $env:Path += ";$installdir" - try { - xmake --version - } catch { - writeErrorTip 'Everything is showing installation has finished' - writeErrorTip 'But xmake could not run... Why?' - throw } -} - -function registerTabCompletion { - - function writeDataToFile($file) { - $encoding = [text.encoding]::UTF8 - if (Test-Path $file -PathType Leaf) { - #Create a stream reader to get the file's encoding and contents. - $sr = New-Object System.IO.StreamReader($file, $true) - [char[]] $buffer = new-object char[] 3 - $sr.Read($buffer, 0, 3) | Out-Null - $encoding = $sr.CurrentEncoding - $sr.Close() | Out-Null - if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { - Write-Host "Seems the tab completion of xmake has installed here... skipped" - return + function xmakeInstall { + $outfile = Join-Path $temppath "$pid-xmake-installer.exe" + $x64arch = @('AMD64', 'IA64', 'ARM64') + $arch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'x64' } else { 'x86' } + $url = if ($v -is [version]) { + if ($v -gt "2.2.6") { + "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?tag=v$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" + } else { + "https://github.com/xmake-io/xmake/releases/download/v$v/xmake-v$v.exe" } + } else { + "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" } - + Write-Host "Start downloading $url .." try { - New-Item $(Split-Path $file -Parent) -ItemType Directory -Force | Out-Null - [IO.File]::AppendAllText($file, "`n", $encoding) + Invoke-Webrequest $url -OutFile $outfile -UseBasicParsing + } catch { + writeErrorTip 'Download failed!' + writeErrorTip 'Check your network or... the news of S3 break' + throw + } + Write-Host 'Start installation... Hope your antivirus doesn''t trouble' + Write-Host "Install to $installdir" + try { + $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 "Failed to append to profile!" - writeErrorTip "Please try again as administrator" - return + writeErrorTip 'Install failed!' + writeErrorTip 'Close your antivirus then try again' + throw + } finally { + Remove-Item $outfile -ErrorAction SilentlyContinue } + Write-Host 'Adding to PATH... almost done' + $env:Path += ";$installdir" try { - $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content + xmake --version } catch { - writeErrorTip 'Download failed!' - writeErrorTip 'Check your network or... the news of S3 break' - return + writeErrorTip 'Everything is showing installation has finished' + writeErrorTip 'But xmake could not run... Why?' + throw } - [IO.File]::AppendAllText($file, $content, $encoding) - [IO.File]::AppendAllText($file, "`n", $encoding) - . $file - Write-Host "Tab completion installed" } - $message = 'Tab completion service' - $question = 'Would you like to install tab completion service of xmake to your profile?' - - $choices = @( - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'For &all users', - "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for &me', - "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for this &host', - "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - '&No', - "Do not install xmake's tab completion service.")) - ) - switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { - 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } - 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } - 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } + + function registerTabCompletion { + + function writeDataToFile($file) { + $encoding = [text.encoding]::UTF8 + if (Test-Path $file -PathType Leaf) { + #Create a stream reader to get the file's encoding and contents. + $sr = New-Object System.IO.StreamReader($file, $true) + [char[]] $buffer = new-object char[] 3 + $sr.Read($buffer, 0, 3) | Out-Null + $encoding = $sr.CurrentEncoding + $sr.Close() | Out-Null + + if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { + Write-Host "Seems the tab completion of xmake has installed here... skipped" + return + } + } + + try { + New-Item $(Split-Path $file -Parent) -ItemType Directory -Force | Out-Null + [IO.File]::AppendAllText($file, "`n", $encoding) + } catch { + writeErrorTip "Failed to append to profile!" + writeErrorTip "Please try again as administrator" + return + } + try { + $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content + } catch { + writeErrorTip 'Download failed!' + writeErrorTip 'Check your network or... the news of S3 break' + return + } + [IO.File]::AppendAllText($file, $content, $encoding) + [IO.File]::AppendAllText($file, "`n", $encoding) + . $file + Write-Host "Tab completion installed" + } + $message = 'Tab completion service' + $question = 'Would you like to install tab completion service of xmake to your profile?' + + $choices = @( + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'For &all users', + "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for &me', + "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for this &host', + "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + '&No', + "Do not install xmake's tab completion service.")) + ) + switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { + 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } + 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } + 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } + } } -} -checkTempAccess -xmakeInstall + checkTempAccess + xmakeInstall -if (-not $env:CI) { - registerTabCompletion -} else { - Write-Host "Tab completion registration has been skipped for CI" -} + if (-not $env:CI) { + registerTabCompletion + } else { + Write-Host "Tab completion registration has been skipped for CI" + } +} -- cgit v1.3.1 From d383b118b3614f9ce330c3bb4f241ed1f6851690 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 22:01:06 +0800 Subject: fix install dir --- scripts/installer.nsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/installer.nsi b/scripts/installer.nsi index e79baef87..795ca6d32 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -46,11 +46,11 @@ OutFile "xmake.exe" ; The default installation directory !ifdef x64 - InstallDir $PROGRAMFILES64\XMake + InstallDir $PROGRAMFILES64\xmake !define HKLM HKLM64 !define HKCU HKCU64 !else - InstallDir $PROGRAMFILES\XMake + InstallDir $PROGRAMFILES\xmake !define HKLM HKLM !define HKCU HKCU !endif -- cgit v1.3.1 From 5d8c5b6d686b802c48ff52bfe72f188c92509f49 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 20 Jun 2019 22:17:33 +0800 Subject: [skip ci] chang title color --- scripts/get.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 75b05efe3..d3deefc56 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -25,7 +25,7 @@ param ( ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' ' ' ' ') - Write-Host $([string]::Join("`n", $logo)) -BackgroundColor White -ForegroundColor DarkBlue + Write-Host $([string]::Join("`n", $logo)) -ForegroundColor Green } if ($IsLinux -or $IsMacOS) { -- cgit v1.3.1