-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStarfield.ts
296 lines (262 loc) · 8.89 KB
/
Starfield.ts
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// 星空 Mod支持
import { extname, basename, join, dirname } from 'path'
import { ElMessage } from "element-plus";
import { statSync, readFileSync, writeFileSync } from "fs";
import ini from 'ini'
import { homedir } from 'os'
//#region data 类型的mod
// 设置 Starfield.ini
async function setArchive() {
try {
const manager = useManager()
// let documents = await FileHandler.getMyDocuments()
const Starfield = join(manager.gameStorage, "Starfield.ini")
let config = ini.parse(readFileSync(Starfield, 'utf-8'))
// console.log(config);
if (config.Archive?.bInvalidateOlderFiles == 1) {
console.log('StarfieldPrefs.ini 已配置过, 无需再次配置.');
return
}
if (config.Archive) {
config.Archive.bInvalidateOlderFiles = 1
config.Archive.sResourceDataDirsFinal = ""
writeFileSync(Starfield, ini.stringify(config))
}
} catch (error) {
ElMessage.error(`配置 StarfieldPrefs.ini 失败! ${error}`)
}
}
// 修改 plugins
async function setPlugins(mod: IModInfo, install: boolean) {
// AppData\Local\Fallout4\plugins.txt
let documents = join(homedir(), "AppData", "Local", "Starfield", "plugins.txt")
let plugins = await FileHandler.readFileSync(documents)
let arr = plugins.split('\n')
if (arr[0] != "# This file is used by Starfield to keep track of your downloaded content. (You HAVE to keep a # on the first line here)") {
arr.unshift("# This file is used by Starfield to keep track of your downloaded content. (You HAVE to keep a # on the first line here)")
}
mod.modFiles.forEach(item => {
if (extname(item) == '.esp' || extname(item) == '.esm') {
if (install) {
arr.push(`*${basename(item)}`)
} else {
arr = arr.filter(i => i != `*${basename(item)}`)
}
}
})
// arr 中移除空内容
arr = arr.filter(i => i != "")
FileHandler.writeFile(documents, arr.join('\n'))
}
//#endregion
//#region Plugins 类型的mod
// 安装到 Plugins
async function handlePlugins(mod: IModInfo, installPath: string, isInstall: boolean) {
if (isInstall) Manager.checkInstalled("SFSE", 201756)
return Manager.installByFolder(mod, installPath, "plugins", isInstall, false, true)
}
//#endregion
//#region esp 类型的mod
function setGeneral(name: string, isInstall: boolean) {
const manager = useManager()
// let documents = await FileHandler.getMyDocuments()
const Starfield = join(manager.gameStorage, "Starfield.ini")
let config = ini.parse(readFileSync(Starfield, 'utf-8'))
// 获取 config.General 下面的所有 key
let keys = Object.keys(config.General)
// console.log(keys);
if (isInstall) {
// 判断 key 中是否有包含 sTestFile 的
let hasKey = keys.some(item => item.includes('sTestFile'))
if (hasKey) {
/**
* sTestFile1
* sTestFile2
* sTestFile3
*/
let lastKey = keys[keys.length - 1]
let lastNum = parseInt(lastKey[lastKey.length - 1])
config.General[`sTestFile${lastNum + 1}`] = name
} else {
config.General.sTestFile1 = name
}
} else {
// 如果是卸载 将所有 sTestFileX=name 删除
keys.forEach(item => {
if (config.General[item] == name) {
delete config.General[item]
}
})
}
writeFileSync(Starfield, ini.stringify(config))
}
function handleEsps(mod: IModInfo, installPath: string, isInstall: boolean) {
const manager = useManager()
mod.modFiles.forEach(item => {
let file = join(manager.modStorage, mod.id.toString(), item)
if (statSync(file).isFile()) {
let name = basename(file)
if (extname(file) == '.esp') setGeneral(name, isInstall)
let target = join(manager.gameStorage ?? "", installPath, item)
if (isInstall) {
FileHandler.copyFile(file, target)
} else {
FileHandler.deleteFile(target)
}
}
})
return true
}
//#endregion
// 获取 sfse_loader.exe 所在目录
function getBaseFolder(mod: IModInfo) {
let folder = ""
mod.modFiles.forEach(item => {
if (basename(item) == 'sfse_loader.exe') {
folder = dirname(item)
}
})
return folder
}
function handleSfse(mod: IModInfo, install: boolean) {
const manager = useManager()
const modStorage = join(manager.modStorage ?? "", mod.id.toString())
let baseFolder = getBaseFolder(mod)
if (baseFolder == "") {
ElMessage.error(`未找到 sfse_loader.exe, 请不要随意修改MOD类型`)
return false
}
mod.modFiles.forEach(item => {
let source = join(modStorage, item)
if (statSync(source).isFile()) {
// 从 item 中移除 folder
let path = item
if (baseFolder != '.') {
path = item.replace(baseFolder, "")
}
// console.log(path);
let target = join(manager.gameStorage ?? "", path)
if (install) FileHandler.copyFile(source, target)
else FileHandler.deleteFile(target)
}
})
return true
}
export const supportedGames: ISupportedGames = {
GlossGameId: 321,
steamAppID: 1716740,
NexusMods: {
game_domain_name: "starfield",
game_id: 4187
},
installdir: join("Starfield"),
gameName: "Starfield",
gameExe: "Starfield.exe",
startExe: [
{
name: 'Steam 启动',
cmd: 'steam://rungameid/1716740'
},
{
name: 'SFSE 启动',
exePath: 'sfse_loader.exe'
},
{
name: '直接启动',
exePath: 'Starfield.exe'
},
],
archivePath: join(FileHandler.getMyDocuments(), "My Games", "Starfield"),
gameCoverImg: "https://mod.3dmgame.com/static/upload/game/64db454e9f5c4.webp",
modType: [
{
id: 1,
name: 'data',
installPath: join("Data"),
async install(mod) {
setArchive();
// symlinkData();
setPlugins(mod, true)
return Manager.installByFolder(mod, this.installPath ?? "", "data", true, false, true)
},
async uninstall(mod) {
setPlugins(mod, false)
return Manager.installByFolder(mod, this.installPath ?? "", "data", false, false, true)
},
},
{
id: 2,
name: '游戏根目录',
installPath: join(""),
async install(mod) {
return Manager.generalInstall(mod, this.installPath ?? "", true)
},
async uninstall(mod) {
return Manager.generalUninstall(mod, this.installPath ?? "", true)
},
},
{
id: 3,
name: 'sfse',
installPath: join(""),
async install(mod) {
return handleSfse(mod, true)
},
async uninstall(mod) {
return handleSfse(mod, false)
},
},
{
id: 4,
name: 'Plugins',
installPath: join("Data", "SFSE", "plugins"),
async install(mod) {
return handlePlugins(mod, this.installPath ?? "", true)
},
async uninstall(mod) {
return handlePlugins(mod, this.installPath ?? "", false)
}
},
{
id: 5,
name: 'esp',
installPath: join("Data"),
async install(mod) {
return handleEsps(mod, this.installPath ?? "", true)
},
async uninstall(mod) {
return handleEsps(mod, this.installPath ?? "", false)
}
},
{
id: 99,
name: '未知',
installPath: '',
async install(mod) {
ElMessage.warning("该mod类型未知, 无法自动安装, 请手动安装!")
return false
},
async uninstall(mod) {
return true
}
}
],
checkModType(mod) {
let data = false
let plugins = false
let esp = false
let sfse = false
mod.modFiles.forEach(item => {
if (item.toLowerCase().includes('data')) data = true
if (item.toLowerCase().includes('plugins')) plugins = true
// if (extname(item) == '.dll') plugins = true
if (extname(item) == '.esp' || extname(item) == '.esm') data = true
if (basename(item) == 'sfse_loader.exe') sfse = true
})
if (sfse) return 3
if (data) return 1
if (plugins) return 4
if (esp) return 5
return 99
}
}