diff --git a/electron/core/paths.ts b/electron/core/paths.ts index 2c9c6ae..7de69a2 100644 --- a/electron/core/paths.ts +++ b/electron/core/paths.ts @@ -1,17 +1,30 @@ // 路径归一化:相对 gameDir(默认 `.minecraft`)在打包后依赖进程 cwd,不可靠。 -// 统一按与 runStartupChecks 一致的基准解析(打包 → exe 目录;开发 → 项目根)。 +// 统一按与 runStartupChecks 一致的基准解析(见 dataBasePath)。 import * as path from 'path'; import electron from 'electron'; const { app } = electron; -function baseDataPath(): string { - if (app.isPackaged) { - return path.dirname(app.getPath('exe')); +/** + * 数据基准目录(游戏数据 `.minecraft` 等相对路径的解析根): + * - 开发模式 → 项目根 + * - Linux / AppImage → userData:exe 目录是只读挂载(/tmp/.mount_*),无法写入 + * - Windows 打包 → exe 目录(沿用历史行为) + */ +export function dataBasePath(): string { + if (!app.isPackaged) { + return path.join(__dirname, '..', '..'); } - return path.join(__dirname, '..', '..'); + if (process.platform === 'linux') { + return app.getPath('userData'); + } + return path.dirname(app.getPath('exe')); } -/** 相对路径 → 绝对(基准 = exe 目录/项目根);绝对路径原样返回 */ +function baseDataPath(): string { + return dataBasePath(); +} + +/** 相对路径 → 绝对(基准 = dataBasePath);绝对路径原样返回 */ export function resolveGamePath(gamePath: string): string { if (!gamePath || path.isAbsolute(gamePath)) { return gamePath;