-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModManager.js
More file actions
137 lines (120 loc) · 4.86 KB
/
ModManager.js
File metadata and controls
137 lines (120 loc) · 4.86 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const fs = require('fs');
https = require('https');
var unzip = require('unzipper')
const { exec } = require('child_process');
class ModManager{
constructor(){
}
createModPackFolder(name){
if(!fs.existsSync(window.lethal_company_dir + '/LCML/' + name)){
fs.mkdirSync(window.lethal_company_dir + '/LCML/' + name)
}
}
getModpacks(){
//read directory ecludeing modpacks.json
var files = fs.readdirSync(window.lethal_company_dir + '/LCML')
var modpacks = []
files.forEach((file) => {
if(file != 'modpacks.json'){
modpacks.push(file)
}
})
return modpacks
}
ensureBepinExInstalled(modpack){
if(!fs.existsSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx')){
fs.mkdirSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx')
fs.cp(window.lethal_company_dir + '/LCMLVIRGINBepInEx', window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx', {recursive: true}, (err) => {
})
}
}
getModpackMods(modpack){
var mods = []
var files = fs.readdirSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins')
files.forEach((file) => {
mods.push(file)
})
return mods
}
getModInfo(modpack, mod){
return new Promise((resolve, reject) => {
if(fs.existsSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins/' + mod + '/manifest.json')){
var mod_info = JSON.parse(fs.readFileSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins/' + mod + '/manifest.json').toString())
resolve(mod_info)
}else{
resolve({
name: mod,
version: 'unknown',
description: 'unknown'
})
}
})
}
buildDoorstopConfig(modname){
return `[UnityDoorstop]
enabled=true
targetAssembly=LCML/${modname}/BepInEx/core/BepInEx.Preloader.dll
redirectOutputLog=false
ignoreDisableSwitch=false
dllSearchPathOverride=`
}
setCurrentDoorstopConfig(doorstop_config){
fs.writeFileSync(window.lethal_company_dir + '/doorstop_config.ini', doorstop_config)
}
openModPackFolder(modpack){
var fullPath = window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins'
exec(`start "" "${fullPath}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(`Stdout: ${stdout}`);
});
}
getModPackReadme(modpack, mod){
return new Promise((resolve, reject) => {
if(fs.existsSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins/' + mod + '/README.md')){
resolve(fs.readFileSync(window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins/' + mod + '/README.md').toString())
}else{
resolve('No README.md found')
}
})
}
downloadMod(url, modpack){
//download zip file from url
//unzip file to modpack folder
//delete zip file
var zip_file_name = url.split('/')
zip_file_name = zip_file_name[zip_file_name.length - 1]
var zip_file_path = window.lethal_company_dir + '/LCML/' + modpack + '/' + zip_file_name
var unzip_path = window.lethal_company_dir + '/LCML/' + modpack + '/BepInEx/plugins/' + zip_file_name.split('.')[0]
return new Promise(resolve => {
let file = fs.createWriteStream(zip_file_path)
https.get(url, function(response) {
var total_size = parseInt(response.headers['content-length'], 10) / 1048576 //1048576 - bytes in 1Megabyte
console.log(total_size)
response.pipe(file)
file.on("finish", () => {
file.close()
resolve()
})
})
}).then(() => {
//now we unzip the file
return new Promise(resolve => {
fs.createReadStream(zip_file_path).pipe(unzip.Extract({ path: unzip_path})).on('close', () => {
resolve()
})
}).then(() => {
//now we delete the zip file
fs.unlinkSync(zip_file_path)
window.ViewManager.view_modpack_view(modpack)
})
})
}
}
module.exports = ModManager;