Implement Portable Mode

According to these specifications:
Portable mode only applies to Windows (for now)
Portable mode only applies if ATOM_HOME is not set
If there is a .atom directory as sibling to directory with running process
	use that as ATOM_HOME
This commit is contained in:
Dave Rael
2015-10-09 10:54:30 -06:00
parent f067fdb7cd
commit b8a153781e
3 changed files with 71 additions and 14 deletions

View File

@@ -0,0 +1,15 @@
fs = require 'fs-plus'
path = require 'path'
module.exports =
class AtomPortable
@portableAtomHomePath: ->
execDirectoryPath = path.dirname(process.execPath)
return path.join(execDirectoryPath, "../.atom")
@isPortableInstall: (platform, environmentAtomHome) ->
return false unless platform is 'win32'
return false if environmentAtomHome
# currently checking only that the directory exists, probably want to do
# some integrity checks on contents and make sure it's writable in future
return fs.existsSync(@portableAtomHomePath())

View File

@@ -57,23 +57,13 @@ handleStartupEventWithSquirrel = ->
setupCrashReporter = ->
crashReporter.start(productName: 'Atom', companyName: 'GitHub')
isPortableInstall = (args) ->
return false unless process.platform is 'win32'
return false unless (process and process.type)
return false if args.devMode or args.testMode
ourPath = process.execPath.toLowerCase()
return (ourPath.indexOf(process.env.LOCALAPPDATA.toLowerCase()) is 0)
setupAtomHome = (args) ->
return if process.env.ATOM_HOME
atomHome = path.join(app.getHomeDir(), '.atom')
try
atomHome = fs.realpathSync(atomHome)
fs.statSync(atomHome)
catch
atomHome = path.join(path.dirname(process.execPath), '.atom') if isPortableInstall(args)
AtomPortable = require './atom-portable'
atomHome = AtomPortable.portableAtomHomePath() if AtomPortable.isPortableInstall process.platform, process.env.ATOM_HOME
atomHome = fs.realpathSync(atomHome)
fs.statSync(atomHome)
process.env.ATOM_HOME = atomHome