ai规范文件路径
This commit is contained in:
parent
31ebc97568
commit
c8ca6d0bda
@ -5,24 +5,24 @@ import { getSystemDbPath, getUserDbPath } from './path.js';
|
||||
|
||||
// 迁移数据库文件
|
||||
export async function migrateDatabases() {
|
||||
// 开发环境下不执行迁移
|
||||
// 获取数据库路径
|
||||
const systemDbPath = getSystemDbPath();
|
||||
const userDbPath = getUserDbPath();
|
||||
const dataDir = path.dirname(systemDbPath);
|
||||
|
||||
// 确保数据目录存在
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
console.log(`创建数据目录: ${dataDir}`);
|
||||
}
|
||||
|
||||
// 开发环境下,确保使用工程data目录下的数据库
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('开发环境下不执行数据库迁移');
|
||||
console.log('开发环境下使用工程data目录');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取数据库路径
|
||||
const systemDbPath = getSystemDbPath();
|
||||
const userDbPath = getUserDbPath();
|
||||
const dataDir = path.dirname(systemDbPath);
|
||||
|
||||
// 确保数据目录存在
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
console.log(`创建数据目录: ${dataDir}`);
|
||||
}
|
||||
|
||||
// 获取安装目录中的数据库文件路径
|
||||
const appPath = app.getAppPath();
|
||||
const installedSystemDbPath = path.join(appPath, 'data', 'system.db');
|
||||
|
@ -2,6 +2,9 @@ import { app } from 'electron';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
// 判断是否为开发环境
|
||||
const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged;
|
||||
|
||||
// 检测是否为便携模式
|
||||
let isPortable = false;
|
||||
const exePath = app.getPath('exe');
|
||||
@ -9,20 +12,22 @@ const appDir = path.dirname(exePath);
|
||||
const portableFlagPath = path.join(appDir, 'portable.txt');
|
||||
|
||||
// 如果应用目录中存在portable.txt文件,则启用便携模式
|
||||
if (fs.existsSync(portableFlagPath)) {
|
||||
if (!isDev && fs.existsSync(portableFlagPath)) {
|
||||
isPortable = true;
|
||||
console.log('启用便携模式');
|
||||
}
|
||||
|
||||
// 根据模式选择数据目录
|
||||
let dataDir;
|
||||
if (isPortable) {
|
||||
if (isDev) {
|
||||
// 开发环境:数据存储在工程的data目录
|
||||
dataDir = path.join(process.cwd(), 'data');
|
||||
} else if (isPortable) {
|
||||
// 便携模式:数据存储在应用目录下的data文件夹
|
||||
dataDir = path.join(appDir, 'data');
|
||||
} else {
|
||||
// 非便携模式:数据存储在用户数据目录
|
||||
const userDataPath = app.getPath('userData');
|
||||
dataDir = path.join(userDataPath, 'data');
|
||||
// 非便携模式:数据存储在应用同级的data目录
|
||||
dataDir = path.join(appDir, 'data');
|
||||
}
|
||||
|
||||
// 确保数据目录存在
|
||||
|
@ -358,7 +358,11 @@ function getAppSaveDir() {
|
||||
|
||||
if (isDev) {
|
||||
// 开发环境:使用项目根目录
|
||||
return path.join(process.cwd(), 'output');
|
||||
const outputDir = path.join(process.cwd(), 'output');
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
return outputDir;
|
||||
} else {
|
||||
// 检测是否为便携模式
|
||||
const exePath = app.getPath('exe');
|
||||
@ -366,33 +370,12 @@ function getAppSaveDir() {
|
||||
const portableFlagPath = path.join(appDir, 'portable.txt');
|
||||
const isPortable = fs.existsSync(portableFlagPath);
|
||||
|
||||
if (isPortable) {
|
||||
// 便携模式:使用应用目录下的output文件夹
|
||||
const outputDir = path.join(appDir, 'output');
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
return outputDir;
|
||||
} else {
|
||||
// 非便携模式:根据操作系统选择不同路径
|
||||
if (process.platform === 'darwin') { // macOS
|
||||
// 使用用户文档目录
|
||||
const docDir = path.join(app.getPath('documents'), 'ExamApp');
|
||||
if (!fs.existsSync(docDir)) {
|
||||
fs.mkdirSync(docDir, { recursive: true });
|
||||
}
|
||||
return docDir;
|
||||
} else if (process.platform === 'win32') { // Windows
|
||||
// 使用用户文档目录
|
||||
const docDir = path.join(app.getPath('documents'), 'ExamApp');
|
||||
if (!fs.existsSync(docDir)) {
|
||||
fs.mkdirSync(docDir, { recursive: true });
|
||||
}
|
||||
return docDir;
|
||||
} else { // Linux 等其他系统
|
||||
return app.getPath('userData');
|
||||
}
|
||||
// 所有生产环境(包括便携和非便携)都使用应用同级的output目录
|
||||
const outputDir = path.join(appDir, 'output');
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
return outputDir;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user