usb() fix parsing JSON (mac OS)
This commit is contained in:
parent
8bb47e5b4e
commit
68b4e5b273
@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
|
||||
|
||||
| Version | Date | Comment |
|
||||
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
|
||||
| 5.17.16 | 2023-05-30 | `usb()` fix parsing JSON (mac OS) |
|
||||
| 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) |
|
||||
| 5.17.14 | 2023-05-29 | `diskLayout()`, `osInfo()` fix parsing issues (mac OS) |
|
||||
| 5.17.13 | 2023-05-24 | `typings` fix typings dynamicData, networkInterfaceDatass |
|
||||
|
||||
@ -57,6 +57,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">5.17.16</th>
|
||||
<td>2023-05-30</td>
|
||||
<td><span class="code">usb()</span> fix parsing JSON (mac OS)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">5.17.15</th>
|
||||
<td>2023-05-29</td>
|
||||
|
||||
@ -1053,7 +1053,7 @@ function getUniqueMacAdresses() {
|
||||
for (let dev in ifaces) {
|
||||
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
||||
ifaces[dev].forEach(function (details) {
|
||||
if (details?.mac && details.mac !== '00:00:00:00:00:00') {
|
||||
if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
|
||||
const mac = details.mac.toLowerCase();
|
||||
if (macs.indexOf(mac) === -1) {
|
||||
macs.push(mac);
|
||||
|
||||
20
lib/usb.js
20
lib/usb.js
@ -125,20 +125,36 @@ function parseDarwinUsb(usb, id) {
|
||||
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
|
||||
lines[i] = lines[i] + ',';
|
||||
}
|
||||
|
||||
lines[i] = lines[i].replace(':Yes,', ':"Yes",');
|
||||
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
|
||||
lines[i] = lines[i].replace(': Yes', ': "Yes"');
|
||||
lines[i] = lines[i].replace(':No,', ':"No",');
|
||||
lines[i] = lines[i].replace(': No,', ': "No",');
|
||||
lines[i] = lines[i].replace(': No', ': "No"');
|
||||
|
||||
// In this case (("com.apple.developer.driverkit.transport.usb"))
|
||||
lines[i] = lines[i].replace('((', '').replace('))', '');
|
||||
|
||||
// In case we have <923c11> we need make it "<923c11>" for correct JSON parse
|
||||
const match = /<(\w+)>/.exec(lines[i]);
|
||||
if (match) {
|
||||
const number = match[0];
|
||||
lines[i] = lines[i].replace(number, `"${number}"`);
|
||||
}
|
||||
}
|
||||
const usbObj = JSON.parse(lines.join('\n'));
|
||||
const removableDrive = usbObj['Built-In'].toLowerCase() !== 'yes' && usbObj['non-removable'].toLowerCase() === 'no';
|
||||
const removableDrive = (usbObj['Built-In'] ? usbObj['Built-In'].toLowerCase() !== 'yes' : true) && (usbObj['non-removable'] ? usbObj['non-removable'].toLowerCase() === 'no' : true);
|
||||
|
||||
result.bus = null;
|
||||
result.deviceId = null;
|
||||
result.id = usbObj['USB Address'] || null;
|
||||
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
|
||||
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase() + (removableDrive ? ' removable' : ''));
|
||||
result.removable = usbObj['non-removable'].toLowerCase() === 'no';
|
||||
result.removable = usbObj['non-removable'] ? usbObj['non-removable'].toLowerCase() || '' === 'no' : true;
|
||||
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
|
||||
result.maxPower = null;
|
||||
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
|
||||
|
||||
|
||||
12
lib/util.js
12
lib/util.js
@ -315,7 +315,7 @@ function getWmic() {
|
||||
if (!fs.existsSync(wmicPath)) {
|
||||
try {
|
||||
const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n');
|
||||
if (wmicPathArray?.length) {
|
||||
if (wmicPathArray && wmicPathArray.length) {
|
||||
wmicPath = wmicPathArray[0];
|
||||
} else {
|
||||
wmicPath = 'wmic';
|
||||
@ -385,7 +385,7 @@ function powerShellStart() {
|
||||
encoding: 'UTF-8',
|
||||
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
||||
});
|
||||
if (_psChild?.pid) {
|
||||
if (_psChild && _psChild.pid) {
|
||||
_psPersistent = true;
|
||||
_psChild.stdout.on('data', function (data) {
|
||||
_psResult = _psResult + data.toString('utf8');
|
||||
@ -436,7 +436,7 @@ function powerShell(cmd) {
|
||||
start: new Date()
|
||||
});
|
||||
try {
|
||||
if (_psChild?.pid) {
|
||||
if (_psChild && _psChild.pid) {
|
||||
_psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
|
||||
}
|
||||
} catch (e) {
|
||||
@ -464,7 +464,7 @@ function powerShell(cmd) {
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (child?.pid) {
|
||||
if (child && child.pid) {
|
||||
child.stdout.on('data', function (data) {
|
||||
result = result + data.toString('utf8');
|
||||
});
|
||||
@ -514,7 +514,7 @@ function execSafe(cmd, args, options) {
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (child?.pid) {
|
||||
if (child && child.pid) {
|
||||
child.stdout.on('data', function (data) {
|
||||
result += data.toString();
|
||||
});
|
||||
@ -576,7 +576,7 @@ function smartMonToolsInstalled() {
|
||||
if (_windows) {
|
||||
try {
|
||||
const pathArray = execSync('WHERE smartctl 2>nul', execOptsWin).toString().split('\r\n');
|
||||
if (pathArray?.length) {
|
||||
if (pathArray && pathArray.length) {
|
||||
_smartMonToolsInstalled = pathArray[0].indexOf(':\\') >= 0;
|
||||
} else {
|
||||
_smartMonToolsInstalled = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user