systeminformation 5.30.5 → 5.30.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/graphics.js +24 -26
  2. package/package.json +1 -1
package/lib/graphics.js CHANGED
@@ -14,11 +14,12 @@
14
14
  // ----------------------------------------------------------------------------------
15
15
 
16
16
  const fs = require('fs');
17
+ const path = require('path');
17
18
  const exec = require('child_process').exec;
18
19
  const execSync = require('child_process').execSync;
19
20
  const util = require('./util');
20
21
 
21
- let _platform = process.platform;
22
+ const _platform = process.platform;
22
23
  let _nvidiaSmiPath = '';
23
24
 
24
25
  const _linux = _platform === 'linux' || _platform === 'android';
@@ -225,10 +226,8 @@ function graphics(callback) {
225
226
  for (let i = 0; i < pciIDs.length; i++) {
226
227
  pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim();
227
228
  }
228
- pciIDs = pciIDs.filter(function (el) {
229
- return el != null && el;
230
- });
231
- } catch (e) {
229
+ pciIDs = pciIDs.filter((el) => el != null && el);
230
+ } catch {
232
231
  util.noop();
233
232
  }
234
233
  let i = 1;
@@ -422,25 +421,24 @@ function graphics(callback) {
422
421
 
423
422
  if (_windows) {
424
423
  try {
425
- const basePath = util.WINDIR + String.raw`\System32\DriverStore\FileRepository`;
426
- // find all directories that have an nvidia-smi.exe file
427
-
428
- const candidateDirs = fs.readdirSync(basePath).filter((dir) => {
429
- if (fs.statSync([basePath, dir].join('/')).isDirectory()) {
430
- return fs.readdirSync([basePath, dir].join('/')).includes('nvidia-smi.exe');
431
- } else {
432
- return false;
433
- }
434
- });
435
- // use the directory with the most recently created nvidia-smi.exe file
436
- const targetDir = candidateDirs.reduce((prevDir, currentDir) => {
437
- const previousNvidiaSmi = fs.statSync([basePath, prevDir, 'nvidia-smi.exe'].join('/'));
438
- const currentNvidiaSmi = fs.statSync([basePath, currentDir, 'nvidia-smi.exe'].join('/'));
439
- return previousNvidiaSmi.ctimeMs > currentNvidiaSmi.ctimeMs ? prevDir : currentDir;
440
- });
441
-
442
- if (targetDir) {
443
- _nvidiaSmiPath = [basePath, targetDir, 'nvidia-smi.exe'].join('/');
424
+ const basePath = path.join(util.WINDIR, 'System32', 'DriverStore', 'FileRepository');
425
+ // find all directories that have an nvidia-smi.exe file with date
426
+ const candidates = fs
427
+ .readdirSync(basePath, { withFileTypes: true })
428
+ .filter((dir) => dir.isDirectory())
429
+ .map((dir) => {
430
+ const nvidiaSmiPath = path.join(basePath, dir.name, 'nvidia-smi.exe');
431
+ try {
432
+ const stats = fs.statSync(nvidiaSmiPath);
433
+ return { path: nvidiaSmiPath, ctime: stats.ctimeMs };
434
+ } catch {
435
+ return null;
436
+ }
437
+ })
438
+ .filter(Boolean);
439
+ if (candidates.length > 0) {
440
+ // take the most recent
441
+ _nvidiaSmiPath = candidates.reduce((prev, curr) => (curr.ctime > prev.ctime ? curr : prev)).path;
444
442
  }
445
443
  } catch {
446
444
  util.noop();
@@ -457,12 +455,12 @@ function graphics(callback) {
457
455
  if (nvidiaSmiExe) {
458
456
  const nvidiaSmiOpts =
459
457
  '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
460
- const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts;
458
+ const cmd = `"${nvidiaSmiExe}" ${nvidiaSmiOpts}`;
461
459
  if (_linux) {
462
460
  options.stdio = ['pipe', 'pipe', 'ignore'];
463
461
  }
464
462
  try {
465
- const sanitized = util.sanitizeShellString(cmd) + (_linux ? ' 2>/dev/null' : '') + (_windows ? ' 2> nul' : '');
463
+ const sanitized = cmd + (_linux ? ' 2>/dev/null' : '') + (_windows ? ' 2> nul' : '');
466
464
  const res = execSync(sanitized, options).toString();
467
465
  return res;
468
466
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.30.5",
3
+ "version": "5.30.6",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",