-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDyingLight2.ts
197 lines (165 loc) · 6.07 KB
/
DyingLight2.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
/**
* @description 消逝的光芒2 支持
*/
import { join, extname, basename } from 'path'
import { statSync } from 'fs'
import { ElMessage } from "element-plus";
let pakList = {
get data() {
let manager = useManager()
let file = join(manager.modStorage, 'pakList.txt')
// console.log(file);
let data = FileHandler.readFile(file, '')
// 将字符串转为数组
let dataList = data.split('\n')
// 将里面的空字符串去掉
let list = dataList.filter(item => item != '')
// 将数组转换为二维数组, 使用 | 分割
let pakList = list.map(item => item.split('|'))
return pakList
},
set data(value) {
// console.log("写入");
let manager = useManager()
let file = join(manager.modStorage, 'pakList.txt')
let data = value.map(item => item.join('|')).join('\n')
FileHandler.writeFile(file, data)
}
}
function getGameFileName(isDat: boolean) {
const manager = useManager()
let dataFolder = join(manager.gameStorage, "ph", "source")
let datFiles = FileHandler.getFolderFiles(dataFolder).filter(item => extname(item) == '.pak')
// 获取 "data3.pak" 中的 data3.pak 为 3
let datNum = datFiles.map(item => {
const match = item.match(/data(\d+)/i);
return match ? parseInt(match[1]) : 0;
})
// 获取最大的数字
let maxNum = Math.max(...datNum)
if (isDat) maxNum += 1
let datName = `data${maxNum}`
// console.log(datName);
return datName
}
async function handlePak(mod: IModInfo, isInstall: boolean) {
const manager = useManager()
let pakListData = pakList.data
mod.modFiles.forEach(item => {
let modStorage = join(manager.modStorage ?? "", mod.id.toString(), item)
if (statSync(modStorage).isFile() && extname(modStorage) == '.pak') {
let gameStorage = join(manager.gameStorage ?? "")
if (isInstall) {
let pakName = getGameFileName(extname(modStorage) == '.pak')
let gamePak = join(gameStorage, 'ph', 'source', pakName + extname(modStorage))
FileHandler.copyFile(modStorage, gamePak)
pakListData.push([mod.id.toString(), basename(modStorage), pakName + extname(modStorage)])
} else {
let modPakInGamePak = pakListData.filter(item => item[0] == mod.id.toString())
let pakName = modPakInGamePak.find(item => extname(item[1]) == extname(modStorage))
if (pakName) {
// console.log(pakName[2]);
pakListData = pakListData.filter(item => item != pakName)
let gamePak = join(gameStorage, 'ph', 'source', pakName[2])
FileHandler.deleteFile(gamePak)
}
}
}
})
if (!isInstall) {
/**
* 卸载逻辑 文件命名规则为
data0.pak
data1.pak
data2.pak
data3.pak
data4.pak
data5.pak
data6.pak
如果卸载的是 data2.pak, 那么后面的 data3.pak 以后的文件都要往前移动
先获取所有pak文件,然后判断缺少了哪个 pak 再将后面的pak 往前移动序号
pakListData 里面是当前剩余的 pak 列表
*/
// 按照文件名进行排序
pakListData.sort((a, b) => {
const fileNumA = parseInt(a[2].replace('data', '').replace('.pak', ''))
const fileNumB = parseInt(b[2].replace('data', '').replace('.pak', ''))
return fileNumA - fileNumB
})
let expectedFileNum = 2
for (let index in pakListData) {
let item = pakListData[index]
const currentFileNum = parseInt(item[2].replace('data', '').replace('.pak', ''))
// 如果当前的文件号和预期的文件号不匹配
// 那么我们就找到了所需跳动的文件号
if (currentFileNum !== expectedFileNum) {
const manager = useManager()
const fileName = `data${String(expectedFileNum)}.pak`
await FileHandler.renameFile(join(manager.gameStorage, 'ph', 'source', item[2]), join(manager.gameStorage, 'ph', 'source', fileName))
item[2] = fileName
}
// 预期的文件号进行加 1 操作
expectedFileNum++
}
}
pakList.data = pakListData
// console.log(pakListData);
return true
}
export const supportedGames: ISupportedGames = {
GlossGameId: 272,
steamAppID: 534380,
installdir: join("Dying Light 2", "ph", "work", "bin", "x64"),
gameName: "Dying Light 2",
gameExe: [
{
name: "DyingLightGame_x64_rwdi.exe",
rootPath: join('..', '..', '..', "..")
}
],
startExe: [
{
name: "Steam 启动",
cmd: "steam://rungameid/534380"
},
{
name: "直接启动",
exePath: join("ph", "work", "bin", "x64", "DyingLightGame_x64_rwdi.exe")
}
],
archivePath: join(FileHandler.getMyDocuments(), "dying light 2", "out"),
gameCoverImg: "https://mod.3dmgame.com/static/upload/game/61dbf5a660a03.png",
modType: [
{
id: 1,
name: 'dat',
installPath: join('ph', 'source'),
async install(mod) {
return handlePak(mod, true)
},
async uninstall(mod) {
return handlePak(mod, false)
}
},
{
id: 99,
name: '未知',
installPath: '\\',
async install(mod) {
ElMessage.warning("该mod类型未知, 无法自动安装, 请手动安装!")
return false
},
async uninstall(mod) {
return true
}
}
],
checkModType(mod) {
let data = false
mod.modFiles.forEach(item => {
if (extname(item) == '.pak') data = true
})
if (data) return 1
return 99
}
}