forked from inotia00/rvx-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateFiles.js
85 lines (74 loc) · 1.94 KB
/
updateFiles.js
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
const { existsSync, mkdirSync, rmSync } = require('node:fs');
const { join: joinPath } = require('node:path');
const { getSources } = require('../utils/Settings.js');
const { downloadFiles } = require('../utils/FileDownloader.js');
const checkJDKAndAapt2 = require('../utils/checkJDKAndAapt2.js');
const checkJDkAndADB = require('../utils/checkJDKAndADB.js');
global.revancedDir = joinPath(process.cwd(), 'revanced');
global.javaCmd = 'java';
global.jarNames = {
cli: '',
patchesJar: global.revancedDir,
integrations: global.revancedDir,
microG: global.revancedDir,
patchesList: global.revancedDir,
selectedApp: '',
patches: '',
isRooted: false,
deviceID: '',
patch: {
integrations: false
}
};
/**
* @param {import('ws').WebSocket} ws
*/
module.exports = async function updateFiles(ws) {
const source = getSources();
const patches = source.patches.split('/');
const integrations = source.integrations.split('/');
if (!existsSync(global.revancedDir)) mkdirSync(global.revancedDir);
if (existsSync('revanced-cache'))
rmSync('revanced-cache', { recursive: true, force: true });
const filesToDownload = [
{
owner: 'revanced',
repo: 'revanced-cli'
},
{
owner: patches[0],
repo: patches[1]
},
{
owner: integrations[0],
repo: integrations[1]
},
{
owner: 'TeamVanced',
repo: 'VancedMicroG'
}
];
if (
typeof global.downloadFinished !== 'undefined' &&
!global.downloadFinished
) {
ws.send(
JSON.stringify({
event: 'error',
error:
"Downloading process hasn't finished and you tried to download again."
})
);
return;
}
global.downloadFinished = false;
await downloadFiles(filesToDownload, ws);
if (process.platform === 'android') await checkJDKAndAapt2(ws);
else await checkJDkAndADB(ws);
global.downloadFinished = true;
ws.send(
JSON.stringify({
event: 'finished'
})
);
};