Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function findHyper(): Promise {
const hyper = enumerateValues(
HKEY.HKEY_CURRENT_USER,
'Software\\Classes\\Directory\\Background\\shell\\Hyper\\command'
)
if (hyper.length === 0) {
return null
}
const first = hyper[0]
if (first.type === RegistryValueType.REG_SZ) {
// Registry key is structured as "{installationPath}\app-x.x.x\Hyper.exe" "%V"
// This regex is designed to get the path to the version-specific Hyper.
// commandPieces = ['"{installationPath}\app-x.x.x\Hyper.exe"', '"', '{installationPath}\app-x.x.x\Hyper.exe', ...]
const commandPieces = first.data.match(/(["'])(.*?)\1/)
const localAppData = process.env.LocalAppData
},
// 64-bit version of SlickEdit Pro 2017
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{15406187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 32-bit version of SlickEdit Pro 2017
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{15006187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 64-bit version of SlickEdit Pro 2016 (21.0.1)
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{10C06187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 64-bit version of SlickEdit Pro 2016 (21.0.0)
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{10406187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 64-bit version of SlickEdit Pro 2015 (20.0.3)
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0DC06187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 64-bit version of SlickEdit Pro 2015 (20.0.2)
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0D406187-F49E-4822-CAF2-1D25C0C83BA2}',
},
// 64-bit version of SlickEdit Pro 2014 (19.0.2)
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{7CC0E567-ACD6-41E8-95DA-154CEEDB0A18}',
},
]
case ExternalEditor.Webstorm:
return [
// 32-bit version of WebStorm
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\WebStorm 2018.3',
},
]
default:
return assertNever(editor, `Unknown external editor: ${editor}`)
}
}
async function findPowerShell(): Promise {
const powerShell = enumerateValues(
HKEY.HKEY_LOCAL_MACHINE,
'Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\PowerShell.exe'
)
if (powerShell.length === 0) {
return null
}
const first = powerShell[0]
// NOTE:
// on Windows 7 these are both REG_SZ, which technically isn't supposed
// to contain unexpanded references to environment variables. But given
// it's also %SystemRoot% and we do the expanding here I think this is
// a fine workaround to do to support the maximum number of setups.
if (
const publisher = getKeyOrEmpty(keys, 'Publisher')
const installLocation = getKeyOrEmpty(keys, 'InstallLocation')
return { displayName, publisher, installLocation }
}
if (editor === ExternalEditor.Webstorm) {
let displayName = ''
let publisher = ''
let installLocation = ''
for (const item of keys) {
// NOTE:
// Webstorm adds the current release number to the end of the Display Name, below checks for "WebStorm"
if (
item.name === 'DisplayName' &&
item.type === RegistryValueType.REG_SZ &&
item.data.startsWith('WebStorm ')
) {
displayName = 'WebStorm'
} else if (
item.name === 'Publisher' &&
item.type === RegistryValueType.REG_SZ
) {
publisher = item.data
} else if (
item.name === 'InstallLocation' &&
item.type === RegistryValueType.REG_SZ
) {
installLocation = item.data
}
}
// NOTE:
// Webstorm adds the current release number to the end of the Display Name, below checks for "WebStorm"
if (
item.name === 'DisplayName' &&
item.type === RegistryValueType.REG_SZ &&
item.data.startsWith('WebStorm ')
) {
displayName = 'WebStorm'
} else if (
item.name === 'Publisher' &&
item.type === RegistryValueType.REG_SZ
) {
publisher = item.data
} else if (
item.name === 'InstallLocation' &&
item.type === RegistryValueType.REG_SZ
) {
installLocation = item.data
}
}
return { displayName, publisher, installLocation }
}
return assertNever(editor, `Unknown external editor: ${editor}`)
}
function getRegistryKeys(
editor: ExternalEditor
): ReadonlyArray<{ key: HKEY; subKey: string }> {
switch (editor) {
case ExternalEditor.Atom:
return [
{
key: HKEY.HKEY_CURRENT_USER,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\atom',
},
]
case ExternalEditor.AtomBeta:
return [
{
key: HKEY.HKEY_CURRENT_USER,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\atom-beta',
},
]
case ExternalEditor.AtomNightly:
return [
{
key: HKEY.HKEY_CURRENT_USER,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\atom-nightly',
},
]
case ExternalEditor.VisualStudioCode:
return [
// 64-bit version of VSCode (user) - provided by default in 64-bit Windows
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1',
},
]
case ExternalEditor.VisualStudioCodeInsiders:
return [
// 64-bit version of VSCode (user) - provided by default in 64-bit Windows
{
key: HKEY.HKEY_CURRENT_USER,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{217B4C08-948D-4276-BFBB-BEE930AE5A2C}_is1',
},
// 32-bit version of VSCode (user)
{
key: HKEY.HKEY_CURRENT_USER,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{26F4A15E-E392-4887-8C09-7BC55712FD5B}_is1',
},
// 64-bit version of VSCode (system) - was default before user scope installation
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1',
},
// 32-bit version of VSCode (system)
{
key: HKEY.HKEY_LOCAL_MACHINE,
subKey:
'SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1',
},
]
async function findHyper(): Promise {
const hyper = enumerateValues(
HKEY.HKEY_CURRENT_USER,
'Software\\Classes\\Directory\\Background\\shell\\Hyper\\command'
)
if (hyper.length === 0) {
return null
}
const first = hyper[0]
if (first.type === RegistryValueType.REG_SZ) {
// Registry key is structured as "{installationPath}\app-x.x.x\Hyper.exe" "%V"
// This regex is designed to get the path to the version-specific Hyper.
// commandPieces = ['"{installationPath}\app-x.x.x\Hyper.exe"', '"', '{installationPath}\app-x.x.x\Hyper.exe', ...]
const commandPieces = first.data.match(/(["'])(.*?)\1/)
const localAppData = process.env.LocalAppData
)
if (powerShell.length === 0) {
return null
}
const first = powerShell[0]
// NOTE:
// on Windows 7 these are both REG_SZ, which technically isn't supposed
// to contain unexpanded references to environment variables. But given
// it's also %SystemRoot% and we do the expanding here I think this is
// a fine workaround to do to support the maximum number of setups.
if (
first.type === RegistryValueType.REG_EXPAND_SZ ||
first.type === RegistryValueType.REG_SZ
) {
const path = first.data.replace(
/^%SystemRoot%/i,
process.env.SystemRoot || 'C:\\Windows'
)
if (await pathExists(path)) {
return path
} else {
log.debug(
`[PowerShell] registry entry found but does not exist at '${path}'`
)
}
}