-
Notifications
You must be signed in to change notification settings - Fork 5
/
debugCopy.js
60 lines (49 loc) · 1.8 KB
/
debugCopy.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
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const sevenZip = require('node-7z');
const sourceArchive = 'game-valheim.7z';
const destinationDirectory = path.join(process.env.APPDATA, 'vortex_devel', 'plugins');
const copyArchive = (source, destination) => {
const sourceStream = fs.createReadStream(source);
const destinationPath = path.join(destination, path.basename(source));
const destinationStream = fs.createWriteStream(destinationPath);
sourceStream.pipe(destinationStream);
destinationStream.on('close', () => {
console.log('Archive copied to destination directory.');
extractArchive(destinationPath, destination);
});
destinationStream.on('error', (error) => {
console.error('Error copying archive:', error);
});
};
const removeArchive = (archivePath) => {
fs.unlink(archivePath, (unlinkErr) => {
if (unlinkErr) {
console.error('Error removing archive:', unlinkErr);
} else {
console.log('Archive removed from the destination directory.');
}
});
};
const removeFolderRecursive = (folderPath) => {
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach((file) => {
const currentPath = path.join(folderPath, file);
if (fs.lstatSync(currentPath).isDirectory()) {
removeFolderRecursive(currentPath);
} else {
fs.unlinkSync(currentPath);
}
});
fs.rmdirSync(folderPath);
}
}
const extractArchive = async (archivePath, destination) => {
const destinationPath = path.join(destination, path.basename(archivePath, '.7z'));
removeFolderRecursive(destinationPath);
const seven = new sevenZip();
await seven.extractFull(archivePath, destinationPath);
removeArchive(archivePath);
};
copyArchive(sourceArchive, destinationDirectory);