code-poltergeist-system-monitor 1.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of code-poltergeist-system-monitor might be problematic. Click here for more details.

Files changed (33) hide show
  1. package/index.js +74 -0
  2. package/package.json +21 -0
  3. package/te/node_modules/.package-lock.json +44 -0
  4. package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
  5. package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
  6. package/te/node_modules/systeminformation/LICENSE +20 -0
  7. package/te/node_modules/systeminformation/README.md +1116 -0
  8. package/te/node_modules/systeminformation/lib/audio.js +222 -0
  9. package/te/node_modules/systeminformation/lib/battery.js +311 -0
  10. package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
  11. package/te/node_modules/systeminformation/lib/cli.js +91 -0
  12. package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
  13. package/te/node_modules/systeminformation/lib/docker.js +758 -0
  14. package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
  15. package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
  16. package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
  17. package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
  18. package/te/node_modules/systeminformation/lib/index.js +504 -0
  19. package/te/node_modules/systeminformation/lib/internet.js +237 -0
  20. package/te/node_modules/systeminformation/lib/memory.js +575 -0
  21. package/te/node_modules/systeminformation/lib/network.js +1783 -0
  22. package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
  23. package/te/node_modules/systeminformation/lib/printer.js +210 -0
  24. package/te/node_modules/systeminformation/lib/processes.js +1296 -0
  25. package/te/node_modules/systeminformation/lib/system.js +742 -0
  26. package/te/node_modules/systeminformation/lib/usb.js +279 -0
  27. package/te/node_modules/systeminformation/lib/users.js +363 -0
  28. package/te/node_modules/systeminformation/lib/util.js +1373 -0
  29. package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
  30. package/te/node_modules/systeminformation/lib/wifi.js +834 -0
  31. package/te/node_modules/systeminformation/package.json +99 -0
  32. package/te/package-lock.json +52 -0
  33. package/te/package.json +15 -0
