Files
koring-launcher/electron/core/paths.ts
T
dream_pep 4acdad6535 refactor(paths): 重构路径解析逻辑并修复Linux打包版写入问题
适配Linux AppImage打包场景,将数据基准目录改为userData以解决只读目录无法写入的问题;重构路径解析相关函数,添加详细注释并优化代码结构。
2026-09-05 20:36:34 +08:00

34 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 路径归一化:相对 gameDir(默认 `.minecraft`)在打包后依赖进程 cwd,不可靠。
// 统一按与 runStartupChecks 一致的基准解析(见 dataBasePath)。
import * as path from 'path';
import electron from 'electron';
const { app } = electron;
/**
* 数据基准目录(游戏数据 `.minecraft` 等相对路径的解析根):
* - 开发模式 → 项目根
* - Linux / AppImage → userDataexe 目录是只读挂载(/tmp/.mount_*),无法写入
* - Windows 打包 → exe 目录(沿用历史行为)
*/
export function dataBasePath(): string {
if (!app.isPackaged) {
return path.join(__dirname, '..', '..');
}
if (process.platform === 'linux') {
return app.getPath('userData');
}
return path.dirname(app.getPath('exe'));
}
function baseDataPath(): string {
return dataBasePath();
}
/** 相对路径 → 绝对(基准 = dataBasePath);绝对路径原样返回 */
export function resolveGamePath(gamePath: string): string {
if (!gamePath || path.isAbsolute(gamePath)) {
return gamePath;
}
return path.join(baseDataPath(), gamePath);
}