42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { app } from 'electron';
|
||
import path from 'path';
|
||
import fs from 'fs';
|
||
|
||
// 检测是否为便携模式
|
||
let isPortable = false;
|
||
const exePath = app.getPath('exe');
|
||
const appDir = path.dirname(exePath);
|
||
const portableFlagPath = path.join(appDir, 'portable.txt');
|
||
|
||
// 如果应用目录中存在portable.txt文件,则启用便携模式
|
||
if (fs.existsSync(portableFlagPath)) {
|
||
isPortable = true;
|
||
console.log('启用便携模式');
|
||
}
|
||
|
||
// 根据模式选择数据目录
|
||
let dataDir;
|
||
if (isPortable) {
|
||
// 便携模式:数据存储在应用目录下的data文件夹
|
||
dataDir = path.join(appDir, 'data');
|
||
} else {
|
||
// 非便携模式:数据存储在用户数据目录
|
||
const userDataPath = app.getPath('userData');
|
||
dataDir = path.join(userDataPath, 'data');
|
||
}
|
||
|
||
// 确保数据目录存在
|
||
if (!fs.existsSync(dataDir)) {
|
||
fs.mkdirSync(dataDir, { recursive: true });
|
||
console.log(`创建数据目录: ${dataDir}`);
|
||
}
|
||
|
||
// 系统数据库路径
|
||
export function getSystemDbPath() {
|
||
return path.join(dataDir, 'system.db');
|
||
}
|
||
|
||
// 用户数据库路径
|
||
export function getUserDbPath() {
|
||
return path.join(dataDir, 'user.db');
|
||
} |