From d931299b9f9ffcaaa3a9538d318eaf7d13696582 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Jan 2014 21:55:49 +0800 Subject: [PATCH] Create shortcut on Desktop. --- build/tasks/install-task.coffee | 10 ++++++++-- script/copy-folder.cmd | 2 +- script/create-shortcut.cmd | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 script/create-shortcut.cmd diff --git a/build/tasks/install-task.coffee b/build/tasks/install-task.coffee index ee7e7156a..a2b591734 100644 --- a/build/tasks/install-task.coffee +++ b/build/tasks/install-task.coffee @@ -1,18 +1,24 @@ path = require 'path' module.exports = (grunt) -> - {cp, mkdir, rm} = require('./task-helpers')(grunt) + {cp, mkdir, rm, spawn} = require('./task-helpers')(grunt) grunt.registerTask 'install', 'Install the built application', -> installDir = grunt.config.get('atom.installDir') shellAppDir = grunt.config.get('atom.shellAppDir') if process.platform is 'win32' + done = @async() + 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}") + done("Failed to copy #{shellAppDir} to #{installDir}") + + createShortcut = path.resolve 'script', 'create-shortcut.cmd' + args = ['/c', createShortcut, path.join(installDir, 'atom.exe'), 'Atom'] + spawn {cmd: 'cmd', args}, done else rm installDir mkdir path.dirname(installDir) diff --git a/script/copy-folder.cmd b/script/copy-folder.cmd index 532675ca2..b17473992 100644 --- a/script/copy-folder.cmd +++ b/script/copy-folder.cmd @@ -1,6 +1,6 @@ @echo off -set USAGE="Usage: %0 source destination" +set USAGE=Usage: %0 source destination if [%1] == [] ( echo %USAGE% diff --git a/script/create-shortcut.cmd b/script/create-shortcut.cmd new file mode 100644 index 000000000..ca295d434 --- /dev/null +++ b/script/create-shortcut.cmd @@ -0,0 +1,23 @@ +@echo off + +set USAGE=Usage: %0 source name-on-desktop + +if [%1] == [] ( + echo %USAGE% + exit 1 +) +if [%2] == [] ( + echo %USAGE% + exit 2 +) + +set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs" + +echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT% +echo sLinkFile = "%USERPROFILE%\Desktop\%2.lnk" >> %SCRIPT% +echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT% +echo oLink.TargetPath = %1 >> %SCRIPT% +echo oLink.Save >> %SCRIPT% + +cscript /nologo %SCRIPT% +del %SCRIPT%