This commit is contained in:
手瓜一十雪 committed 2026-10-30 14:17:03 +08:00
1 parent 162c6db1ac
commit 093b3bf4aa
5 files changed
+41 -20

No files matched your search

+8
View File
@@ -3,6 +3,11 @@ import { fileURLToPath } from 'url';
import fs from 'fs';
import os from 'os';
export function getQQDataDirOverride (): string | undefined {
const dataDir = process.env['NAPCAT_QQ_DATA_DIR'];
return dataDir ? path.resolve(dataDir) : undefined;
}
export class NapCatPathWrapper {
binaryPath: string;
logsPath: string;
@@ -14,9 +19,12 @@ export class NapCatPathWrapper {
constructor (mainPath: string = dirname(fileURLToPath(import.meta.url))) {
this.binaryPath = mainPath;
let writePath: string;
const qqDataDir = getQQDataDirOverride();
if (process.env['NAPCAT_WORKDIR']) {
writePath = process.env['NAPCAT_WORKDIR'];
} else if (qqDataDir) {
writePath = path.join(qqDataDir, 'NapCat');
} else if (os.platform() === 'darwin') {
writePath = path.join(os.homedir(), 'Library', 'Application Support', 'QQ', 'NapCat');
} else {
+3 -1
View File
@@ -23,7 +23,7 @@ import {
} from '@/napcat-core/wrapper';
import { LogLevel, LogWrapper } from '@/napcat-core/helper/log';
import { QQBasicInfoWrapper } from '@/napcat-core/helper/qq-basic-info';
import { NapCatPathWrapper } from 'napcat-common/src/path';
import { getQQDataDirOverride, NapCatPathWrapper } from 'napcat-common/src/path';
import path from 'node:path';
import fs from 'node:fs';
import { hostname, systemName, systemVersion } from 'napcat-common/src/system';
@@ -240,6 +240,8 @@ export class NapCatCore {
}
get dataPath (): string {
const override = getQQDataDirOverride();
if (override) return override;
let result = this.context.wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
if (!result) {
result = path.resolve(os.homedir(), './.config/QQ');
+1 -18
View File
@@ -42,6 +42,7 @@ import { QQBasicInfoWrapper } from '@/napcat-core/helper/qq-basic-info';
import { statusHelperSubscription } from '@/napcat-core/helper/status';
import { applyPendingUpdates } from '@/napcat-webui-backend/src/api/UpdateNapCat';
import { migrateLegacyGlobalPath } from './global-migrate';
import { getDataPaths } from './data-path';
import { connectToNamedPipe } from './pipe';
// NapCat Shell App ES 入口文件
@@ -54,24 +55,6 @@ async function handleUncaughtExceptions (logger: LogWrapper) {
});
}
function getDataPaths (wrapper: WrapperNodeApi): [string, string] {
if (os.platform() === 'darwin') {
const userPath = os.homedir();
const appDataPath = path.resolve(userPath, './Library/Application Support/QQ');
return [appDataPath, path.join(appDataPath, 'global')];
}
let dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
if (!dataPath) {
dataPath = path.resolve(os.homedir(), './.config/QQ');
fs.mkdirSync(dataPath, { recursive: true });
}
// Linux: global 直接位于数据目录下; Windows: global 位于 nt_qq 子目录下
const dataPathGlobal = os.platform() === 'linux'
? path.resolve(dataPath, './global')
: path.resolve(dataPath, './nt_qq/global');
return [dataPath, dataPathGlobal];
}
function getPlatformType (): PlatformType {
const platformMapping: Partial<Record<NodeJS.Platform, PlatformType>> = {
win32: PlatformType.KWINDOWS,
+28
View File
@@ -0,0 +1,28 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { getQQDataDirOverride } from 'napcat-common/src/path';
import type { WrapperNodeApi } from 'napcat-core';
export function getDataPaths (wrapper: WrapperNodeApi): [string, string] {
const platform = os.platform();
let dataPath = getQQDataDirOverride();
if (dataPath) {
// 自定义目录必须在初始化内核前存在;创建失败时不能回退到桌面 QQ。
fs.mkdirSync(dataPath, { recursive: true });
} else if (platform === 'darwin') {
dataPath = path.resolve(os.homedir(), './Library/Application Support/QQ');
} else {
dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
if (!dataPath) {
dataPath = path.resolve(os.homedir(), './.config/QQ');
fs.mkdirSync(dataPath, { recursive: true });
}
}
// Linux/macOS: global 直接位于数据目录下;Windows: 位于 nt_qq 子目录下。
// 此处不创建 global,以免阻止后续 Linux 旧目录迁移。
const dataPathGlobal = platform === 'linux' || platform === 'darwin'
? path.resolve(dataPath, 'global')
: path.resolve(dataPath, 'nt_qq', 'global');
return [dataPath, dataPathGlobal];
}
+1 -1
View File
@@ -12,7 +12,6 @@ import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const pathWrapper = new NapCatPathWrapper();
const envPath = path.join(__dirname, 'config', '.env');
if (fs.existsSync(envPath)) {
try {
@@ -32,6 +31,7 @@ if (fs.existsSync(envPath)) {
console.log('[NapCat] Failed to load .env file:', e);
}
}
const pathWrapper = new NapCatPathWrapper();
// 环境变量配置
const ENV = {