feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const fs = require('fs')
|
||||
const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/'
|
||||
function patch(file, pairs) {
|
||||
const p = base + file
|
||||
let c = fs.readFileSync(p, 'utf8')
|
||||
for (const [from, to] of pairs) {
|
||||
if (!c.includes(from)) {
|
||||
console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n'))
|
||||
continue
|
||||
}
|
||||
c = c.replace(from, to)
|
||||
}
|
||||
fs.writeFileSync(p, c, 'utf8')
|
||||
}
|
||||
|
||||
patch('main/index.ts', [
|
||||
// 迁移时把旧全局配置复制进 default(保留主题/皮肤设置)
|
||||
[
|
||||
` for (const item of ['save.json', 'photos.json', 'files.json']) {
|
||||
const src = path.join(baseDir, item)
|
||||
if (fs.existsSync(src)) fs.renameSync(src, path.join(target, item))
|
||||
}`,
|
||||
` for (const item of ['save.json', 'photos.json', 'files.json']) {
|
||||
const src = path.join(baseDir, item)
|
||||
if (fs.existsSync(src)) fs.renameSync(src, path.join(target, item))
|
||||
}
|
||||
{
|
||||
const srcCfg = path.join(baseDir, 'config.json')
|
||||
if (fs.existsSync(srcCfg)) fs.copyFileSync(srcCfg, path.join(target, 'config.json'))
|
||||
}`
|
||||
],
|
||||
// 切换时写全局指针,重启后仍回到该存档
|
||||
[
|
||||
` store.setConfig({ profile: sanitizeId(String(id)) })
|
||||
loadProfile(String(id))`,
|
||||
` store.setConfig({ profile: sanitizeId(String(id)) })
|
||||
try {
|
||||
const globalCfg = path.join(HOME, 'data', 'config.json')
|
||||
const existing = fs.existsSync(globalCfg)
|
||||
? JSON.parse(fs.readFileSync(globalCfg, 'utf8'))
|
||||
: {}
|
||||
existing.profile = sanitizeId(String(id))
|
||||
fs.writeFileSync(globalCfg, JSON.stringify(existing, null, 2), 'utf8')
|
||||
} catch (err) {
|
||||
console.error('[profile] 指针写入失败', err)
|
||||
}
|
||||
loadProfile(String(id))`
|
||||
]
|
||||
])
|
||||
|
||||
console.log('profile persistence patched')
|
||||
Reference in New Issue
Block a user