[Registry] Minor rewrite / code cleanup
This commit is contained in:
parent
0b4e1f79bc
commit
364d3c564c
1 changed files with 6 additions and 12 deletions
|
@ -1,15 +1,11 @@
|
||||||
const child_process = require('child_process');
|
const CP = require('child_process');
|
||||||
const { join } = require('path');
|
|
||||||
|
|
||||||
const sr = process.env.SystemRoot;
|
|
||||||
const regExe = sr ? join(sr, 'System32', 'reg.exe') : 'reg.exe'; // %SystemRoot%\System32\reg.exe OR reg.exe if SR is undefined
|
|
||||||
|
|
||||||
|
|
||||||
const spawn = (args, callback) => {
|
const spawn = (args, callback) => {
|
||||||
let process, stdout = '';
|
let process, stdout = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process = child_process.spawn(regExe, args);
|
process = CP.spawn('reg.exe', args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback(e, stdout);
|
callback(e, stdout);
|
||||||
}
|
}
|
||||||
|
@ -21,13 +17,11 @@ const spawn = (args, callback) => {
|
||||||
process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn: ' + signal ?? code) : null, stdout));
|
process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn: ' + signal ?? code) : null, stdout));
|
||||||
};
|
};
|
||||||
|
|
||||||
const add = (queue, callback) => {
|
const add = (todo, callback) => {
|
||||||
let args = queue.shift();
|
const x = todo.shift();
|
||||||
if (!args) return callback();
|
if (!x) return callback();
|
||||||
|
|
||||||
args = [ 'add', ...args, '/f' ];
|
spawn([ 'add', ...x, '/f' ], () => add(todo, callback));
|
||||||
|
|
||||||
return spawn(args, () => add(queue, callback));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue