42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
// 将 CommonJS 导入改为 ES 模块导入
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
// 导入app模块
|
|
import { app } from 'electron';
|
|
|
|
// 获取当前文件所在目录
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
// 获取用户数据目录(跨平台解决方案)
|
|
const getUserDataPath = () => {
|
|
return app.getPath('userData');
|
|
};
|
|
|
|
// 确保数据目录存在
|
|
const ensureDataDirExists = () => {
|
|
const dataDir = path.join(getUserDataPath(), 'data');
|
|
if (!fs.existsSync(dataDir)) {
|
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
}
|
|
return dataDir;
|
|
};
|
|
|
|
// 获取系统数据库路径
|
|
const getSystemDbPath = () => {
|
|
const dataDir = ensureDataDirExists();
|
|
return path.join(dataDir, 'system.db');
|
|
};
|
|
|
|
// 获取用户数据库路径
|
|
const getUserDbPath = () => {
|
|
const dataDir = ensureDataDirExists();
|
|
return path.join(dataDir, 'user.db');
|
|
};
|
|
|
|
// 导出函数
|
|
export {
|
|
getSystemDbPath,
|
|
getUserDbPath
|
|
}; |