-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
138 lines (124 loc) · 3.91 KB
/
Copy pathindex.js
File metadata and controls
138 lines (124 loc) · 3.91 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
138
import fs from 'node:fs'
import { Version } from './components/index.js'
if (!global.segment) {
global.segment = (await import('oicq')).segment
}
logger.info(logger.green('正在加载ark-plugin'))
const files = fs.readdirSync('./plugins/ark-plugin/apps').filter(file => file.endsWith('.js'))
let ret = []
files.forEach((file) => {
ret.push(import(`./apps/${file}`))
})
ret = await Promise.allSettled(ret)
let apps = {}
for (let i = 0; i < files.length; i++) {
let name = files[i].replace('.js', '')
if (ret[i].status !== 'fulfilled') {
logger.error(`载入插件错误:${logger.red(name)}`)
logger.error(ret[i].reason)
continue
}
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
}
// 3. Config Backup
const backupPath = './plugins/ark-plugin/config/backup.json'
if (!fs.existsSync(backupPath)) {
fs.cpSync(
'./plugins/ark-plugin/defset/config/backup.json',
backupPath,
{ recursive: true }
)
}
const suffix = Version.isQsyhh ? '-qsyhh' : ''
const backupBase = `../../../ark-plugin/backup/miao-plugin-rank${suffix}`
let symlinkCount = 0
let arkInitStatus = null
let stygianInitStatus = false
const createSymlink = ({ src, dest }) => {
try {
fs.lstatSync(src)
symlinkCount++
} catch {
try {
fs.symlinkSync(dest, src, 'file')
symlinkCount++
} catch (err) {
logger.error(`软链接文件时出现问题 ${err}`)
}
}
}
let ArkInit
try {
ArkInit = (await import(`./model/init${suffix}.js`)).default
const ArkCfg = (await import('./components/Cfg.js')).default
if (ArkCfg.get('lnFiles', false)) {
const links = [
{
src: './plugins/miao-plugin/resources/character/profile-detail-ark.html',
dest: `${backupBase}/resources/character/profile-detail.html`
}
]
if (Version.isQsyhh) {
links.push({
src: './plugins/miao-plugin/resources/character/rank-profile-list-ark.css',
dest: `${backupBase}/resources/character/rank-profile-list.css`
})
}
links.push({
src: './plugins/miao-plugin/resources/character/rank-profile-list-ark.html',
dest: `${backupBase}/resources/character/rank-profile-list.html`
})
links.forEach(createSymlink)
}
} catch (err) {
logger.warn(`[ark-plugin] 功能注入失败: ${err?.message || err}`)
}
if (ArkInit?.init) {
try {
const status = ArkInit.init()
if (status) {
arkInitStatus = status
}
} catch (err) {
logger.warn('ProfileRank 初始化失败', err)
}
}
let stygianInit
try {
stygianInit = (await import(`./model/stygian-init${suffix}.js`)).default
} catch (err) {
logger.warn('幽境危战排名初始化失败')
logger.warn(err)
}
if (stygianInit?.init) {
try {
stygianInit.init()
stygianInitStatus = true
} catch (err) {
logger.error('幽境危战初始化失败', err)
}
}
const lnStatus = symlinkCount > 0
? logger.green(`✔ 已链接 ${symlinkCount} 个文件`)
: logger.red('⚠ 未启用或无链接')
const profileDetailStatus = arkInitStatus?.ProfileDetail || logger.red('✖ 注入失败(初始化异常)')
const charRankStatus = arkInitStatus?.CharRank || logger.red('✖ 注入失败(初始化异常)')
const stygianStatus = stygianInitStatus
? logger.green('✔ 注入成功')
: logger.red('✖ 注入失败')
let uiOutput = `
${logger.green('==============ark-plugin加载完毕===============')}
软链接状态: ${lnStatus}
功能注入:
- ProfileDetail: ${profileDetailStatus}
- ProfileRank: ${charRankStatus}
- 幽境危战排名: ${stygianStatus}
`
if (arkInitStatus?.shouldReplace) {
uiOutput += `
${logger.red('⚠ 检测到核心文件未替换,请执行 #ark替换文件miao-rank 以使用完整功能')}
`
}
uiOutput += logger.green('===============================================')
logger.info(uiOutput)
export { apps }