Added command line parameter to set portable

If parameter included, home directory will be copied to the portable
location to make this a portable install
This commit is contained in:
Dave Rael
2015-10-13 05:21:54 -06:00
parent 28c322a4cf
commit 4312f76ed7
3 changed files with 29 additions and 3 deletions

View File

@@ -4,7 +4,26 @@ temp = require "temp"
rimraf = require "rimraf"
AtomPortable = require "../src/browser/atom-portable"
describe "Portable Mode", ->
describe "Set Portable Mode", ->
portableAtomHomePath = path.join(path.dirname(process.execPath), "../.atom").toString()
portableAtomHomeNaturallyExists = fs.existsSync(portableAtomHomePath)
portableAtomHomeBackupPath = portableAtomHomePath + ".temp"
beforeEach ->
fs.renameSync(portableAtomHomePath, portableAtomHomeBackupPath) if fs.existsSync(portableAtomHomePath)
afterEach ->
if portableAtomHomeNaturallyExists
fs.renameSync(portableAtomHomeBackupPath, portableAtomHomePath) if not fs.existsSync(portableAtomHomePath)
else
rimraf.sync(portableAtomHomePath) if fs.existsSync(portableAtomHomePath)
rimraf.sync(portableAtomHomeBackupPath) if fs.existsSync(portableAtomHomeBackupPath)
it "creates portable home directory", ->
AtomPortable.setPortable(process.env.ATOM_HOME)
expect(fs.existsSync(portableAtomHomePath)).toBe true
describe "Check for Portable Mode", ->
describe "Windows", ->
platform = "win32"

View File

@@ -5,7 +5,11 @@ module.exports =
class AtomPortable
@portableAtomHomePath: ->
execDirectoryPath = path.dirname(process.execPath)
return path.join(execDirectoryPath, "../.atom")
return path.join(execDirectoryPath, "../.atom/")
@setPortable: (existingAtomHome) ->
fs.copySync(existingAtomHome, @portableAtomHomePath())
@isPortableInstall: (platform, environmentAtomHome) ->
return false unless platform is 'win32'
return false if environmentAtomHome

View File

@@ -61,6 +61,7 @@ setupAtomHome = (args) ->
return if process.env.ATOM_HOME
atomHome = path.join(app.getHomeDir(), '.atom')
AtomPortable = require './atom-portable'
AtomPortable.setPortable(atomHome) if not AtomPortable.isPortableInstall(process.platform, process.env.ATOM_HOME) and args.setPortable
atomHome = AtomPortable.portableAtomHomePath() if AtomPortable.isPortableInstall process.platform, process.env.ATOM_HOME
atomHome = fs.realpathSync(atomHome)
fs.statSync(atomHome)
@@ -107,6 +108,7 @@ parseCommandLine = ->
options.alias('t', 'test').boolean('t').describe('t', 'Run the specified specs and exit with error code on failures.')
options.alias('v', 'version').boolean('v').describe('v', 'Print the version.')
options.alias('w', 'wait').boolean('w').describe('w', 'Wait for window to be closed before returning.')
options.alias('p', 'set-portable').boolean('p').describe('p', 'Set portable mode.')
options.string('socket-path')
args = options.argv
@@ -132,6 +134,7 @@ parseCommandLine = ->
profileStartup = args['profile-startup']
urlsToOpen = []
devResourcePath = process.env.ATOM_DEV_RESOURCE_PATH ? path.join(app.getHomeDir(), 'github', 'atom')
setPortable = args['set-portable']
if args['resource-path']
devMode = true
@@ -161,6 +164,6 @@ parseCommandLine = ->
{resourcePath, devResourcePath, pathsToOpen, urlsToOpen, executedFrom, test,
version, pidToKillWhenClosed, devMode, safeMode, newWindow, specDirectory,
logFile, socketPath, profileStartup}
logFile, socketPath, profileStartup, setPortable}
start()