44 *--------------------------------------------------------------------------------------------*/
55'use strict' ;
66
7- let perf = require ( './vs/base/common/performance' ) ;
7+ const perf = require ( './vs/base/common/performance' ) ;
88perf . mark ( 'main:started' ) ;
99
1010// Perf measurements
1111global . perfStartTime = Date . now ( ) ;
1212
1313Error . stackTraceLimit = 100 ; // increase number of stack frames (from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
1414
15+ const fs = require ( 'fs' ) ;
16+ const path = require ( 'path' ) ;
17+ const product = require ( '../product.json' ) ;
18+ const appRoot = path . dirname ( __dirname ) ;
19+
20+ function getApplicationPath ( ) {
21+ if ( process . env [ 'VSCODE_DEV' ] ) {
22+ return appRoot ;
23+ } else if ( process . platform === 'darwin' ) {
24+ return path . dirname ( path . dirname ( path . dirname ( appRoot ) ) ) ;
25+ } else {
26+ return path . dirname ( path . dirname ( appRoot ) ) ;
27+ }
28+ }
29+
30+ function getPortableDataPath ( ) {
31+ return path . join ( path . dirname ( getApplicationPath ( ) ) , product . portable ) ;
32+ }
33+
34+ if ( product . portable ) {
35+ const portablePath = getPortableDataPath ( ) ;
36+ try { fs . mkdirSync ( portablePath ) ; } catch ( err ) { if ( err . code !== 'EEXIST' ) { throw err ; } }
37+
38+ const tmpdir = path . join ( portablePath , 'tmp' ) ;
39+ try { fs . mkdirSync ( tmpdir ) ; } catch ( err ) { if ( err . code !== 'EEXIST' ) { throw err ; } }
40+
41+ process . env [ process . platform === 'win32' ? 'TEMP' : 'TMPDIR' ] = tmpdir ;
42+ }
43+
1544//#region Add support for using node_modules.asar
1645( function ( ) {
1746 const path = require ( 'path' ) ;
@@ -36,18 +65,15 @@ Error.stackTraceLimit = 100; // increase number of stack frames (from 10, https:
3665} ) ( ) ;
3766//#endregion
3867
39- let app = require ( 'electron' ) . app ;
68+ const app = require ( 'electron' ) . app ;
4069
4170// TODO@Ben Electron 2.0.x: prevent localStorage migration from SQLite to LevelDB due to issues
4271app . commandLine . appendSwitch ( 'disable-mojo-local-storage' ) ;
4372
44- let fs = require ( 'fs' ) ;
45- let path = require ( 'path' ) ;
46- let minimist = require ( 'minimist' ) ;
47- let paths = require ( './paths' ) ;
48- let product = require ( '../product.json' ) ;
73+ const minimist = require ( 'minimist' ) ;
74+ const paths = require ( './paths' ) ;
4975
50- let args = minimist ( process . argv , {
76+ const args = minimist ( process . argv , {
5177 string : [
5278 'user-data-dir' ,
5379 'locale' ,
@@ -350,9 +376,16 @@ function getNodeCachedDataDir() {
350376}
351377//#endregion
352378
379+ function getUserDataPath ( ) {
380+ if ( product . portable ) {
381+ return path . join ( getPortableDataPath ( ) , 'user-data' ) ;
382+ }
383+
384+ return path . resolve ( args [ 'user-data-dir' ] || paths . getDefaultUserDataPath ( process . platform ) ) ;
385+ }
386+
353387// Set userData path before app 'ready' event and call to process.chdir
354- let userData = path . resolve ( args [ 'user-data-dir' ] || paths . getDefaultUserDataPath ( process . platform ) ) ;
355- app . setPath ( 'userData' , userData ) ;
388+ app . setPath ( 'userData' , getUserDataPath ( ) ) ;
356389
357390// Update cwd based on environment and platform
358391try {
0 commit comments