Add command line parameter to set portable

If parameter included, home directory will be copied to the portable
This commit is contained in:
Dave Rael
2015-10-20 10:57:04 -06:00
committed by Kevin Sawicki
parent 8b76c3d57c
commit e3da370d82
3 changed files with 28 additions and 2 deletions

View File

@@ -4,6 +4,25 @@ temp = require "temp"
rimraf = require "rimraf"
AtomPortable = require "../src/browser/atom-portable"
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", ->
describe "with ATOM_HOME environment variable", ->

View File

@@ -8,6 +8,9 @@ class AtomPortable
execDirectoryPath = path.dirname(process.execPath)
path.join(execDirectoryPath, '..', '.atom')
@setPortable: (existingAtomHome) ->
fs.copySync(existingAtomHome, @getPortableAtomHomePath())
@isPortableInstall: (platform, environmentAtomHome, defaultHome) ->
return false unless platform is 'win32'
return false if environmentAtomHome

View File

@@ -61,7 +61,9 @@ setupAtomHome = ->
return if process.env.ATOM_HOME
atomHome = path.join(app.getHomeDir(), '.atom')
AtomPortable = require './atom-portable'
atomHome = AtomPortable.getPortableAtomHomePath() if AtomPortable.isPortableInstall(process.platform, process.env.ATOM_HOME, atomHome)
AtomPortable.setPortable(atomHome) if not AtomPortable.isPortableInstall(process.platform, process.env.ATOM_HOME, atomHome) and args.setPortable
atomHome = AtomPortable.getPortableAtomHomePath() if AtomPortable.isPortableInstall process.platform, process.env.ATOM_HOME, atomHome
try
atomHome = fs.realpathSync(atomHome)
process.env.ATOM_HOME = atomHome
@@ -106,6 +108,7 @@ parseCommandLine = ->
options.string('timeout').describe('timeout', 'When in test mode, waits until the specified time (in minutes) and kills the process (exit code: 130).')
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
@@ -131,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
@@ -151,6 +155,6 @@ parseCommandLine = ->
{resourcePath, devResourcePath, pathsToOpen, urlsToOpen, executedFrom, test,
version, pidToKillWhenClosed, devMode, safeMode, newWindow,
logFile, socketPath, profileStartup, timeout}
logFile, socketPath, profileStartup, timeout, setPortable}
start()