提交 b43c9501 编写于 作者: B Benjamin Pasero

polish

上级 17d66171
......@@ -95,13 +95,16 @@ function getNLSConfiguration() {
return { locale: initialLocale, availableLanguages: {} };
}
// Change cwd if given via env variable
// Update cwd based on environment and platform
try {
if (process.env.VSCODE_CWD) {
if (process.platform === 'win32') {
process.env.VSCODE_CWD = process.cwd(); // remember as environment variable
process.chdir(path.dirname(app.getPath('exe'))); // always set application folder as cwd
} else if (process.env.VSCODE_CWD) {
process.chdir(process.env.VSCODE_CWD);
}
} catch (err) {
// noop
console.error(err);
}
// Set path according to being built or not
......@@ -121,12 +124,12 @@ args.forEach(function (arg) {
// Mac: when someone drops a file to the not-yet running VSCode, the open-file event fires even before
// the app-ready event. We listen very early for open-file and remember this upon startup as path to open.
global.macOpenFiles = [];
app.on('open-file', function(event, path) {
app.on('open-file', function (event, path) {
global.macOpenFiles.push(path);
});
// Load our code once ready
app.once('ready', function() {
app.once('ready', function () {
var nlsConfig = getNLSConfiguration();
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
require('./bootstrap-amd').bootstrap('vs/workbench/electron-main/main');
......
......@@ -64,6 +64,8 @@ export const isBuilt = !process.env.VSCODE_DEV;
export const appRoot = path.dirname(uri.parse(require.toUrl('')).fsPath);
export const currentWorkingDirectory = process.env.VSCODE_CWD || process.cwd();
let productContents: IProductConfiguration;
try {
productContents = JSON.parse(fs.readFileSync(path.join(appRoot, 'product.json'), 'utf8'));
......@@ -280,7 +282,7 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] {
}
if (pathCandidate) {
pathCandidate = massagePath(pathCandidate);
pathCandidate = preparePath(pathCandidate);
}
let realPath: string;
......@@ -289,7 +291,7 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] {
} catch (error) {
// in case of an error, assume the user wants to create this file
// if the path is relative, we join it to the cwd
realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(process.cwd(), pathCandidate));
realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(currentWorkingDirectory, pathCandidate));
}
if (!paths.isValidBasename(path.basename(realPath))) {
......@@ -310,30 +312,32 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] {
);
}
function massagePath(path: string): string {
function preparePath(p: string): string {
// Trim trailing quotes
if (platform.isWindows) {
path = strings.rtrim(path, '"'); // https://github.com/Microsoft/vscode/issues/1498
p = strings.rtrim(p, '"'); // https://github.com/Microsoft/vscode/issues/1498
}
// Trim whitespaces
path = strings.trim(strings.trim(path, ' '), '\t');
p = strings.trim(strings.trim(p, ' '), '\t');
// Trim '.' chars on Windows to prevent invalid file names
if (platform.isWindows) {
path = strings.rtrim(resolvePath(path), '.');
// Resolve the path against cwd if it is relative
p = path.resolve(currentWorkingDirectory, p);
// Trim trailing '.' chars on Windows to prevent invalid file names
p = strings.rtrim(p, '.');
}
return path;
return p;
}
function normalizePath(p?: string): string {
return p ? path.normalize(p) : p;
}
function resolvePath(p?: string): string {
return p ? path.resolve(p): p;
}
function parseNumber(argv: string[], key: string, defaultValue?: number, fallbackValue?: number): number {
let value: number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册