path
This commit is contained in:
parent
24a7e00382
commit
ee3ee77e31
@ -1,4 +1,4 @@
|
|||||||
const { getSystemDbPath, getUserDbPath } = require('./path.js');
|
const { getSystemDbPath, getUserDbPath } = require('./path.js'); // 添加路径函数导入
|
||||||
const { systemSchema, userSchema, defaultData } = require('./schema.js');
|
const { systemSchema, userSchema, defaultData } = require('./schema.js');
|
||||||
const { openDatabase, batchInsert } = require('./utils.js');
|
const { openDatabase, batchInsert } = require('./utils.js');
|
||||||
const bcrypt = require('bcryptjs');
|
const bcrypt = require('bcryptjs');
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs'); // 添加缺失的fs模块导入
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ let portableFlagPath;
|
|||||||
// 确保app已经初始化后再获取路径
|
// 确保app已经初始化后再获取路径
|
||||||
if (app && app.getPath) {
|
if (app && app.getPath) {
|
||||||
try {
|
try {
|
||||||
const exePath = app.getPath('exe');
|
// 在Windows上,使用process.execPath获取可执行文件路径
|
||||||
|
const exePath = process.execPath;
|
||||||
appDir = path.dirname(exePath);
|
appDir = path.dirname(exePath);
|
||||||
portableFlagPath = path.join(appDir, 'portable.txt');
|
portableFlagPath = path.join(appDir, 'portable.txt');
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ if (app && app.getPath) {
|
|||||||
appDir = process.cwd();
|
appDir = process.cwd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在第35行左右,更新数据目录选择逻辑
|
||||||
// 根据模式选择数据目录
|
// 根据模式选择数据目录
|
||||||
let dataDir;
|
let dataDir;
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
@ -43,12 +45,32 @@ if (isDev) {
|
|||||||
dataDir = path.join(path.dirname(appDir), 'data');
|
dataDir = path.join(path.dirname(appDir), 'data');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 增强路径处理:添加备选路径检测
|
||||||
|
if (!isDev && !fs.existsSync(dataDir) && fs.existsSync(path.join(appDir, 'data'))) {
|
||||||
|
console.log('检测到应用目录下存在data目录,自动切换到便携模式');
|
||||||
|
dataDir = path.join(appDir, 'data');
|
||||||
|
isPortable = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 确保数据目录存在
|
// 确保数据目录存在
|
||||||
if (!fs.existsSync(dataDir)) {
|
if (!fs.existsSync(dataDir)) {
|
||||||
|
try {
|
||||||
fs.mkdirSync(dataDir, { recursive: true });
|
fs.mkdirSync(dataDir, { recursive: true });
|
||||||
console.log(`创建数据目录: ${dataDir}`);
|
console.log(`创建数据目录: ${dataDir}`);
|
||||||
|
} catch (mkdirError) {
|
||||||
|
console.error(`创建数据目录失败: ${dataDir}`, mkdirError);
|
||||||
|
// 作为最后的备选方案,使用当前工作目录
|
||||||
|
dataDir = process.cwd();
|
||||||
|
console.log(`备选数据目录: ${dataDir}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加更多调试日志
|
||||||
|
console.log(`当前运行模式: ${isDev ? '开发环境' : (isPortable ? '便携模式' : '安装模式')}`);
|
||||||
|
console.log(`数据目录路径: ${dataDir}`);
|
||||||
|
console.log(`系统数据库路径: ${path.join(dataDir, 'system.db')}`);
|
||||||
|
console.log(`用户数据库路径: ${path.join(dataDir, 'user.db')}`);
|
||||||
|
|
||||||
// 系统数据库路径
|
// 系统数据库路径
|
||||||
function getSystemDbPath() {
|
function getSystemDbPath() {
|
||||||
return path.join(dataDir, 'system.db');
|
return path.join(dataDir, 'system.db');
|
||||||
|
Loading…
Reference in New Issue
Block a user