-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_install_debug.js
More file actions
110 lines (89 loc) · 3.34 KB
/
Copy pathtest_install_debug.js
File metadata and controls
110 lines (89 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const { spawn } = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
function findCurl() {
const candidates = [
path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'curl.exe'),
path.join(process.env.SystemRoot || 'C:\\Windows', 'SysWOW64', 'curl.exe'),
'curl.exe'
];
for (const c of candidates) {
if (fs.existsSync(c)) return c;
}
return null;
}
async function testInstall(id, url, filename, type) {
console.log('=== TESTING', id, '===');
const curlPath = findCurl();
console.log('curlPath:', curlPath);
if (!curlPath) {
console.log('ERROR: curl not found');
return;
}
const tmpFile = path.join(os.tmpdir(), `atom_${id}_${filename}`);
console.log('tmpFile:', tmpFile);
return new Promise((resolve) => {
const curlArgs = ['-L', '--max-redirs', '10', '-o', tmpFile, url];
console.log('Spawning:', curlPath, curlArgs);
const dlProc = spawn(curlPath, curlArgs, { windowsHide: true });
let dlOutput = '';
dlProc.on('error', (err) => {
console.log('DL SPAWN ERROR:', err.message);
resolve({ success: false, error: err.message });
});
dlProc.stderr.on('data', (data) => {
dlOutput += data.toString();
});
dlProc.stdout.on('data', (data) => {
dlOutput += data.toString();
});
dlProc.on('close', (dlCode) => {
console.log('DL exit:', dlCode);
console.log('DL output:', dlOutput.substring(0, 300));
if (dlCode !== 0) {
resolve({ success: false, stage: 'download', code: dlCode, output: dlOutput });
return;
}
if (!fs.existsSync(tmpFile)) {
resolve({ success: false, stage: 'download', error: 'File not found' });
return;
}
const size = fs.statSync(tmpFile).size;
console.log('File size:', size);
if (size < 1000) {
const content = fs.readFileSync(tmpFile, 'utf8').substring(0, 500);
console.log('File too small:', content);
resolve({ success: false, stage: 'download', error: 'Too small', content });
return;
}
console.log('Download OK, size:', size);
// Install
let installCmd;
switch (type) {
case 'msi': installCmd = `msiexec /i "${tmpFile}" /norestart`; break;
case 'portable': installCmd = `echo portable`; break;
default: installCmd = `"${tmpFile}"`; break;
}
console.log('Install cmd:', installCmd);
const instProc = spawn('cmd', ['/c', installCmd], { windowsHide: true });
let instOutput = '';
instProc.on('error', (err) => {
console.log('INSTALL SPAWN ERROR:', err.message);
resolve({ success: false, stage: 'install', error: err.message });
});
instProc.stdout.on('data', d => instOutput += d);
instProc.stderr.on('data', d => instOutput += d);
instProc.on('close', (instCode) => {
console.log('Install exit:', instCode);
console.log('Install output:', instOutput.substring(0, 300));
setTimeout(() => { try { fs.unlinkSync(tmpFile); } catch {} }, 3000);
resolve({ success: instCode === 0 || instCode === 3010, code: instCode, output: instOutput });
});
});
});
}
(async () => {
const r = await testInstall('sevenzip', 'https://www.7-zip.org/a/7z2408-x64.exe', '7zip.exe', 'exe_inno');
console.log('\nRESULT:', r);
})();