@@ -0,0 +1,1373 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // utils.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2024
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 0. helper functions
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+ const spawn = require('child_process').spawn;
20
+ const exec = require('child_process').exec;
21
+ const execSync = require('child_process').execSync;
22
+ const util = require('util');
23
+
24
+ let _platform = process.platform;
25
+ const _linux = (_platform === 'linux' || _platform === 'android');
26
+ const _darwin = (_platform === 'darwin');
27
+ const _windows = (_platform === 'win32');
28
+ const _freebsd = (_platform === 'freebsd');
29
+ const _openbsd = (_platform === 'openbsd');
30
+ const _netbsd = (_platform === 'netbsd');
31
+
32
+ let _cores = 0;
33
+ let wmicPath = '';
34
+ let codepage = '';
35
+ let _smartMonToolsInstalled = null;
36
+ let _rpi_cpuinfo = null;
37
+
38
+ const WINDIR = process.env.WINDIR || 'C:\\Windows';
39
+
40
+ // powerShell
41
+ let _psChild;
42
+ let _psResult = '';
43
+ let _psCmds = [];
44
+ let _psPersistent = false;
45
+ const _psToUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
46
+ const _psCmdStart = '--###START###--';
47
+ const _psError = '--ERROR--';
48
+ const _psCmdSeperator = '--###ENDCMD###--';
49
+ const _psIdSeperator = '--##ID##--';
50
+
51
+ const execOptsWin = {
52
+ windowsHide: true,
53
+ maxBuffer: 1024 * 20000,
54
+ encoding: 'UTF-8',
55
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
56
+ };
57
+
58
+ const execOptsLinux = {
59
+ maxBuffer: 1024 * 20000,
60
+ encoding: 'UTF-8',
61
+ stdio: ['pipe', 'pipe', 'ignore']
62
+ };
63
+
64
+ function toInt(value) {
65
+ let result = parseInt(value, 10);
66
+ if (isNaN(result)) {
67
+ result = 0;
68
+ }
69
+ return result;
70
+ }
71
+
72
+ function splitByNumber(str) {
73
+ let numberStarted = false;
74
+ let num = '';
75
+ let cpart = '';
76
+ for (const c of str) {
77
+ if ((c >= '0' && c <= '9') || numberStarted) {
78
+ numberStarted = true;
79
+ num += c;
80
+ } else {
81
+ cpart += c;
82
+ }
83
+ }
84
+ return [cpart, num];
85
+ }
86
+
87
+ const stringReplace = new String().replace;
88
+ const stringToLower = new String().toLowerCase;
89
+ const stringToString = new String().toString;
90
+ const stringSubstr = new String().substr;
91
+ const stringTrim = new String().trim;
92
+ const stringStartWith = new String().startsWith;
93
+ const mathMin = Math.min;
94
+
95
+ function isFunction(functionToCheck) {
96
+ let getType = {};
97
+ return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
98
+ }
99
+
100
+ function unique(obj) {
101
+ let uniques = [];
102
+ let stringify = {};
103
+ for (let i = 0; i < obj.length; i++) {
104
+ let keys = Object.keys(obj[i]);
105
+ keys.sort(function (a, b) { return a - b; });
106
+ let str = '';
107
+ for (let j = 0; j < keys.length; j++) {
108
+ str += JSON.stringify(keys[j]);
109
+ str += JSON.stringify(obj[i][keys[j]]);
110
+ }
111
+ if (!{}.hasOwnProperty.call(stringify, str)) {
112
+ uniques.push(obj[i]);
113
+ stringify[str] = true;
114
+ }
115
+ }
116
+ return uniques;
117
+ }
118
+
119
+ function sortByKey(array, keys) {
120
+ return array.sort(function (a, b) {
121
+ let x = '';
122
+ let y = '';
123
+ keys.forEach(function (key) {
124
+ x = x + a[key]; y = y + b[key];
125
+ });
126
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
127
+ });
128
+ }
129
+
130
+ function cores() {
131
+ if (_cores === 0) {
132
+ _cores = os.cpus().length;
133
+ }
134
+ return _cores;
135
+ }
136
+
137
+ function getValue(lines, property, separator, trimmed, lineMatch) {
138
+ separator = separator || ':';
139
+ property = property.toLowerCase();
140
+ trimmed = trimmed || false;
141
+ lineMatch = lineMatch || false;
142
+ let result = '';
143
+ lines.some((line) => {
144
+ let lineLower = line.toLowerCase().replace(/\t/g, '');
145
+ if (trimmed) {
146
+ lineLower = lineLower.trim();
147
+ }
148
+ if (lineLower.startsWith(property) && (lineMatch ? (lineLower.match(property + separator)) || (lineLower.match(property + ' ' + separator)) : true)) {
149
+ const parts = trimmed ? line.trim().split(separator) : line.split(separator);
150
+ if (parts.length >= 2) {
151
+ parts.shift();
152
+ result = parts.join(separator).trim();
153
+ return true;
154
+ }
155
+ }
156
+ });
157
+ return result;
158
+ }
159
+
160
+ function decodeEscapeSequence(str, base) {
161
+ base = base || 16;
162
+ return str.replace(/\\x([0-9A-Fa-f]{2})/g, function () {
163
+ return String.fromCharCode(parseInt(arguments[1], base));
164
+ });
165
+ }
166
+
167
+ function detectSplit(str) {
168
+ let seperator = '';
169
+ let part = 0;
170
+ str.split('').forEach(element => {
171
+ if (element >= '0' && element <= '9') {
172
+ if (part === 1) { part++; }
173
+ } else {
174
+ if (part === 0) { part++; }
175
+ if (part === 1) {
176
+ seperator += element;
177
+ }
178
+ }
179
+ });
180
+ return seperator;
181
+ }
182
+
183
+ function parseTime(t, pmDesignator) {
184
+ pmDesignator = pmDesignator || '';
185
+ t = t.toUpperCase();
186
+ let hour = 0;
187
+ let min = 0;
188
+ let splitter = detectSplit(t);
189
+ let parts = t.split(splitter);
190
+ if (parts.length >= 2) {
191
+ if (parts[2]) {
192
+ parts[1] += parts[2];
193
+ }
194
+ let isPM = (parts[1] && (parts[1].toLowerCase().indexOf('pm') > -1) || (parts[1].toLowerCase().indexOf('p.m.') > -1) || (parts[1].toLowerCase().indexOf('p. m.') > -1) || (parts[1].toLowerCase().indexOf('n') > -1) || (parts[1].toLowerCase().indexOf('ch') > -1) || (parts[1].toLowerCase().indexOf('ös') > -1) || (pmDesignator && parts[1].toLowerCase().indexOf(pmDesignator) > -1));
195
+ hour = parseInt(parts[0], 10);
196
+ min = parseInt(parts[1], 10);
197
+ hour = isPM && hour < 12 ? hour + 12 : hour;
198
+ return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2);
199
+ }
200
+ }
201
+
202
+ function parseDateTime(dt, culture) {
203
+ const result = {
204
+ date: '',
205
+ time: ''
206
+ };
207
+ culture = culture || {};
208
+ let dateFormat = (culture.dateFormat || '').toLowerCase();
209
+ let pmDesignator = (culture.pmDesignator || '');
210
+
211
+ const parts = dt.split(' ');
212
+ if (parts[0]) {
213
+ if (parts[0].indexOf('/') >= 0) {
214
+ // Dateformat: mm/dd/yyyy or dd/mm/yyyy or dd/mm/yy or yyyy/mm/dd
215
+ const dtparts = parts[0].split('/');
216
+ if (dtparts.length === 3) {
217
+ if (dtparts[0].length === 4) {
218
+ // Dateformat: yyyy/mm/dd
219
+ result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2);
220
+ } else if (dtparts[2].length === 2) {
221
+ if ((dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1)) {
222
+ // Dateformat: mm/dd/yy
223
+ result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
224
+ } else {
225
+ // Dateformat: dd/mm/yy
226
+ result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
227
+ }
228
+ } else {
229
+ // Dateformat: mm/dd/yyyy or dd/mm/yyyy
230
+ const isEN = ((dt.toLowerCase().indexOf('pm') > -1) || (dt.toLowerCase().indexOf('p.m.') > -1) || (dt.toLowerCase().indexOf('p. m.') > -1) || (dt.toLowerCase().indexOf('am') > -1) || (dt.toLowerCase().indexOf('a.m.') > -1) || (dt.toLowerCase().indexOf('a. m.') > -1));
231
+ if ((isEN || dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1) && dateFormat.indexOf('dd/') !== 0) {
232
+ // Dateformat: mm/dd/yyyy
233
+ result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2);
234
+ } else {
235
+ // Dateformat: dd/mm/yyyy
236
+ result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
237
+ }
238
+ }
239
+ }
240
+ }
241
+ if (parts[0].indexOf('.') >= 0) {
242
+ const dtparts = parts[0].split('.');
243
+ if (dtparts.length === 3) {
244
+ if (dateFormat.indexOf('.d.') > -1 || dateFormat.indexOf('.dd.') > -1) {
245
+ // Dateformat: mm.dd.yyyy
246
+ result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2);
247
+ } else {
248
+ // Dateformat: dd.mm.yyyy
249
+ result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
250
+ }
251
+ }
252
+ }
253
+ if (parts[0].indexOf('-') >= 0) {
254
+ // Dateformat: yyyy-mm-dd
255
+ const dtparts = parts[0].split('-');
256
+ if (dtparts.length === 3) {
257
+ result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2);
258
+ }
259
+ }
260
+ }
261
+ if (parts[1]) {
262
+ parts.shift();
263
+ let time = parts.join(' ');
264
+ result.time = parseTime(time, pmDesignator);
265
+ }
266
+ return result;
267
+ }
268
+
269
+ function parseHead(head, rights) {
270
+ let space = (rights > 0);
271
+ let count = 1;
272
+ let from = 0;
273
+ let to = 0;
274
+ let result = [];
275
+ for (let i = 0; i < head.length; i++) {
276
+ if (count <= rights) {
277
+ if (/\s/.test(head[i]) && !space) {
278
+ to = i - 1;
279
+ result.push({
280
+ from: from,
281
+ to: to + 1,
282
+ cap: head.substring(from, to + 1)
283
+ });
284
+ from = to + 2;
285
+ count++;
286
+ }
287
+ space = head[i] === ' ';
288
+ } else {
289
+ if (!/\s/.test(head[i]) && space) {
290
+ to = i - 1;
291
+ if (from < to) {
292
+ result.push({
293
+ from: from,
294
+ to: to,
295
+ cap: head.substring(from, to)
296
+ });
297
+ }
298
+ from = to + 1;
299
+ count++;
300
+ }
301
+ space = head[i] === ' ';
302
+ }
303
+ }
304
+ to = 5000;
305
+ result.push({
306
+ from: from,
307
+ to: to,
308
+ cap: head.substring(from, to)
309
+ });
310
+ let len = result.length;
311
+ for (let i = 0; i < len; i++) {
312
+ if (result[i].cap.replace(/\s/g, '').length === 0) {
313
+ if (i + 1 < len) {
314
+ result[i].to = result[i + 1].to;
315
+ result[i].cap = result[i].cap + result[i + 1].cap;
316
+ result.splice(i + 1, 1);
317
+ len = len - 1;
318
+ }
319
+ }
320
+ }
321
+ return result;
322
+ }
323
+
324
+ function findObjectByKey(array, key, value) {
325
+ for (let i = 0; i < array.length; i++) {
326
+ if (array[i][key] === value) {
327
+ return i;
328
+ }
329
+ }
330
+ return -1;
331
+ }
332
+
333
+ function getWmic() {
334
+ if (os.type() === 'Windows_NT' && !wmicPath) {
335
+ wmicPath = WINDIR + '\\system32\\wbem\\wmic.exe';
336
+ if (!fs.existsSync(wmicPath)) {
337
+ try {
338
+ const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n');
339
+ if (wmicPathArray && wmicPathArray.length) {
340
+ wmicPath = wmicPathArray[0];
341
+ } else {
342
+ wmicPath = 'wmic';
343
+ }
344
+ } catch (e) {
345
+ wmicPath = 'wmic';
346
+ }
347
+ }
348
+ }
349
+ return wmicPath;
350
+ }
351
+
352
+ function wmic(command) {
353
+ return new Promise((resolve) => {
354
+ process.nextTick(() => {
355
+ try {
356
+ powerShell(getWmic() + ' ' + command).then(stdout => {
357
+ resolve(stdout, '');
358
+ });
359
+ } catch (e) {
360
+ resolve('', e);
361
+ }
362
+ });
363
+ });
364
+ }
365
+
366
+ function getVboxmanage() {
367
+ return _windows ? `"${process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH}\\VBoxManage.exe"` : 'vboxmanage';
368
+ }
369
+
370
+ function powerShellProceedResults(data) {
371
+ let id = '';
372
+ let parts;
373
+ let res = '';
374
+ // startID
375
+ if (data.indexOf(_psCmdStart) >= 0) {
376
+ parts = data.split(_psCmdStart);
377
+ const parts2 = parts[1].split(_psIdSeperator);
378
+ id = parts2[0];
379
+ if (parts2.length > 1) {
380
+ data = parts2.slice(1).join(_psIdSeperator);
381
+ }
382
+ }
383
+ // result;
384
+ if (data.indexOf(_psCmdSeperator) >= 0) {
385
+ parts = data.split(_psCmdSeperator);
386
+ res = parts[0];
387
+ }
388
+ let remove = -1;
389
+ for (let i = 0; i < _psCmds.length; i++) {
390
+ if (_psCmds[i].id === id) {
391
+ remove = i;
392
+ _psCmds[i].callback(res);
393
+ }
394
+ }
395
+ if (remove >= 0) {
396
+ _psCmds.splice(remove, 1);
397
+ }
398
+ }
399
+
400
+ function powerShellStart() {
401
+ if (!_psChild) {
402
+ _psChild = spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
403
+ stdio: 'pipe',
404
+ windowsHide: true,
405
+ maxBuffer: 1024 * 20000,
406
+ encoding: 'UTF-8',
407
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
408
+ });
409
+ if (_psChild && _psChild.pid) {
410
+ _psPersistent = true;
411
+ _psChild.stdout.on('data', function (data) {
412
+ _psResult = _psResult + data.toString('utf8');
413
+ if (data.indexOf(_psCmdSeperator) >= 0) {
414
+ powerShellProceedResults(_psResult);
415
+ _psResult = '';
416
+ }
417
+ });
418
+ _psChild.stderr.on('data', function () {
419
+ powerShellProceedResults(_psResult + _psError);
420
+ });
421
+ _psChild.on('error', function () {
422
+ powerShellProceedResults(_psResult + _psError);
423
+ });
424
+ _psChild.on('close', function () {
425
+ if (_psChild) { _psChild.kill(); }
426
+ });
427
+ }
428
+ }
429
+ }
430
+
431
+ function powerShellRelease() {
432
+ try {
433
+ if (_psChild) {
434
+ _psChild.stdin.write('exit' + os.EOL);
435
+ _psChild.stdin.end();
436
+ _psPersistent = false;
437
+ }
438
+ } catch (e) {
439
+ if (_psChild) { _psChild.kill(); }
440
+ }
441
+ _psChild = null;
442
+ }
443
+
444
+ function powerShell(cmd) {
445
+
446
+ /// const pattern = [
447
+ /// '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
448
+ /// '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
449
+ /// ].join('|');
450
+
451
+ if (_psPersistent) {
452
+ const id = Math.random().toString(36).substring(2, 12);
453
+ return new Promise((resolve) => {
454
+ process.nextTick(() => {
455
+ function callback(data) {
456
+ resolve(data);
457
+ }
458
+ _psCmds.push({
459
+ id,
460
+ cmd,
461
+ callback,
462
+ start: new Date()
463
+ });
464
+ try {
465
+ if (_psChild && _psChild.pid) {
466
+ _psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
467
+ }
468
+ } catch (e) {
469
+ resolve('');
470
+ }
471
+ });
472
+ });
473
+
474
+ } else {
475
+ let result = '';
476
+
477
+ return new Promise((resolve) => {
478
+ process.nextTick(() => {
479
+ try {
480
+ const child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
481
+ stdio: 'pipe',
482
+ windowsHide: true,
483
+ maxBuffer: 1024 * 20000,
484
+ encoding: 'UTF-8',
485
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
486
+ });
487
+
488
+ if (child && !child.pid) {
489
+ child.on('error', function () {
490
+ resolve(result);
491
+ });
492
+ }
493
+ if (child && child.pid) {
494
+ child.stdout.on('data', function (data) {
495
+ result = result + data.toString('utf8');
496
+ });
497
+ child.stderr.on('data', function () {
498
+ child.kill();
499
+ resolve(result);
500
+ });
501
+ child.on('close', function () {
502
+ child.kill();
503
+
504
+ resolve(result);
505
+ });
506
+ child.on('error', function () {
507
+ child.kill();
508
+ resolve(result);
509
+ });
510
+ try {
511
+ child.stdin.write(_psToUTF8 + cmd + os.EOL);
512
+ child.stdin.write('exit' + os.EOL);
513
+ child.stdin.end();
514
+ } catch (e) {
515
+ child.kill();
516
+ resolve(result);
517
+ }
518
+ } else {
519
+ resolve(result);
520
+ }
521
+ } catch (e) {
522
+ resolve(result);
523
+ }
524
+ });
525
+ });
526
+ }
527
+ }
528
+
529
+ function execSafe(cmd, args, options) {
530
+ let result = '';
531
+ options = options || {};
532
+
533
+ return new Promise((resolve) => {
534
+ process.nextTick(() => {
535
+ try {
536
+ const child = spawn(cmd, args, options);
537
+
538
+ if (child && !child.pid) {
539
+ child.on('error', function () {
540
+ resolve(result);
541
+ });
542
+ }
543
+ if (child && child.pid) {
544
+ child.stdout.on('data', function (data) {
545
+ result += data.toString();
546
+ });
547
+ child.on('close', function () {
548
+ child.kill();
549
+ resolve(result);
550
+ });
551
+ child.on('error', function () {
552
+ child.kill();
553
+ resolve(result);
554
+ });
555
+ } else {
556
+ resolve(result);
557
+ }
558
+ } catch (e) {
559
+ resolve(result);
560
+ }
561
+ });
562
+ });
563
+ }
564
+
565
+ function getCodepage() {
566
+ if (_windows) {
567
+ if (!codepage) {
568
+ try {
569
+ const stdout = execSync('chcp', execOptsWin);
570
+ const lines = stdout.toString().split('\r\n');
571
+ const parts = lines[0].split(':');
572
+ codepage = parts.length > 1 ? parts[1].replace('.', '').trim() : '';
573
+ } catch (err) {
574
+ codepage = '437';
575
+ }
576
+ }
577
+ return codepage;
578
+ }
579
+ if (_linux || _darwin || _freebsd || _openbsd || _netbsd) {
580
+ if (!codepage) {
581
+ try {
582
+ const stdout = execSync('echo $LANG', util.execOptsLinux);
583
+ const lines = stdout.toString().split('\r\n');
584
+ const parts = lines[0].split('.');
585
+ codepage = parts.length > 1 ? parts[1].trim() : '';
586
+ if (!codepage) {
587
+ codepage = 'UTF-8';
588
+ }
589
+ } catch (err) {
590
+ codepage = 'UTF-8';
591
+ }
592
+ }
593
+ return codepage;
594
+ }
595
+ }
596
+
597
+ function smartMonToolsInstalled() {
598
+ if (_smartMonToolsInstalled !== null) {
599
+ return _smartMonToolsInstalled;
600
+ }
601
+ _smartMonToolsInstalled = false;
602
+ if (_windows) {
603
+ try {
604
+ const pathArray = execSync('WHERE smartctl 2>nul', execOptsWin).toString().split('\r\n');
605
+ if (pathArray && pathArray.length) {
606
+ _smartMonToolsInstalled = pathArray[0].indexOf(':\\') >= 0;
607
+ } else {
608
+ _smartMonToolsInstalled = false;
609
+ }
610
+ } catch (e) {
611
+ _smartMonToolsInstalled = false;
612
+ }
613
+ }
614
+ if (_linux || _darwin || _freebsd || _openbsd || _netbsd) {
615
+ try {
616
+ const pathArray = execSync('which smartctl 2>/dev/null', execOptsLinux).toString().split('\r\n');
617
+ _smartMonToolsInstalled = pathArray.length > 0;
618
+ } catch (e) {
619
+ util.noop();
620
+ }
621
+ }
622
+ return _smartMonToolsInstalled;
623
+ }
624
+
625
+ function isRaspberry() {
626
+ const PI_MODEL_NO = [
627
+ 'BCM2708',
628
+ 'BCM2709',
629
+ 'BCM2710',
630
+ 'BCM2711',
631
+ 'BCM2712',
632
+ 'BCM2835',
633
+ 'BCM2836',
634
+ 'BCM2837',
635
+ 'BCM2837B0'
636
+ ];
637
+ let cpuinfo = [];
638
+
639
+ if (_rpi_cpuinfo !== null) {
640
+ cpuinfo = _rpi_cpuinfo;
641
+ } else {
642
+ try {
643
+ cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
644
+ _rpi_cpuinfo = cpuinfo;
645
+ } catch (e) {
646
+ return false;
647
+ }
648
+ }
649
+
650
+ const hardware = getValue(cpuinfo, 'hardware');
651
+ return (hardware && PI_MODEL_NO.indexOf(hardware) > -1);
652
+ }
653
+
654
+ function isRaspbian() {
655
+ let osrelease = [];
656
+ try {
657
+ osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).toString().split('\n');
658
+ } catch (e) {
659
+ return false;
660
+ }
661
+ const id = getValue(osrelease, 'id', '=');
662
+ return (id && id.indexOf('raspbian') > -1);
663
+ }
664
+
665
+ function execWin(cmd, opts, callback) {
666
+ if (!callback) {
667
+ callback = opts;
668
+ opts = execOptsWin;
669
+ }
670
+ let newCmd = 'chcp 65001 > nul && cmd /C ' + cmd + ' && chcp ' + codepage + ' > nul';
671
+ exec(newCmd, opts, function (error, stdout) {
672
+ callback(error, stdout);
673
+ });
674
+ }
675
+
676
+ function darwinXcodeExists() {
677
+ const cmdLineToolsExists = fs.existsSync('/Library/Developer/CommandLineTools/usr/bin/');
678
+ const xcodeAppExists = fs.existsSync('/Applications/Xcode.app/Contents/Developer/Tools');
679
+ const xcodeExists = fs.existsSync('/Library/Developer/Xcode/');
680
+ return (cmdLineToolsExists || xcodeExists || xcodeAppExists);
681
+ }
682
+
683
+ function nanoSeconds() {
684
+ const time = process.hrtime();
685
+ if (!Array.isArray(time) || time.length !== 2) {
686
+ return 0;
687
+ }
688
+ return +time[0] * 1e9 + +time[1];
689
+ }
690
+
691
+ function countUniqueLines(lines, startingWith) {
692
+ startingWith = startingWith || '';
693
+ const uniqueLines = [];
694
+ lines.forEach(line => {
695
+ if (line.startsWith(startingWith)) {
696
+ if (uniqueLines.indexOf(line) === -1) {
697
+ uniqueLines.push(line);
698
+ }
699
+ }
700
+ });
701
+ return uniqueLines.length;
702
+ }
703
+
704
+ function countLines(lines, startingWith) {
705
+ startingWith = startingWith || '';
706
+ const uniqueLines = [];
707
+ lines.forEach(line => {
708
+ if (line.startsWith(startingWith)) {
709
+ uniqueLines.push(line);
710
+ }
711
+ });
712
+ return uniqueLines.length;
713
+ }
714
+
715
+ function sanitizeShellString(str, strict) {
716
+ if (typeof strict === 'undefined') { strict = false; }
717
+ const s = str || '';
718
+ let result = '';
719
+ const l = mathMin(s.length, 2000);
720
+ for (let i = 0; i <= l; i++) {
721
+ if (!(s[i] === undefined ||
722
+ s[i] === '>' ||
723
+ s[i] === '<' ||
724
+ s[i] === '*' ||
725
+ s[i] === '?' ||
726
+ s[i] === '[' ||
727
+ s[i] === ']' ||
728
+ s[i] === '|' ||
729
+ s[i] === '˚' ||
730
+ s[i] === '$' ||
731
+ s[i] === ';' ||
732
+ s[i] === '&' ||
733
+ s[i] === ']' ||
734
+ s[i] === '#' ||
735
+ s[i] === '\\' ||
736
+ s[i] === '\t' ||
737
+ s[i] === '\n' ||
738
+ s[i] === '\r' ||
739
+ s[i] === '\'' ||
740
+ s[i] === '`' ||
741
+ s[i] === '"' ||
742
+ s[i].length > 1 ||
743
+ (strict && s[i] === '(') ||
744
+ (strict && s[i] === ')') ||
745
+ (strict && s[i] === '@') ||
746
+ (strict && s[i] === ' ') ||
747
+ (strict && s[i] == '{') ||
748
+ (strict && s[i] == ';') ||
749
+ (strict && s[i] == '}'))) {
750
+ result = result + s[i];
751
+ }
752
+ }
753
+ return result;
754
+ }
755
+
756
+ function isPrototypePolluted() {
757
+ const s = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
758
+ let notPolluted = true;
759
+ let st = '';
760
+
761
+ st.__proto__.replace = stringReplace;
762
+ st.__proto__.toLowerCase = stringToLower;
763
+ st.__proto__.toString = stringToString;
764
+ st.__proto__.substr = stringSubstr;
765
+
766
+ notPolluted = notPolluted || (s.length !== 62);
767
+ const ms = Date.now();
768
+ if (typeof ms === 'number' && ms > 1600000000000) {
769
+ const l = ms % 100 + 15;
770
+ for (let i = 0; i < l; i++) {
771
+ const r = Math.random() * 61.99999999 + 1;
772
+ const rs = parseInt(Math.floor(r).toString(), 10);
773
+ const rs2 = parseInt(r.toString().split('.')[0], 10);
774
+ const q = Math.random() * 61.99999999 + 1;
775
+ const qs = parseInt(Math.floor(q).toString(), 10);
776
+ const qs2 = parseInt(q.toString().split('.')[0], 10);
777
+ notPolluted = notPolluted && (r !== q);
778
+ notPolluted = notPolluted && rs === rs2 && qs === qs2;
779
+ st += s[rs - 1];
780
+ }
781
+ notPolluted = notPolluted && st.length === l;
782
+ // string manipulation
783
+ let p = Math.random() * l * 0.9999999999;
784
+ let stm = st.substr(0, p) + ' ' + st.substr(p, 2000);
785
+ stm.__proto__.replace = stringReplace;
786
+ let sto = stm.replace(/ /g, '');
787
+ notPolluted = notPolluted && st === sto;
788
+ p = Math.random() * l * 0.9999999999;
789
+ stm = st.substr(0, p) + '{' + st.substr(p, 2000);
790
+ sto = stm.replace(/{/g, '');
791
+ notPolluted = notPolluted && st === sto;
792
+ p = Math.random() * l * 0.9999999999;
793
+ stm = st.substr(0, p) + '*' + st.substr(p, 2000);
794
+ sto = stm.replace(/\*/g, '');
795
+ notPolluted = notPolluted && st === sto;
796
+ p = Math.random() * l * 0.9999999999;
797
+ stm = st.substr(0, p) + '$' + st.substr(p, 2000);
798
+ sto = stm.replace(/\$/g, '');
799
+ notPolluted = notPolluted && st === sto;
800
+
801
+ // lower
802
+ const stl = st.toLowerCase();
803
+ notPolluted = notPolluted && (stl.length === l) && stl[l - 1] && !(stl[l]);
804
+ for (let i = 0; i < l; i++) {
805
+ const s1 = st[i];
806
+ s1.__proto__.toLowerCase = stringToLower;
807
+ const s2 = stl ? stl[i] : '';
808
+ const s1l = s1.toLowerCase();
809
+ notPolluted = notPolluted && s1l[0] === s2 && s1l[0] && !(s1l[1]);
810
+ }
811
+ }
812
+ return !notPolluted;
813
+ }
814
+
815
+ function hex2bin(hex) {
816
+ return ('00000000' + (parseInt(hex, 16)).toString(2)).substr(-8);
817
+ }
818
+
819
+ function getFilesInPath(source) {
820
+ const lstatSync = fs.lstatSync;
821
+ const readdirSync = fs.readdirSync;
822
+ const join = path.join;
823
+
824
+ function isDirectory(source) {
825
+ return lstatSync(source).isDirectory();
826
+ }
827
+ function isFile(source) { return lstatSync(source).isFile(); }
828
+
829
+ function getDirectories(source) {
830
+ return readdirSync(source).map(function (name) { return join(source, name); }).filter(isDirectory);
831
+ }
832
+ function getFiles(source) {
833
+ return readdirSync(source).map(function (name) { return join(source, name); }).filter(isFile);
834
+ }
835
+
836
+ function getFilesRecursively(source) {
837
+ try {
838
+ let dirs = getDirectories(source);
839
+ let files = dirs
840
+ .map(function (dir) { return getFilesRecursively(dir); })
841
+ .reduce(function (a, b) { return a.concat(b); }, []);
842
+ return files.concat(getFiles(source));
843
+ } catch (e) {
844
+ return [];
845
+ }
846
+ }
847
+
848
+ if (fs.existsSync(source)) {
849
+ return getFilesRecursively(source);
850
+ } else {
851
+ return [];
852
+ }
853
+ }
854
+
855
+ function decodePiCpuinfo(lines) {
856
+
857
+ if (_rpi_cpuinfo === null) {
858
+ _rpi_cpuinfo = lines;
859
+ }
860
+
861
+ // https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
862
+
863
+ const oldRevisionCodes = {
864
+ '0002': {
865
+ type: 'B',
866
+ revision: '1.0',
867
+ memory: 256,
868
+ manufacturer: 'Egoman',
869
+ processor: 'BCM2835'
870
+ },
871
+ '0003': {
872
+ type: 'B',
873
+ revision: '1.0',
874
+ memory: 256,
875
+ manufacturer: 'Egoman',
876
+ processor: 'BCM2835'
877
+ },
878
+ '0004': {
879
+ type: 'B',
880
+ revision: '2.0',
881
+ memory: 256,
882
+ manufacturer: 'Sony UK',
883
+ processor: 'BCM2835'
884
+ },
885
+ '0005': {
886
+ type: 'B',
887
+ revision: '2.0',
888
+ memory: 256,
889
+ manufacturer: 'Qisda',
890
+ processor: 'BCM2835'
891
+ },
892
+ '0006': {
893
+ type: 'B',
894
+ revision: '2.0',
895
+ memory: 256,
896
+ manufacturer: 'Egoman',
897
+ processor: 'BCM2835'
898
+ },
899
+ '0007': {
900
+ type: 'A',
901
+ revision: '2.0',
902
+ memory: 256,
903
+ manufacturer: 'Egoman',
904
+ processor: 'BCM2835'
905
+ },
906
+ '0008': {
907
+ type: 'A',
908
+ revision: '2.0',
909
+ memory: 256,
910
+ manufacturer: 'Sony UK',
911
+ processor: 'BCM2835'
912
+ },
913
+ '0009': {
914
+ type: 'A',
915
+ revision: '2.0',
916
+ memory: 256,
917
+ manufacturer: 'Qisda',
918
+ processor: 'BCM2835'
919
+ },
920
+ '000d': {
921
+ type: 'B',
922
+ revision: '2.0',
923
+ memory: 512,
924
+ manufacturer: 'Egoman',
925
+ processor: 'BCM2835'
926
+ },
927
+ '000e': {
928
+ type: 'B',
929
+ revision: '2.0',
930
+ memory: 512,
931
+ manufacturer: 'Sony UK',
932
+ processor: 'BCM2835'
933
+ },
934
+ '000f': {
935
+ type: 'B',
936
+ revision: '2.0',
937
+ memory: 512,
938
+ manufacturer: 'Egoman',
939
+ processor: 'BCM2835'
940
+ },
941
+ '0010': {
942
+ type: 'B+',
943
+ revision: '1.2',
944
+ memory: 512,
945
+ manufacturer: 'Sony UK',
946
+ processor: 'BCM2835'
947
+ },
948
+ '0011': {
949
+ type: 'CM1',
950
+ revision: '1.0',
951
+ memory: 512,
952
+ manufacturer: 'Sony UK',
953
+ processor: 'BCM2835'
954
+ },
955
+ '0012': {
956
+ type: 'A+',
957
+ revision: '1.1',
958
+ memory: 256,
959
+ manufacturer: 'Sony UK',
960
+ processor: 'BCM2835'
961
+ },
962
+ '0013': {
963
+ type: 'B+',
964
+ revision: '1.2',
965
+ memory: 512,
966
+ manufacturer: 'Embest',
967
+ processor: 'BCM2835'
968
+ },
969
+ '0014': {
970
+ type: 'CM1',
971
+ revision: '1.0',
972
+ memory: 512,
973
+ manufacturer: 'Embest',
974
+ processor: 'BCM2835'
975
+ },
976
+ '0015': {
977
+ type: 'A+',
978
+ revision: '1.1',
979
+ memory: 256,
980
+ manufacturer: '512MB Embest',
981
+ processor: 'BCM2835'
982
+ }
983
+ };
984
+
985
+ const processorList = [
986
+ 'BCM2835',
987
+ 'BCM2836',
988
+ 'BCM2837',
989
+ 'BCM2711',
990
+ 'BCM2712',
991
+ ];
992
+ const manufacturerList = [
993
+ 'Sony UK',
994
+ 'Egoman',
995
+ 'Embest',
996
+ 'Sony Japan',
997
+ 'Embest',
998
+ 'Stadium'
999
+ ];
1000
+ const typeList = {
1001
+ '00': 'A',
1002
+ '01': 'B',
1003
+ '02': 'A+',
1004
+ '03': 'B+',
1005
+ '04': '2B',
1006
+ '05': 'Alpha (early prototype)',
1007
+ '06': 'CM1',
1008
+ '08': '3B',
1009
+ '09': 'Zero',
1010
+ '0a': 'CM3',
1011
+ '0c': 'Zero W',
1012
+ '0d': '3B+',
1013
+ '0e': '3A+',
1014
+ '0f': 'Internal use only',
1015
+ '10': 'CM3+',
1016
+ '11': '4B',
1017
+ '12': 'Zero 2 W',
1018
+ '13': '400',
1019
+ '14': 'CM4',
1020
+ '15': 'CM4S',
1021
+ '17': '5',
1022
+ };
1023
+
1024
+ const revisionCode = getValue(lines, 'revision', ':', true);
1025
+ const model = getValue(lines, 'model:', ':', true);
1026
+ const serial = getValue(lines, 'serial', ':', true);
1027
+
1028
+ let result = {};
1029
+ if ({}.hasOwnProperty.call(oldRevisionCodes, revisionCode)) {
1030
+ // old revision codes
1031
+ result = {
1032
+ model,
1033
+ serial,
1034
+ revisionCode,
1035
+ memory: oldRevisionCodes[revisionCode].memory,
1036
+ manufacturer: oldRevisionCodes[revisionCode].manufacturer,
1037
+ processor: oldRevisionCodes[revisionCode].processor,
1038
+ type: oldRevisionCodes[revisionCode].type,
1039
+ revision: oldRevisionCodes[revisionCode].revision,
1040
+ };
1041
+
1042
+ } else {
1043
+ // new revision code
1044
+ const revision = ('00000000' + getValue(lines, 'revision', ':', true).toLowerCase()).substr(-8);
1045
+ const memSizeCode = parseInt(hex2bin(revision.substr(2, 1)).substr(5, 3), 2) || 0;
1046
+ const manufacturer = manufacturerList[parseInt(revision.substr(3, 1), 10)];
1047
+ const processor = processorList[parseInt(revision.substr(4, 1), 10)];
1048
+ const typeCode = revision.substr(5, 2);
1049
+
1050
+
1051
+ result = {
1052
+ model,
1053
+ serial,
1054
+ revisionCode,
1055
+ memory: 256 * Math.pow(2, memSizeCode),
1056
+ manufacturer,
1057
+ processor,
1058
+ type: {}.hasOwnProperty.call(typeList, typeCode) ? typeList[typeCode] : '',
1059
+ revision: '1.' + revision.substr(7, 1),
1060
+ };
1061
+ }
1062
+ return result;
1063
+ }
1064
+
1065
+ function getRpiGpu() {
1066
+ let cpuinfo = null;
1067
+ if (_rpi_cpuinfo !== null) {
1068
+ cpuinfo = _rpi_cpuinfo;
1069
+ } else {
1070
+ try {
1071
+ cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).toString().split('\n');
1072
+ _rpi_cpuinfo = cpuinfo;
1073
+ } catch (e) {
1074
+ return false;
1075
+ }
1076
+ }
1077
+
1078
+ const rpi = decodePiCpuinfo(cpuinfo);
1079
+ if (rpi.type === '4B' || rpi.type === 'CM4' || rpi.type === 'CM4S' || rpi.type === '400') { return 'VideoCore VI'; }
1080
+ if (rpi.type === '5') { return 'VideoCore VII'; }
1081
+ return 'VideoCore IV';
1082
+ }
1083
+
1084
+ function promiseAll(promises) {
1085
+ const resolvingPromises = promises.map(function (promise) {
1086
+ return new Promise(function (resolve) {
1087
+ let payload = new Array(2);
1088
+ promise.then(function (result) {
1089
+ payload[0] = result;
1090
+ })
1091
+ .catch(function (error) {
1092
+ payload[1] = error;
1093
+ })
1094
+ .then(function () {
1095
+ // The wrapped Promise returns an array: 0 = result, 1 = error ... we resolve all
1096
+ resolve(payload);
1097
+ });
1098
+ });
1099
+ });
1100
+ const errors = [];
1101
+ const results = [];
1102
+
1103
+ // Execute all wrapped Promises
1104
+ return Promise.all(resolvingPromises)
1105
+ .then(function (items) {
1106
+ items.forEach(function (payload) {
1107
+ if (payload[1]) {
1108
+ errors.push(payload[1]);
1109
+ results.push(null);
1110
+ } else {
1111
+ errors.push(null);
1112
+ results.push(payload[0]);
1113
+ }
1114
+ });
1115
+
1116
+ return {
1117
+ errors: errors,
1118
+ results: results
1119
+ };
1120
+ });
1121
+ }
1122
+
1123
+ function promisify(nodeStyleFunction) {
1124
+ return function () {
1125
+ const args = Array.prototype.slice.call(arguments);
1126
+ return new Promise(function (resolve, reject) {
1127
+ args.push(function (err, data) {
1128
+ if (err) {
1129
+ reject(err);
1130
+ } else {
1131
+ resolve(data);
1132
+ }
1133
+ });
1134
+ nodeStyleFunction.apply(null, args);
1135
+ });
1136
+ };
1137
+ }
1138
+
1139
+ function promisifySave(nodeStyleFunction) {
1140
+ return function () {
1141
+ const args = Array.prototype.slice.call(arguments);
1142
+ return new Promise(function (resolve) {
1143
+ args.push(function (err, data) {
1144
+ resolve(data);
1145
+ });
1146
+ nodeStyleFunction.apply(null, args);
1147
+ });
1148
+ };
1149
+ }
1150
+
1151
+ function linuxVersion() {
1152
+ let result = '';
1153
+ if (_linux) {
1154
+ try {
1155
+ result = execSync('uname -v', util.execOptsLinux).toString();
1156
+ } catch (e) {
1157
+ result = '';
1158
+ }
1159
+ }
1160
+ return result;
1161
+ }
1162
+
1163
+ function plistParser(xmlStr) {
1164
+ const tags = ['array', 'dict', 'key', 'string', 'integer', 'date', 'real', 'data', 'boolean', 'arrayEmpty'];
1165
+ const startStr = '<plist version';
1166
+
1167
+ let pos = xmlStr.indexOf(startStr);
1168
+ let len = xmlStr.length;
1169
+ while (xmlStr[pos] !== '>' && pos < len) {
1170
+ pos++;
1171
+ }
1172
+
1173
+ let depth = 0;
1174
+ let inTagStart = false;
1175
+ let inTagContent = false;
1176
+ let inTagEnd = false;
1177
+ let metaData = [{ tagStart: '', tagEnd: '', tagContent: '', key: '', data: null }];
1178
+ let c = '';
1179
+ let cn = xmlStr[pos];
1180
+
1181
+ while (pos < len) {
1182
+ c = cn;
1183
+ if (pos + 1 < len) { cn = xmlStr[pos + 1]; }
1184
+ if (c === '<') {
1185
+ inTagContent = false;
1186
+ if (cn === '/') { inTagEnd = true; }
1187
+ else if (metaData[depth].tagStart) {
1188
+ metaData[depth].tagContent = '';
1189
+ if (!metaData[depth].data) { metaData[depth].data = metaData[depth].tagStart === 'array' ? [] : {}; }
1190
+ depth++;
1191
+ metaData.push({ tagStart: '', tagEnd: '', tagContent: '', key: null, data: null });
1192
+ inTagStart = true;
1193
+ inTagContent = false;
1194
+ }
1195
+ else if (!inTagStart) { inTagStart = true; }
1196
+ } else if (c === '>') {
1197
+ if (metaData[depth].tagStart === 'true/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/boolean'; metaData[depth].data = true; }
1198
+ if (metaData[depth].tagStart === 'false/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/boolean'; metaData[depth].data = false; }
1199
+ if (metaData[depth].tagStart === 'array/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/arrayEmpty'; metaData[depth].data = []; }
1200
+ if (inTagContent) { inTagContent = false; }
1201
+ if (inTagStart) {
1202
+ inTagStart = false;
1203
+ inTagContent = true;
1204
+ if (metaData[depth].tagStart === 'array') {
1205
+ metaData[depth].data = [];
1206
+ }
1207
+ if (metaData[depth].tagStart === 'dict') {
1208
+ metaData[depth].data = {};
1209
+ }
1210
+ }
1211
+ if (inTagEnd) {
1212
+ inTagEnd = false;
1213
+ if (metaData[depth].tagEnd && tags.indexOf(metaData[depth].tagEnd.substr(1)) >= 0) {
1214
+ if (metaData[depth].tagEnd === '/dict' || metaData[depth].tagEnd === '/array') {
1215
+ if (depth > 1 && metaData[depth - 2].tagStart === 'array') {
1216
+ metaData[depth - 2].data.push(metaData[depth - 1].data);
1217
+ }
1218
+ if (depth > 1 && metaData[depth - 2].tagStart === 'dict') {
1219
+ metaData[depth - 2].data[metaData[depth - 1].key] = metaData[depth - 1].data;
1220
+ }
1221
+ depth--;
1222
+ metaData.pop();
1223
+ metaData[depth].tagContent = '';
1224
+ metaData[depth].tagStart = '';
1225
+ metaData[depth].tagEnd = '';
1226
+ }
1227
+ else {
1228
+ if (metaData[depth].tagEnd === '/key' && metaData[depth].tagContent) {
1229
+ metaData[depth].key = metaData[depth].tagContent;
1230
+ } else {
1231
+ if (metaData[depth].tagEnd === '/real' && metaData[depth].tagContent) { metaData[depth].data = parseFloat(metaData[depth].tagContent) || 0; }
1232
+ if (metaData[depth].tagEnd === '/integer' && metaData[depth].tagContent) { metaData[depth].data = parseInt(metaData[depth].tagContent) || 0; }
1233
+ if (metaData[depth].tagEnd === '/string' && metaData[depth].tagContent) { metaData[depth].data = metaData[depth].tagContent || ''; }
1234
+ if (metaData[depth].tagEnd === '/boolean') { metaData[depth].data = metaData[depth].tagContent || false; }
1235
+ if (metaData[depth].tagEnd === '/arrayEmpty') { metaData[depth].data = metaData[depth].tagContent || []; }
1236
+ if (depth > 0 && metaData[depth - 1].tagStart === 'array') { metaData[depth - 1].data.push(metaData[depth].data); }
1237
+ if (depth > 0 && metaData[depth - 1].tagStart === 'dict') { metaData[depth - 1].data[metaData[depth].key] = metaData[depth].data; }
1238
+ }
1239
+ metaData[depth].tagContent = '';
1240
+ metaData[depth].tagStart = '';
1241
+ metaData[depth].tagEnd = '';
1242
+ }
1243
+ }
1244
+ metaData[depth].tagEnd = '';
1245
+ inTagStart = false;
1246
+ inTagContent = false;
1247
+ }
1248
+ } else {
1249
+ if (inTagStart) { metaData[depth].tagStart += c; }
1250
+ if (inTagEnd) { metaData[depth].tagEnd += c; }
1251
+ if (inTagContent) { metaData[depth].tagContent += c; }
1252
+ }
1253
+ pos++;
1254
+ }
1255
+ return metaData[0].data;
1256
+ }
1257
+
1258
+ function strIsNumeric(str) {
1259
+ return typeof str === 'string' && !isNaN(str) && !isNaN(parseFloat(str));
1260
+ }
1261
+
1262
+ function plistReader(output) {
1263
+ const lines = output.split('\n');
1264
+ for (let i = 0; i < lines.length; i++) {
1265
+ if (lines[i].indexOf(' = ') >= 0) {
1266
+ const lineParts = lines[i].split(' = ');
1267
+ lineParts[0] = lineParts[0].trim();
1268
+ if (!lineParts[0].startsWith('"')) {
1269
+ lineParts[0] = '"' + lineParts[0] + '"';
1270
+ }
1271
+ lineParts[1] = lineParts[1].trim();
1272
+ if (lineParts[1].indexOf('"') === -1 && lineParts[1].endsWith(';')) {
1273
+ const valueString = lineParts[1].substring(0, lineParts[1].length - 1);
1274
+ if (!strIsNumeric(valueString)) {
1275
+ lineParts[1] = `"${valueString}";`;
1276
+ }
1277
+ }
1278
+ if (lineParts[1].indexOf('"') >= 0 && lineParts[1].endsWith(';')) {
1279
+ const valueString = lineParts[1].substring(0, lineParts[1].length - 1).replace(/"/g, '');
1280
+ if (strIsNumeric(valueString)) {
1281
+ lineParts[1] = `${valueString};`;
1282
+ }
1283
+ }
1284
+ lines[i] = lineParts.join(' : ');
1285
+ }
1286
+ lines[i] = lines[i].replace(/\(/g, '[').replace(/\)/g, ']').replace(/;/g, ',').trim();
1287
+ if (lines[i].startsWith('}') && lines[i - 1] && lines[i - 1].endsWith(',')) {
1288
+ lines[i - 1] = lines[i - 1].substring(0, lines[i - 1].length - 1);
1289
+ }
1290
+ }
1291
+ output = lines.join('');
1292
+ let obj = {};
1293
+ try {
1294
+ obj = JSON.parse(output);
1295
+ } catch (e) {
1296
+ noop();
1297
+ }
1298
+ return obj;
1299
+ }
1300
+
1301
+ function semverCompare(v1, v2) {
1302
+ let res = 0;
1303
+ const parts1 = v1.split('.');
1304
+ const parts2 = v2.split('.');
1305
+ if (parts1[0] < parts2[0]) { res = 1; }
1306
+ else if (parts1[0] > parts2[0]) { res = -1; }
1307
+ else if (parts1[0] === parts2[0] && parts1.length >= 2 && parts2.length >= 2) {
1308
+ if (parts1[1] < parts2[1]) { res = 1; }
1309
+ else if (parts1[1] > parts2[1]) { res = -1; }
1310
+ else if (parts1[1] === parts2[1]) {
1311
+ if (parts1.length >= 3 && parts2.length >= 3) {
1312
+ if (parts1[2] < parts2[2]) { res = 1; }
1313
+ else if (parts1[2] > parts2[2]) { res = -1; }
1314
+ } else if (parts2.length >= 3) {
1315
+ res = 1;
1316
+ }
1317
+ }
1318
+ }
1319
+ return res;
1320
+ }
1321
+
1322
+ function noop() { }
1323
+
1324
+ exports.toInt = toInt;
1325
+ exports.splitByNumber = splitByNumber;
1326
+ exports.execOptsWin = execOptsWin;
1327
+ exports.execOptsLinux = execOptsLinux;
1328
+ exports.getCodepage = getCodepage;
1329
+ exports.execWin = execWin;
1330
+ exports.isFunction = isFunction;
1331
+ exports.unique = unique;
1332
+ exports.sortByKey = sortByKey;
1333
+ exports.cores = cores;
1334
+ exports.getValue = getValue;
1335
+ exports.decodeEscapeSequence = decodeEscapeSequence;
1336
+ exports.parseDateTime = parseDateTime;
1337
+ exports.parseHead = parseHead;
1338
+ exports.findObjectByKey = findObjectByKey;
1339
+ exports.getWmic = getWmic;
1340
+ exports.wmic = wmic;
1341
+ exports.darwinXcodeExists = darwinXcodeExists;
1342
+ exports.getVboxmanage = getVboxmanage;
1343
+ exports.powerShell = powerShell;
1344
+ exports.powerShellStart = powerShellStart;
1345
+ exports.powerShellRelease = powerShellRelease;
1346
+ exports.execSafe = execSafe;
1347
+ exports.nanoSeconds = nanoSeconds;
1348
+ exports.countUniqueLines = countUniqueLines;
1349
+ exports.countLines = countLines;
1350
+ exports.noop = noop;
1351
+ exports.isRaspberry = isRaspberry;
1352
+ exports.isRaspbian = isRaspbian;
1353
+ exports.sanitizeShellString = sanitizeShellString;
1354
+ exports.isPrototypePolluted = isPrototypePolluted;
1355
+ exports.decodePiCpuinfo = decodePiCpuinfo;
1356
+ exports.getRpiGpu = getRpiGpu;
1357
+ exports.promiseAll = promiseAll;
1358
+ exports.promisify = promisify;
1359
+ exports.promisifySave = promisifySave;
1360
+ exports.smartMonToolsInstalled = smartMonToolsInstalled;
1361
+ exports.linuxVersion = linuxVersion;
1362
+ exports.plistParser = plistParser;
1363
+ exports.plistReader = plistReader;
1364
+ exports.stringReplace = stringReplace;
1365
+ exports.stringToLower = stringToLower;
1366
+ exports.stringToString = stringToString;
1367
+ exports.stringSubstr = stringSubstr;
1368
+ exports.stringTrim = stringTrim;
1369
+ exports.stringStartWith = stringStartWith;
1370
+ exports.mathMin = mathMin;
1371
+ exports.WINDIR = WINDIR;
1372
+ exports.getFilesInPath = getFilesInPath;
1373
+ exports.semverCompare = semverCompare;