VC runtime detection changes
This commit is contained in:
144
src/helpers.js
144
src/helpers.js
@@ -8,6 +8,60 @@ const spawn = require('child_process').spawn;
|
||||
const Constants = require('./constants');
|
||||
const RandomString = require('randomstring');
|
||||
|
||||
let vcRuntimeExists;
|
||||
|
||||
const _vcRuntimeExists = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (os.platform() !== 'win32') {
|
||||
reject('Windows OS is not being used');
|
||||
} else {
|
||||
if (vcRuntimeExists) {
|
||||
resolve(true);
|
||||
} else {
|
||||
const cmd = path.join(process.env.windir, 'system32', 'reg.exe');
|
||||
const args = ["QUERY", "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"];
|
||||
_execProcessGetOutput(cmd, null, args)
|
||||
.then(lines => {
|
||||
const parseLine = index => {
|
||||
if (index < lines.length) {
|
||||
const line = lines[index];
|
||||
if (line.startsWith('HKEY_LOCAL_MACHINE\\')) {
|
||||
let args2 = JSON.parse(JSON.stringify(args));
|
||||
args2[1] = 'HKLM\\' + line.substr(19);
|
||||
args2.push('/v');
|
||||
args2.push('DisplayName');
|
||||
args2.push('/t');
|
||||
args2.push('REG_SZ');
|
||||
_execProcessGetOutput(cmd, null, args2)
|
||||
.then(lines => {
|
||||
const value = lines[2].trim().substr(args2[3].length).trim().substr(6).trim();
|
||||
if (value.includes('Microsoft Visual C++ 2015-2019 Redistributable (x64)')) {
|
||||
vcRuntimeExists = true;
|
||||
resolve(true);
|
||||
} else {
|
||||
parseLine(++index);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
parseLine(++index);
|
||||
});
|
||||
} else {
|
||||
parseLine(++index);
|
||||
}
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
};
|
||||
parseLine(0);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const _executeProcess = (command, working, args=[]) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let processOptions = {
|
||||
@@ -542,51 +596,65 @@ module.exports.getMissingDependencies = dependencies => {
|
||||
};
|
||||
|
||||
const Registry = require('winreg');
|
||||
const checkRegistry = (dep, index) => {
|
||||
const checkRegistry = (dep, index, legacyRuntimeDetection) => {
|
||||
if (index >= dep.registry.length) {
|
||||
missing.push(dep);
|
||||
resolveIfComplete();
|
||||
} else {
|
||||
let hive = null;
|
||||
const hiveName = dep.registry[index].split('\\')[0];
|
||||
switch (hiveName) {
|
||||
case 'HKEY_CLASSES_ROOT':
|
||||
hive = Registry.HKCR;
|
||||
break;
|
||||
case 'HKEY_CURRENT_CONFIG':
|
||||
hive = Registry.HKCC;
|
||||
break;
|
||||
case 'HKEY_CURRENT_USER':
|
||||
hive = Registry.HKCU;
|
||||
break;
|
||||
case 'HKEY_LOCAL_MACHINE':
|
||||
hive = Registry.HKLM;
|
||||
break;
|
||||
case 'HKEY_USERS':
|
||||
hive = Registry.HKU;
|
||||
break;
|
||||
default:
|
||||
throw Error('Invalid registry hive: ' + hiveName);
|
||||
}
|
||||
|
||||
const key = dep.registry[index].substr(hiveName.length);
|
||||
const regKey = new Registry({
|
||||
hive: hive,
|
||||
key: key
|
||||
});
|
||||
regKey.valueExists('DisplayName', (err, exists) => {
|
||||
if (err || !exists) {
|
||||
regKey.valueExists('ProductName', (err, exists) => {
|
||||
if (err || !exists) {
|
||||
checkRegistry(dep, ++index);
|
||||
} else {
|
||||
if (!legacyRuntimeDetection && (dep.display === 'VC Runtime 2015-2019')) {
|
||||
_vcRuntimeExists()
|
||||
.then(exists => {
|
||||
if (exists) {
|
||||
resolveIfComplete();
|
||||
} else {
|
||||
checkRegistry(dep, 0, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolveIfComplete();
|
||||
})
|
||||
.catch (() => {
|
||||
checkRegistry(dep, 0, true);
|
||||
})
|
||||
} else {
|
||||
let hive = null;
|
||||
const hiveName = dep.registry[index].split('\\')[0];
|
||||
switch (hiveName) {
|
||||
case 'HKEY_CLASSES_ROOT':
|
||||
hive = Registry.HKCR;
|
||||
break;
|
||||
case 'HKEY_CURRENT_CONFIG':
|
||||
hive = Registry.HKCC;
|
||||
break;
|
||||
case 'HKEY_CURRENT_USER':
|
||||
hive = Registry.HKCU;
|
||||
break;
|
||||
case 'HKEY_LOCAL_MACHINE':
|
||||
hive = Registry.HKLM;
|
||||
break;
|
||||
case 'HKEY_USERS':
|
||||
hive = Registry.HKU;
|
||||
break;
|
||||
default:
|
||||
throw Error('Invalid registry hive: ' + hiveName);
|
||||
}
|
||||
});
|
||||
|
||||
const key = dep.registry[index].substr(hiveName.length);
|
||||
const regKey = new Registry({
|
||||
hive: hive,
|
||||
key: key
|
||||
});
|
||||
regKey.valueExists('DisplayName', (err, exists) => {
|
||||
if (err || !exists) {
|
||||
regKey.valueExists('ProductName', (err, exists) => {
|
||||
if (err || !exists) {
|
||||
checkRegistry(dep, ++index);
|
||||
} else {
|
||||
resolveIfComplete();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolveIfComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user