From c5d7614d8017e3d9ee02061cb19cd8372c29c59c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Jan 2014 19:22:13 +0800 Subject: [PATCH 1/3] Use named pipe instead of socket file on Windows. --- src/browser/atom-application.coffee | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 5daea762c..bca05312e 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -15,7 +15,11 @@ url = require 'url' {EventEmitter} = require 'events' _ = require 'underscore-plus' -socketPath = path.join(os.tmpdir(), 'atom.sock') +socketPath = + if process.platform is 'win32' + '\\\\.\\pipe\\atom-sock' + else + path.join(os.tmpdir(), 'atom.sock') # Private: The application's singleton class. # @@ -35,7 +39,7 @@ class AtomApplication # take a few seconds to trigger 'error' event, it could be a bug of node # or atom-shell, before it's fixed we check the existence of socketPath to # speedup startup. - if (not fs.existsSync socketPath) or options.test + if (process.platform isnt 'win32' and not fs.existsSync socketPath) or options.test createAtomApplication() return @@ -99,7 +103,8 @@ class AtomApplication # the other launches will just pass their information to this server and then # close immediately. listenForArgumentsFromNewProcess: -> - fs.unlinkSync socketPath if fs.existsSync(socketPath) + if process.platform isnt 'win32' and fs.existsSync(socketPath) + fs.unlinkSync socketPath server = net.createServer (connection) => connection.on 'data', (data) => @openWithOptions(JSON.parse(data)) @@ -152,7 +157,9 @@ class AtomApplication app.quit() if process.platform is 'win32' app.on 'will-quit', => - fs.unlinkSync socketPath if fs.existsSync(socketPath) # Clean the socket file when quit normally. + # Clean the socket file when quit normally. + if process.platform isnt 'win32' and fs.existsSync(socketPath) + fs.unlinkSync socketPath app.on 'open-file', (event, pathToOpen) => event.preventDefault() From b1778aa7dfc26a24451bad3fc17592b461228a61 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Jan 2014 21:07:32 +0800 Subject: [PATCH 2/3] 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 From d931299b9f9ffcaaa3a9538d318eaf7d13696582 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Jan 2014 21:55:49 +0800 Subject: [PATCH 3/3] 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%