From b1778aa7dfc26a24451bad3fc17592b461228a61 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Jan 2014 21:07:32 +0800 Subject: [PATCH] Use administrator power to install Atom on Windows. --- build/package.json | 1 + build/tasks/install-task.coffee | 14 +++++++++++--- script/copy-folder.cmd | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 script/copy-folder.cmd diff --git a/build/package.json b/build/package.json index 836679d8c..14b1437e4 100644 --- a/build/package.json +++ b/build/package.json @@ -30,6 +30,7 @@ "rcedit": "~0.1.2", "request": "~2.27.0", "rimraf": "~2.2.2", + "runas": "~0.3.0", "unzip": "~0.1.9", "vm-compatibility-layer": "~0.1.0", "walkdir": "0.0.7" diff --git a/build/tasks/install-task.coffee b/build/tasks/install-task.coffee index 23cae1bb9..ee7e7156a 100644 --- a/build/tasks/install-task.coffee +++ b/build/tasks/install-task.coffee @@ -6,6 +6,14 @@ module.exports = (grunt) -> grunt.registerTask 'install', 'Install the built application', -> installDir = grunt.config.get('atom.installDir') shellAppDir = grunt.config.get('atom.shellAppDir') - rm installDir - mkdir path.dirname(installDir) - cp shellAppDir, installDir + if process.platform is 'win32' + runas = require 'runas' + copyFolder = path.resolve 'script', 'copy-folder.cmd' + # cmd /c ""script" "source" "destination"" + arg = "/c \"\"#{copyFolder}\" \"#{shellAppDir}\" \"#{installDir}\"\"" + if runas('cmd', [arg], hide: true) isnt 0 + throw new Error("Failed to copy #{shellAppDir} to #{installDir}") + else + rm installDir + mkdir path.dirname(installDir) + cp shellAppDir, installDir diff --git a/script/copy-folder.cmd b/script/copy-folder.cmd new file mode 100644 index 000000000..532675ca2 --- /dev/null +++ b/script/copy-folder.cmd @@ -0,0 +1,18 @@ +@echo off + +set USAGE="Usage: %0 source destination" + +if [%1] == [] ( + echo %USAGE% + exit 1 +) +if [%2] == [] ( + echo %USAGE% + exit 2 +) + +:: rm -rf %2 +if exist %2 rmdir %2 /s /q + +:: cp -rf %1 %2 +xcopy %1 %2 /e /h /c /i /y /r