mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 09:42:34 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -3,58 +3,47 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
|
||||
import { IEnvironmentService, ParsedArgs, IDebugParams, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
|
||||
import * as crypto from 'crypto';
|
||||
import * as paths from 'vs/base/node/paths';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { generateUuid, isUUID } from 'vs/base/common/uuid';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import pkg from 'vs/platform/node/package';
|
||||
import product from 'vs/platform/node/product';
|
||||
|
||||
function getUniqueUserId(): string {
|
||||
let username: string;
|
||||
if (process.platform === 'win32') {
|
||||
username = process.env.USERNAME;
|
||||
} else {
|
||||
username = process.env.USER;
|
||||
}
|
||||
|
||||
if (!username) {
|
||||
return ''; // fail gracefully if there is no user name
|
||||
}
|
||||
|
||||
// use sha256 to ensure the userid value can be used in filenames and are unique
|
||||
return crypto.createHash('sha256').update(username).digest('hex').substr(0, 6);
|
||||
}
|
||||
// Read this before there's any chance it is overwritten
|
||||
// Related to https://github.com/Microsoft/vscode/issues/30624
|
||||
const xdgRuntimeDir = process.env['XDG_RUNTIME_DIR'];
|
||||
|
||||
function getNixIPCHandle(userDataPath: string, type: string): string {
|
||||
if (process.env['XDG_RUNTIME_DIR']) {
|
||||
return path.join(process.env['XDG_RUNTIME_DIR'], `${pkg.name}-${pkg.version}-${type}.sock`);
|
||||
if (xdgRuntimeDir) {
|
||||
return path.join(xdgRuntimeDir, `${pkg.name}-${pkg.version}-${type}.sock`);
|
||||
}
|
||||
|
||||
return path.join(userDataPath, `${pkg.version}-${type}.sock`);
|
||||
}
|
||||
|
||||
function getWin32IPCHandle(type: string): string {
|
||||
// Support to run VS Code multiple times as different user
|
||||
// by making the socket unique over the logged in user
|
||||
const userId = getUniqueUserId();
|
||||
const name = product.applicationName + (userId ? `-${userId}` : '');
|
||||
|
||||
return `\\\\.\\pipe\\${name}-${pkg.version}-${type}-sock`;
|
||||
function getWin32IPCHandle(userDataPath: string, type: string): string {
|
||||
const scope = crypto.createHash('md5').update(userDataPath).digest('hex');
|
||||
return `\\\\.\\pipe\\${scope}-${pkg.version}-${type}-sock`;
|
||||
}
|
||||
|
||||
function getIPCHandle(userDataPath: string, type: string): string {
|
||||
if (process.platform === 'win32') {
|
||||
return getWin32IPCHandle(type);
|
||||
return getWin32IPCHandle(userDataPath, type);
|
||||
} else {
|
||||
return getNixIPCHandle(userDataPath, type);
|
||||
}
|
||||
}
|
||||
|
||||
export function getInstallSourcePath(userDataPath: string): string {
|
||||
return path.join(userDataPath, 'installSource');
|
||||
}
|
||||
|
||||
export class EnvironmentService implements IEnvironmentService {
|
||||
|
||||
_serviceBrand: any;
|
||||
@@ -111,7 +100,10 @@ export class EnvironmentService implements IEnvironmentService {
|
||||
get skipGettingStarted(): boolean { return this._args['skip-getting-started']; }
|
||||
|
||||
@memoize
|
||||
get debugExtensionHost(): { port: number; break: boolean; debugId: string } { return parseExtensionHostPort(this._args, this.isBuilt); }
|
||||
get debugExtensionHost(): IExtensionHostDebugParams { return parseExtensionHostPort(this._args, this.isBuilt); }
|
||||
|
||||
@memoize
|
||||
get debugSearch(): IDebugParams { return parseSearchPort(this._args, this.isBuilt); }
|
||||
|
||||
get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
|
||||
get verbose(): boolean { return this._args.verbose; }
|
||||
@@ -139,32 +131,55 @@ export class EnvironmentService implements IEnvironmentService {
|
||||
get sharedIPCHandle(): string { return getIPCHandle(this.userDataPath, 'shared'); }
|
||||
|
||||
@memoize
|
||||
get nodeCachedDataDir(): string { return this.isBuilt ? path.join(this.userDataPath, 'CachedData', product.commit) : undefined; }
|
||||
get nodeCachedDataDir(): string { return this.isBuilt ? path.join(this.userDataPath, 'CachedData', product.commit || new Array(41).join('0')) : undefined; }
|
||||
|
||||
get disableUpdates(): boolean { return !!this._args['disable-updates']; }
|
||||
get disableCrashReporter(): boolean { return !!this._args['disable-crash-reporter']; }
|
||||
|
||||
readonly machineUUID: string;
|
||||
|
||||
readonly installSource: string;
|
||||
|
||||
constructor(private _args: ParsedArgs, private _execPath: string) {
|
||||
const machineIdPath = path.join(this.userDataPath, 'machineid');
|
||||
|
||||
try {
|
||||
this.machineUUID = fs.readFileSync(machineIdPath, 'utf8');
|
||||
|
||||
if (!isUUID(this.machineUUID)) {
|
||||
throw new Error('Not a UUID');
|
||||
}
|
||||
} catch (err) {
|
||||
this.machineUUID = generateUuid();
|
||||
|
||||
try {
|
||||
fs.writeFileSync(machineIdPath, this.machineUUID);
|
||||
fs.writeFileSync(machineIdPath, this.machineUUID, 'utf8');
|
||||
} catch (err) {
|
||||
console.warn('Could not store machine ID');
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.installSource = fs.readFileSync(getInstallSourcePath(this.userDataPath), 'utf8').slice(0, 30);
|
||||
} catch (err) {
|
||||
this.installSource = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): { port: number; break: boolean; debugId: string } {
|
||||
const portStr = args.debugBrkPluginHost || args.debugPluginHost;
|
||||
const port = Number(portStr) || (!isBuild ? 5870 : null);
|
||||
const brk = port ? Boolean(!!args.debugBrkPluginHost) : false;
|
||||
return { port, break: brk, debugId: args.debugId };
|
||||
export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
|
||||
return parseDebugPort(args.debugPluginHost, args.debugBrkPluginHost, 5870, isBuild, args.debugId);
|
||||
}
|
||||
|
||||
export function parseSearchPort(args: ParsedArgs, isBuild: boolean): IDebugParams {
|
||||
return parseDebugPort(args.debugSearch, args.debugBrkSearch, 5876, isBuild);
|
||||
}
|
||||
|
||||
export function parseDebugPort(debugArg: string, debugBrkArg: string, defaultBuildPort: number, isBuild: boolean, debugId?: string): IExtensionHostDebugParams {
|
||||
const portStr = debugBrkArg || debugArg;
|
||||
const port = Number(portStr) || (!isBuild ? defaultBuildPort : null);
|
||||
const brk = port ? Boolean(!!debugBrkArg) : false;
|
||||
return { port, break: brk, debugId };
|
||||
}
|
||||
|
||||
function parsePathArg(arg: string, process: NodeJS.Process): string {
|
||||
|
||||
Reference in New Issue
Block a user