diff --git a/src/extension.ts b/src/extension.ts index 53f37932b4..b220bf2d95 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -485,7 +485,7 @@ class ExtensionManager implements vscode.Disposable { await scanForKitsIfNeeded(cmt); let should_configure = cmt.workspaceContext.config.configureOnOpen; - if (should_configure === null && process.env['CMT_TESTING'] !== '1') { + if (should_configure === null && util.envGetValue(process.env, 'CMT_TESTING') !== '1') { interface Choice1 { title: string; doConfigure: boolean; @@ -858,7 +858,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to select an active kit */ async selectKit(folder?: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('selecting.kit.in.test.mode', 'Running CMakeTools in test mode. selectKit is disabled.')); return false; } @@ -1326,7 +1326,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to add an active configure preset */ async addConfigurePreset(folder: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('add.config.preset.in.test.mode', 'Running CMakeTools in test mode. addConfigurePreset is disabled.')); return false; } @@ -1343,7 +1343,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to add an active build preset */ async addBuildPreset(folder: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('add.build.preset.in.test.mode', 'Running CMakeTools in test mode. addBuildPreset is disabled.')); return false; } @@ -1360,7 +1360,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to add an active test preset */ async addTestPreset(folder: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('add.test.preset.in.test.mode', 'Running CMakeTools in test mode. addTestPreset is disabled.')); return false; } @@ -1378,7 +1378,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to select an active configure preset */ async selectConfigurePreset(folder?: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('selecting.config.preset.in.test.mode', 'Running CMakeTools in test mode. selectConfigurePreset is disabled.')); return false; } @@ -1406,7 +1406,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to select an active build preset */ async selectBuildPreset(folder?: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('selecting.build.preset.in.test.mode', 'Running CMakeTools in test mode. selectBuildPreset is disabled.')); return false; } @@ -1428,7 +1428,7 @@ class ExtensionManager implements vscode.Disposable { * Show UI to allow the user to select an active test preset */ async selectTestPreset(folder?: vscode.WorkspaceFolder): Promise { - if (process.env['CMT_TESTING'] === '1') { + if (util.envGetValue(process.env, 'CMT_TESTING') === '1') { log.trace(localize('selecting.test.preset.in.test.mode', 'Running CMakeTools in test mode. selectTestPreset is disabled.')); return false; } diff --git a/src/installs/visual-studio.ts b/src/installs/visual-studio.ts index c007a840b0..887cbe217c 100644 --- a/src/installs/visual-studio.ts +++ b/src/installs/visual-studio.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import * as logging from '../logging'; import * as proc from '../proc'; -import {thisExtensionPath} from '../util'; +import {envGetValue, thisExtensionPath} from '../util'; import * as nls from 'vscode-nls'; @@ -61,7 +61,7 @@ export async function vsInstallations(): Promise { const installs = [] as VSInstallation[]; const inst_ids = [] as string[]; const vswhere_exe = path.join(thisExtensionPath(), 'res', 'vswhere.exe'); - const sys32_path = path.join(process.env.WINDIR as string, 'System32'); + const sys32_path = path.join(envGetValue(process.env, 'WINDIR') ?? 'C:\\Windows', 'System32'); const vswhere_args = ['/c', `${sys32_path}\\chcp 65001>nul && "${vswhere_exe}" -all -format json -utf8 -products * -legacy -prerelease`]; diff --git a/src/logging.ts b/src/logging.ts index 903dfc29a6..5ef42bd058 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -151,7 +151,7 @@ class SingletonLogger { case LogLevel.Debug: case LogLevel.Info: case LogLevel.Note: - if (process.env['CMT_QUIET_CONSOLE'] !== '1') { + if (util.envGetValue(process.env, 'CMT_QUIET_CONSOLE') !== '1') { // tslint:disable-next-line console.info('[CMakeTools]', raw_message); } diff --git a/src/paths.ts b/src/paths.ts index 2a2249f546..24bd145b6c 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -18,19 +18,19 @@ interface VSCMakePaths { class WindowsEnvironment { get AppData(): string | undefined { - return process.env['APPDATA']; + return util.envGetValue(process.env, 'APPDATA'); } get LocalAppData(): string | undefined { - return process.env['LOCALAPPDATA']; + return util.envGetValue(process.env, 'LOCALAPPDATA'); } get AllUserProfile(): string | undefined { - return process.env['ProgramData']; + return util.envGetValue(process.env, 'ProgramData'); } get ComSpec(): string { - let comSpec = process.env['ComSpec']; + let comSpec = util.envGetValue(process.env, 'ComSpec'); if (undefined === comSpec) { comSpec = this.SystemRoot! + '\\system32\\cmd.exe'; @@ -40,31 +40,31 @@ class WindowsEnvironment { } get HomeDrive(): string | undefined { - return process.env['HOMEDRIVE']; + return util.envGetValue(process.env, 'HOMEDRIVE'); } get HomePath(): string | undefined { - return process.env['HOMEPATH']; + return util.envGetValue(process.env, 'HOMEPATH'); } get ProgramFilesX86(): string | undefined { - return process.env['ProgramFiles(x86)']; + return util.envGetValue(process.env, 'ProgramFiles(x86)'); } get ProgramFiles(): string | undefined { - return process.env['ProgramFiles']; + return util.envGetValue(process.env, 'ProgramFiles'); } get SystemDrive(): string | undefined { - return process.env['SystemDrive']; + return util.envGetValue(process.env, 'SystemDrive'); } get SystemRoot(): string | undefined { - return process.env['SystemRoot']; + return util.envGetValue(process.env, 'SystemRoot'); } get Temp(): string | undefined { - return process.env['TEMP']; + return util.envGetValue(process.env, 'TEMP'); } } @@ -81,9 +81,9 @@ class Paths { */ get userHome(): string { if (process.platform === 'win32') { - return path.join(process.env['HOMEDRIVE'] || 'C:', process.env['HOMEPATH'] || 'Users\\Public'); + return path.join(util.envGetValue(process.env, 'HOMEDRIVE') ?? 'C:', util.envGetValue(process.env, 'HOMEPATH') ?? 'Users\\Public'); } else { - return process.env['HOME'] || process.env['PROFILE']!; + return util.envGetValue(process.env, 'HOME') ?? util.envGetValue(process.env, 'PROFILE') ?? '/root'; } } @@ -95,7 +95,7 @@ class Paths { if (process.platform == 'win32') { return this.windows.LocalAppData!; } else { - const xdg_dir = process.env['XDG_DATA_HOME']; + const xdg_dir = util.envGetValue(process.env, 'XDG_DATA_HOME'); if (xdg_dir) { return xdg_dir; } @@ -108,7 +108,7 @@ class Paths { if (process.platform == 'win32') { return this.windows.AppData!; } else { - const xdg_dir = process.env['XDG_CONFIG_HOME']; + const xdg_dir = util.envGetValue(process.env, 'XDG_CONFIG_HOME'); if (xdg_dir) { return xdg_dir; }