This commit is contained in:
2021-08-05 13:41:51 -05:00
parent e23c0086c2
commit 33f9ffb393
76 changed files with 1390 additions and 1388 deletions

View File

@@ -27,48 +27,48 @@ const _vcRuntimeExists = () => {
: 'HKLM\\SOFTWARE\\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(
IS_64BIT
? 'Microsoft Visual C++ 2015-2019 Redistributable (x64)'
: 'Microsoft Visual C++ 2015-2019 Redistributable (x32)',
)
) {
vcRuntimeExists = true;
resolve(true);
} else {
parseLine(++index);
}
})
.catch(() => {
.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(
IS_64BIT
? 'Microsoft Visual C++ 2015-2019 Redistributable (x64)'
: 'Microsoft Visual C++ 2015-2019 Redistributable (x32)'
)
) {
vcRuntimeExists = true;
resolve(true);
} else {
parseLine(++index);
}
})
.catch(() => {
parseLine(++index);
});
} else {
parseLine(++index);
});
}
} else {
parseLine(++index);
resolve(false);
}
} else {
resolve(false);
}
};
parseLine(0);
})
.catch((err) => {
reject(err);
});
};
parseLine(0);
})
.catch((err) => {
reject(err);
});
}
}
});
@@ -317,13 +317,13 @@ module.exports.cleanupOldReleases = (versionList) => {
if (versionList && versionList.length > 0) {
const dataDir = _getDataDirectory();
const directoryList = fs
.readdirSync(dataDir, {withFileTypes: true})
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent);
.readdirSync(dataDir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent);
const removeList = directoryList
.filter((dirent) => !versionList.includes(dirent.name))
.map((dirent) => dirent.name);
.filter((dirent) => !versionList.includes(dirent.name))
.map((dirent) => dirent.name);
for (const dir of removeList) {
try {
@@ -391,8 +391,8 @@ module.exports.detectRepertoryMounts = (version, providerList) => {
const args = _getDefaultRepertoryArgs(
provider,
!Constants.PROVIDER_LIST.includes(provider) &&
provider.toLowerCase().startsWith('remote'),
!Constants.PROVIDER_LIST.includes(provider) && provider.toLowerCase().startsWith('s3'),
provider.toLowerCase().startsWith('remote'),
!Constants.PROVIDER_LIST.includes(provider) && provider.toLowerCase().startsWith('s3')
);
args.push('-status');
@@ -438,51 +438,51 @@ module.exports.downloadFile = (url, destination, progressCallback, completeCallb
}
axios
.get(url, {
responseType: 'stream',
})
.then((response) => {
try {
const total = parseInt(response.headers['content-length'], 10);
if (total === 0) {
completeCallback(new Error('No data available for download'));
} else {
const stream = fs.createWriteStream(destination);
.get(url, {
responseType: 'stream',
})
.then((response) => {
try {
const total = parseInt(response.headers['content-length'], 10);
if (total === 0) {
completeCallback(new Error('No data available for download'));
} else {
const stream = fs.createWriteStream(destination);
let downloaded = 0;
response.data.on('data', (chunk) => {
stream.write(Buffer.from(chunk));
downloaded += chunk.length;
if (progressCallback) {
progressCallback(((downloaded / total) * 100.0).toFixed(2));
}
});
response.data.on('end', () => {
stream.end(() => {
if (downloaded === 0) {
completeCallback(new Error('Received 0 bytes'));
} else if (downloaded !== total) {
completeCallback(new Error('Received incorrect number of bytes'));
} else {
completeCallback();
let downloaded = 0;
response.data.on('data', (chunk) => {
stream.write(Buffer.from(chunk));
downloaded += chunk.length;
if (progressCallback) {
progressCallback(((downloaded / total) * 100.0).toFixed(2));
}
});
});
response.data.on('error', (error) => {
stream.end(() => {
completeCallback(error);
response.data.on('end', () => {
stream.end(() => {
if (downloaded === 0) {
completeCallback(new Error('Received 0 bytes'));
} else if (downloaded !== total) {
completeCallback(new Error('Received incorrect number of bytes'));
} else {
completeCallback();
}
});
});
});
response.data.on('error', (error) => {
stream.end(() => {
completeCallback(error);
});
});
}
} catch (error) {
completeCallback(error);
}
} catch (error) {
})
.catch((error) => {
completeCallback(error);
}
})
.catch((error) => {
completeCallback(error);
});
});
};
module.exports.executeAndWait = (command, ignoreResult) => {
@@ -539,9 +539,9 @@ module.exports.executeAsync = (command, args = []) => {
() =>
launchProcess(
count,
setTimeout(() => resolve(), 3000),
setTimeout(() => resolve(), 3000)
),
1000,
1000
);
}
});
@@ -556,9 +556,9 @@ module.exports.executeAsync = (command, args = []) => {
() =>
launchProcess(
count,
setTimeout(() => resolve(), 3000),
setTimeout(() => resolve(), 3000)
),
1000,
1000
);
}
}
@@ -569,7 +569,7 @@ module.exports.executeAsync = (command, args = []) => {
launchProcess(
0,
setTimeout(() => resolve(), 3000),
setTimeout(() => resolve(), 3000)
);
});
};
@@ -785,16 +785,16 @@ module.exports.getMissingDependencies = (dependencies) => {
if (index >= dep.registry.length) {
if (dep.display === 'VC Runtime 2015-2019') {
_vcRuntimeExists()
.then((exists) => {
if (!exists) {
.then((exists) => {
if (!exists) {
missing.push(dep);
}
resolveIfComplete();
})
.catch(() => {
missing.push(dep);
}
resolveIfComplete();
})
.catch(() => {
missing.push(dep);
resolveIfComplete();
});
resolveIfComplete();
});
} else {
missing.push(dep);
resolveIfComplete();
@@ -823,7 +823,7 @@ module.exports.getMissingDependencies = (dependencies) => {
}
const key = dep.registry[index].substr(hiveName.length);
const regKey = new Registry({hive: hive, key: key});
const regKey = new Registry({ hive: hive, key: key });
regKey.valueExists('DisplayName', (err, exists) => {
if (err || !exists) {
regKey.valueExists('ProductName', (err, exists) => {
@@ -861,18 +861,18 @@ module.exports.getMissingDependencies = (dependencies) => {
module.exports.grabSkynetFileTree = (version) => {
return new Promise((resolve, reject) => {
_exportAllSkylinks(version)
.then((results) => {
resolve([
{
name: '/',
directory: true,
children: _createTreeNodes(results.success),
},
]);
})
.catch((e) => {
reject(e);
});
.then((results) => {
resolve([
{
name: '/',
directory: true,
children: _createTreeNodes(results.success),
},
]);
})
.catch((e) => {
reject(e);
});
});
};
@@ -1002,7 +1002,7 @@ module.exports.importSkylinks = (version, jsonArray) => {
};
// https://stackoverflow.com/questions/31645738/how-to-create-full-path-with-nodes-fs-mkdirsync
module.exports.mkDirByPathSync = (targetDir, {isRelativeToScript = false} = {}) => {
module.exports.mkDirByPathSync = (targetDir, { isRelativeToScript = false } = {}) => {
const sep = path.sep;
const initDir = path.isAbsolute(targetDir) ? sep : '';
const baseDir = isRelativeToScript ? __dirname : '.';
@@ -1048,53 +1048,53 @@ module.exports.performWindowsUninstall = (names) => {
: 'HKLM\\SOFTWARE\\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 (names.includes(value)) {
const items = line.split('\\');
const productCode = items[items.length - 1];
_executeProcess('msiexec.exe', null, ['/x', productCode, '/norestart'])
.then((code) => {
if (code === 0 || code === 3010 || code === 1641) {
resolve(true);
.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 (names.includes(value)) {
const items = line.split('\\');
const productCode = items[items.length - 1];
_executeProcess('msiexec.exe', null, ['/x', productCode, '/norestart'])
.then((code) => {
if (code === 0 || code === 3010 || code === 1641) {
resolve(true);
} else {
reject('[' + value + '] uninstall failed: ' + code);
}
})
.catch((err) => {
reject(err);
});
} else {
reject('[' + value + '] uninstall failed: ' + code);
parseLine(++index);
}
})
.catch((err) => {
reject(err);
.catch(() => {
parseLine(++index);
});
} else {
parseLine(++index);
}
})
.catch(() => {
} else {
parseLine(++index);
});
}
} else {
parseLine(++index);
resolve(false);
}
} else {
resolve(false);
}
};
parseLine(0);
})
.catch((err) => {
reject(err);
});
};
parseLine(0);
})
.catch((err) => {
reject(err);
});
}
});
};
@@ -1136,7 +1136,14 @@ module.exports.setConfigValue = (name, value, provider, remote, s3, version) =>
});
};
module.exports.testSkynetLogon = (version, authURL, authUser, authPassword, agentString, apiKey) => {
module.exports.testSkynetLogon = (
version,
authURL,
authUser,
authPassword,
agentString,
apiKey
) => {
return new Promise((resolve, reject) => {
const repertoryExec = _getRepertoryExec(version);
const processOptions = {
@@ -1218,16 +1225,16 @@ module.exports.testRepertoryBinary = (version) => {
return new Promise((resolve, reject) => {
const repertoryExec = _getRepertoryExec(version);
_executeProcess(repertoryExec.cmd, repertoryExec.working, ['-dc'])
.then((code) => {
if (code === 0) {
resolve();
} else {
reject(new Error('Invalid exit code: ' + code));
}
})
.catch((error) => {
reject(error);
});
.then((code) => {
if (code === 0) {
resolve();
} else {
reject(new Error('Invalid exit code: ' + code));
}
})
.catch((error) => {
reject(error);
});
});
};
@@ -1274,7 +1281,7 @@ module.exports.verifySignature = (file, signatureFile, publicKeyFile) => {
} else {
resolve(stdout);
}
},
}
);
};
@@ -1298,7 +1305,7 @@ module.exports.verifySignature = (file, signatureFile, publicKeyFile) => {
}
});
} else {
reject(new Error('Failed to locate \'openssl.exe\''));
reject(new Error("Failed to locate 'openssl.exe'"));
}
});
} else if (os.platform() === 'linux') {