refactor(paths): 重构路径解析逻辑并修复Linux打包版写入问题

适配Linux AppImage打包场景,将数据基准目录改为userData以解决只读目录无法写入的问题;重构路径解析相关函数,添加详细注释并优化代码结构。
This commit is contained in:
2026-09-05 20:36:34 +08:00
parent 3b627389c9
commit 4acdad6535
+19 -6
View File
@@ -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 → userDataexe 目录是只读挂载(/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;