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', [ // 统一的资源目录解析(打包后资源在 resources/) [ `function bundledSkins(): string { return app.isPackaged ? path.join(process.resourcesPath, 'skins') : path.join(APP_DIR, 'assets', 'skins') }`, `function bundledDir(name: string): string { return app.isPackaged ? path.join(process.resourcesPath, name) : path.join(APP_DIR, 'assets', name) } function bundledSkins(): string { return bundledDir('skins') }` ], [ `function userSkins(): string { const dir = path.join(HOME, 'skins') try { if (!fs.existsSync(dir)) fs.cpSync(bundledSkins(), dir, { recursive: true }) } catch (err) { console.warn('[skins] 播种失败,回退到内置目录', err) return bundledSkins() } return dir }`, `function userSkins(): string { const dir = path.join(HOME, 'skins') try { if (!fs.existsSync(dir)) fs.cpSync(bundledSkins(), dir, { recursive: true }) } catch (err) { console.warn('[skins] 播种失败,使用空目录', err) } try { fs.mkdirSync(dir, { recursive: true }) } catch { /* 忽略 */ } return dir }` ], [ `function libRoot(): string { return app.isPackaged ? path.join(process.resourcesPath, 'lib') : path.join(APP_DIR, 'assets', 'lib') }`, `function libRoot(): string { return bundledDir('lib') }` ], // 表情包目录 [ ` } else if (url.host === 'stickers') { const dir = path.join(APP_DIR, 'assets', 'stickers') abs = path.join(dir, rel) root = dir } else if (url.host === 'music') {`, ` } else if (url.host === 'stickers') { const dir = bundledDir('stickers') abs = path.join(dir, rel) root = dir } else if (url.host === 'music') {` ], [ ` const p = path.join(APP_DIR, 'assets', 'stickers', '1.0.png') if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: 256, height: 256 })`, ` const p = path.join(bundledDir('stickers'), '1.0.png') if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: 256, height: 256 })` ], [ ` const p = path.join(APP_DIR, 'assets', 'stickers', '1.0.png') if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: 32, height: 32 })`, ` const p = path.join(bundledDir('stickers'), '1.0.png') if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: 32, height: 32 })` ], // 扫描皮肤:任何异常都不要抛到定时器 [ `function scanSkinsForNew(): boolean { const root = userSkins() let changed = false for (const d of fs.readdirSync(root, { withFileTypes: true })) {`, `function scanSkinsForNew(): boolean { const root = userSkins() let changed = false let entries: fs.Dirent[] = [] try { entries = fs.readdirSync(root, { withFileTypes: true }) } catch { return false } for (const d of entries) {` ] ]) console.log('packaged paths patched')