[Registry] Rewrite to not use internal spawn func, fix using old func name
This commit is contained in:
parent
1540dfcbbb
commit
b3614d035f
1 changed files with 6 additions and 7 deletions
|
@ -2,13 +2,14 @@ const child_process = require('child_process');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
|
||||||
const sr = process.env.SystemRoot;
|
const sr = process.env.SystemRoot;
|
||||||
const regExePath = join(sr || '', sr ? 'System32' : '', 'reg.exe'); // %SystemRoot%\System32\reg.exe OR reg.exe if SR is undefined
|
const regExe = join(sr || '', sr ? 'System32' : '', 'reg.exe'); // %SystemRoot%\System32\reg.exe OR reg.exe if SR is undefined
|
||||||
|
|
||||||
const _spawn = (cmd, args, callback = (() => {})) => {
|
|
||||||
|
const spawn = (args, callback = (() => {})) => {
|
||||||
let process, stdout = '';
|
let process, stdout = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process = child_process.spawn(cmd, args);
|
process = child_process.spawn(regExe, args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback(e, stdout);
|
callback(e, stdout);
|
||||||
}
|
}
|
||||||
|
@ -17,11 +18,9 @@ const _spawn = (cmd, args, callback = (() => {})) => {
|
||||||
|
|
||||||
process.on('error', err => callback(err, stdout));
|
process.on('error', err => callback(err, stdout));
|
||||||
|
|
||||||
process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn returned: ' + signal ?? code) : null, stdout));
|
process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn: ' + signal ?? code) : null, stdout));
|
||||||
};
|
};
|
||||||
|
|
||||||
const spawn = (args, callback) => _spawn(regExePath, args, callback);
|
|
||||||
|
|
||||||
const add = (queue, callback = (() => {})) => {
|
const add = (queue, callback = (() => {})) => {
|
||||||
const args = queue.shift();
|
const args = queue.shift();
|
||||||
if (!args) return callback();
|
if (!args) return callback();
|
||||||
|
@ -29,7 +28,7 @@ const add = (queue, callback = (() => {})) => {
|
||||||
args.unshift('add');
|
args.unshift('add');
|
||||||
args.push('/f');
|
args.push('/f');
|
||||||
|
|
||||||
return spawnReg(args, () => add(queue, callback));
|
return spawn(args, () => add(queue, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue