From fbb614b86b692f041326289651b1f98bc8f4523f Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 16 Oct 2017 09:50:21 +0200 Subject: [PATCH] bugfix graphics() vendor and model parsing linux --- CHANGELOG.md | 1 + README.md | 2 +- lib/graphics.js | 23 ++++++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c94f0..3383258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.31.1 | 2017-10-16 | bugfix `graphics()` vendor and model parsing linux | | 3.31.0 | 2017-10-15 | extended windows support `cpuFlags()` (partially) | | 3.30.6 | 2017-10-05 | updated community profile | | 3.30.5 | 2017-10-05 | bugfix `users()` - parsing values on windows | diff --git a/README.md b/README.md index f6276de..040ffef 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | cache.l1i | X | X | X | L1I (instruction) size | | | cache.l2 | X | X | X | L2 size | | | cache.l3 | X | X | X | L3 size | -| si.cpuFlags(cb) | : string | X | X | | CPU flags| +| si.cpuFlags(cb) | : string | X | X | X | CPU flags| | si.cpuCache(cb) | {...} | X | X | X | CPU cache sizes | | | l1d | X | X | X | L1D size | | | l1i | X | X | X | L1I size | diff --git a/lib/graphics.js b/lib/graphics.js index accd690..cc60a88 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -14,7 +14,6 @@ const os = require('os'); const exec = require('child_process').exec; -const fs = require('fs'); const util = require('./util'); let _platform = os.type(); @@ -22,13 +21,12 @@ let _platform = os.type(); const _linux = (_platform === 'Linux'); const _darwin = (_platform === 'Darwin'); const _windows = (_platform === 'Windows_NT'); -const NOT_SUPPORTED = 'not supported'; let _resolutionx = 0; let _resolutiony = 0; let _pixeldepth = 0; function toInt(value) { - let result = parseInt(value,10); + let result = parseInt(value, 10); if (isNaN(result)) { result = 0; } @@ -136,12 +134,23 @@ function graphics(callback) { let parts = lines[i].substr(vgapos, endpos - vgapos).split(':'); if (parts.length > 1) { parts[1] = parts[1].trim(); - if (parts[1].toLowerCase().indexOf('corporation')) { + if (parts[1].toLowerCase().indexOf('corporation') >= 0) { currentController.vendor = parts[1].substr(0, parts[1].toLowerCase().indexOf('corporation') + 11).trim(); currentController.model = parts[1].substr(parts[1].toLowerCase().indexOf('corporation') + 11, 200).trim().split('(')[0]; currentController.bus = ''; currentController.vram = -1; currentController.vramDynamic = false; + } else if (parts[1].toLowerCase().indexOf(' inc.') >= 0) { + if ((parts[1].match(new RegExp("]", "g")) || []).length > 1) { + currentController.vendor = parts[1].substr(0, parts[1].toLowerCase().indexOf(']') + 1).trim(); + currentController.model = parts[1].substr(parts[1].toLowerCase().indexOf(']')+1, 200).trim().split('(')[0]; + } else { + currentController.vendor = parts[1].substr(0, parts[1].toLowerCase().indexOf(' inc.') + 5).trim(); + currentController.model = parts[1].substr(parts[1].toLowerCase().indexOf(' inc.') + 5, 200).trim().split('(')[0]; + } + currentController.bus = ''; + currentController.vram = -1; + currentController.vramDynamic = false; } } @@ -151,7 +160,7 @@ function graphics(callback) { } if (is_vga) { // within VGA details let parts = lines[i].split(':'); - if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('devicename') !== -1 && parts[0].toLowerCase().indexOf('onboard') !== -1) currentController.bus = 'Onboard'; + if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('devicename') !== -1 && parts[0].toLowerCase().indexOf('onboard') !== -1) currentController.bus = 'Onboard'; if (parts.length > 1 && parts[0].replace(/ +/g, "").toLowerCase().indexOf('region') !== -1 && parts[1].toLowerCase().indexOf('memory') !== -1) { let memparts = parts[1].split("="); if (memparts.length > 1) { @@ -341,7 +350,7 @@ function graphics(callback) { }); }); - function parseLinesWindowsControllers(sections){ + function parseLinesWindowsControllers(sections) { let controllers = []; for (let i in sections) { if (sections.hasOwnProperty(i)) { @@ -364,7 +373,7 @@ function graphics(callback) { return controllers; } - function parseLinesWindowsDisplays(sections){ + function parseLinesWindowsDisplays(sections) { let displays = []; for (let i in sections) { if (sections.hasOwnProperty(i)) {