summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-11-11 15:29:06 +0800
committerruki <[email protected]>2018-11-11 15:29:06 +0800
commitf372a5c5cf20e9a7deaa99cdb9d2c14b5aec7755 (patch)
treede254801dde03db15fffb313004ee316ac121ed4
parent7d5215f5807e37a23d350aaa11fc1e1b6464bd7e (diff)
improve to update with sudo on win7
-rw-r--r--xmake/actions/update/main.lua34
-rw-r--r--xmake/scripts/sudo.vbs15
2 files changed, 42 insertions, 7 deletions
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua
index b2c879b53..4bcc334be 100644
--- a/xmake/actions/update/main.lua
+++ b/xmake/actions/update/main.lua
@@ -106,9 +106,17 @@ function _uninstall()
if is_host("windows") then
local uninstaller = path.join(os.programdir(), "uninstall.exe")
if os.isfile(uninstaller) then
- local proc = process.open(uninstaller)
- if proc ~= nil then
- process.close(proc)
+ -- UAC on win7
+ if winos:version():gt("winxp") then
+ local proc = process.openv("cscript", {path.join(os.programdir(), "scripts", "sudo.vbs"), uninstaller})
+ if proc ~= nil then
+ process.close(proc)
+ end
+ else
+ local proc = process.open(uninstaller)
+ if proc ~= nil then
+ process.close(proc)
+ end
end
else
raise("the uninstaller(%s) not found!", uninstaller)
@@ -147,9 +155,17 @@ function _install(sourcedir, version)
if is_host("windows") then
local installer = "xmake-" .. version .. ".exe"
if os.isfile(installer) then
- local proc = process.open(installer)
- if proc ~= nil then
- process.close(proc)
+ -- UAC on win7
+ if winos:version():gt("winxp") then
+ local proc = process.openv("cscript", {path.join(os.programdir(), "scripts", "sudo.vbs"), installer})
+ if proc ~= nil then
+ process.close(proc)
+ end
+ else
+ local proc = process.open(installer)
+ if proc ~= nil then
+ process.close(proc)
+ end
end
else
raise("the installer(%s) not found!", installer)
@@ -175,7 +191,6 @@ function _install(sourcedir, version)
-- trace
if ok then
cprint("\r${yellow} => ${clear}install to %s .. ${green}ok", os.programdir())
- os.exec("xmake --version")
else
raise("install failed!")
end
@@ -187,6 +202,11 @@ function _install(sourcedir, version)
else
process.asyncrun(install_task)
end
+
+ -- show version
+ if not is_host("windows") then
+ os.exec("xmake --version")
+ end
end
-- main
diff --git a/xmake/scripts/sudo.vbs b/xmake/scripts/sudo.vbs
new file mode 100644
index 000000000..9bc71637c
--- /dev/null
+++ b/xmake/scripts/sudo.vbs
@@ -0,0 +1,15 @@
+Set UAC = CreateObject("Shell.Application")
+Set Shell = CreateObject("WScript.Shell")
+If WScript.Arguments.count < 1 Then
+ WScript.echo "Help: sudo <command> [args]"
+ElseIf WScript.Arguments.count = 1 Then
+ UAC.ShellExecute WScript.arguments(0), "", "", "runas", 1
+Else
+ Dim ucCount
+ Dim args
+ args = NULL
+ For ucCount = 1 To (WScript.Arguments.count - 1) Step 1
+ args = args & " " & WScript.Arguments(ucCount)
+ Next
+ UAC.ShellExecute WScript.arguments(0), args, "", "runas", 5
+End If