environmentService.ts 2.7 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
J
Joao Moreno 已提交
7 8 9 10
import * as paths from 'vs/base/node/paths';
import product from 'vs/platform/product';
import * as os from 'os';
import * as path from 'path';
11
import {ParsedArgs} from 'vs/code/node/argv';
12
import URI from 'vs/base/common/uri';
J
Joao Moreno 已提交
13 14 15

export class EnvironmentService implements IEnvironmentService {

16
	_serviceBrand: any;
J
Joao Moreno 已提交
17

18 19 20
	private _appRoot: string;
	get appRoot(): string { return this._appRoot; }

J
Joao Moreno 已提交
21 22 23
	private _userHome: string;
	get userHome(): string { return this._userHome; }

J
Joao Moreno 已提交
24 25 26
	private _userDataPath: string;
	get userDataPath(): string { return this._userDataPath; }

27 28 29 30 31 32 33 34 35
	private _appSettingsHome: string;
	get appSettingsHome(): string { return this._appSettingsHome; }

	private _appSettingsPath: string;
	get appSettingsPath(): string { return this._appSettingsPath; }

	private _appKeybindingsPath: string;
	get appKeybindingsPath(): string { return this._appKeybindingsPath; }

J
Joao Moreno 已提交
36 37 38
	private _extensionsPath: string;
	get extensionsPath(): string { return this._extensionsPath; }

39 40 41
	private _extensionDevelopmentPath: string;
	get extensionDevelopmentPath(): string { return this._extensionDevelopmentPath; }

42 43 44
	private _debugExtensionHostPort: number;
	get debugExtensionHostPort(): number { return this._debugExtensionHostPort; }

45
	get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
J
Joao Moreno 已提交
46
	get verbose(): boolean { return this.args.verbose; }
47

J
Joao Moreno 已提交
48
	get debugBrkFileWatcherPort(): number { return typeof this.args.debugBrkFileWatcherPort === 'string' ? Number(this.args.debugBrkFileWatcherPort) : void 0; }
J
Joao Moreno 已提交
49

J
Joao Moreno 已提交
50
	constructor(private args: ParsedArgs) {
51
		this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
J
Joao Moreno 已提交
52
		this._userDataPath = args['user-data-dir'] || paths.getDefaultUserDataPath(process.platform);
J
Joao Moreno 已提交
53

54 55 56 57
		this._appSettingsHome = path.join(this.userDataPath, 'User');
		this._appSettingsPath = path.join(this.appSettingsHome, 'settings.json');
		this._appKeybindingsPath = path.join(this.appSettingsHome, 'keybindings.json');

J
Joao Moreno 已提交
58
		this._userHome = path.join(os.homedir(), product.dataFolderName);
J
Joao Moreno 已提交
59
		this._extensionsPath = args.extensionHomePath || path.join(this._userHome, 'extensions');
J
Joao Moreno 已提交
60
		this._extensionsPath = path.normalize(this._extensionsPath);
61

J
Joao Moreno 已提交
62
		this._extensionDevelopmentPath = args.extensionDevelopmentPath;
63 64 65 66

		if (args.debugPluginHost) {
			this._debugExtensionHostPort = Number(args.debugPluginHost);
		}
J
Joao Moreno 已提交
67 68
	}
}