diff --git a/src/common/config-base.ts b/src/common/config-base.ts index ce4070d1..79e44c85 100644 --- a/src/common/config-base.ts +++ b/src/common/config-base.ts @@ -22,9 +22,14 @@ export abstract class ConfigBase { } getConfigPath(pathName: string | undefined): string { - const suffix = pathName ? `_${pathName}` : ''; - const filename = `${this.name}${suffix}.json`; - return path.join(this.configPath, filename); + if (!pathName) { + const filename = `${this.name}.json`; + const mainPath = this.core.context.pathWrapper.binaryPath; + return path.join(mainPath, 'config', filename); + } else { + const filename = `${this.name}_${pathName}.json`; + return path.join(this.configPath, filename); + } } read(): T { diff --git a/src/common/helper.ts b/src/common/helper.ts index d0ee50a6..f4ad9812 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -37,7 +37,7 @@ export class FileNapCatOneBotUUID { if (!uuid.startsWith('NapCatOneBot|ModelIdFile|')) return undefined; const data = uuid.split('|'); if (data.length !== 6) return undefined; - const [, , chatType, peerUid, modelId,fileId] = data; + const [, , chatType, peerUid, modelId, fileId] = data; return { peer: { chatType: chatType as any, @@ -156,9 +156,13 @@ export function getDefaultQQVersionConfigInfo(): QQVersionConfigType { }; } +export function getQQPackageInfoPath(exePath: string = ''): string { + return path.join(path.dirname(exePath), 'resources', 'app', 'package.json'); +} + export function getQQVersionConfigPath(exePath: string = ''): string | undefined { let configVersionInfoPath; - if (os.platform() !== 'linux') { + if (os.platform() === 'win32') { configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); } else { const userPath = os.homedir(); diff --git a/src/common/path.ts b/src/common/path.ts index e154bb46..308bcfd5 100644 --- a/src/common/path.ts +++ b/src/common/path.ts @@ -1,6 +1,7 @@ import path, { dirname } from 'path'; import { fileURLToPath } from 'url'; import fs from 'fs'; +import os from 'os'; export class NapCatPathWrapper { binaryPath: string; @@ -11,17 +12,19 @@ export class NapCatPathWrapper { constructor(mainPath: string = dirname(fileURLToPath(import.meta.url))) { this.binaryPath = mainPath; - this.logsPath = path.join(this.binaryPath, 'logs'); - this.configPath = path.join(this.binaryPath, 'config'); - this.cachePath = path.join(this.binaryPath, 'cache'); + let writePath: string; + writePath = this.binaryPath; + this.logsPath = path.join(writePath, 'logs'); + this.configPath = path.join(writePath, 'config'); + this.cachePath = path.join(writePath, 'cache'); this.staticPath = path.join(this.binaryPath, 'static'); - if (fs.existsSync(this.logsPath)) { + if (!fs.existsSync(this.logsPath)) { fs.mkdirSync(this.logsPath, { recursive: true }); } - if (fs.existsSync(this.configPath)) { + if (!fs.existsSync(this.configPath)) { fs.mkdirSync(this.configPath, { recursive: true }); } - if (fs.existsSync(this.cachePath)) { + if (!fs.existsSync(this.cachePath)) { fs.mkdirSync(this.cachePath, { recursive: true }); } } diff --git a/src/common/qq-basic-info.ts b/src/common/qq-basic-info.ts index 4e063ee2..79556fab 100644 --- a/src/common/qq-basic-info.ts +++ b/src/common/qq-basic-info.ts @@ -1,7 +1,6 @@ -import path from 'node:path'; import fs from 'node:fs'; import { systemPlatform } from '@/common/system'; -import { getDefaultQQVersionConfigInfo, getQQVersionConfigPath } from './helper'; +import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath } from './helper'; import AppidTable from '@/core/external/appid.json'; import { LogWrapper } from './log'; @@ -20,7 +19,7 @@ export class QQBasicInfoWrapper { //基础目录获取 this.context = context; this.QQMainPath = process.execPath; - this.QQPackageInfoPath = path.join(path.dirname(this.QQMainPath), 'resources', 'app', 'package.json'); + this.QQPackageInfoPath = getQQPackageInfoPath(this.QQMainPath); this.QQVersionConfigPath = getQQVersionConfigPath(this.QQMainPath); //基础信息获取 无快更则启用默认模板填充 @@ -53,9 +52,21 @@ export class QQBasicInfoWrapper { //此方法不要直接使用 getQUAInternal() { - return systemPlatform === 'linux' - ? `V1_LNX_NQ_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B` - : `V1_WIN_NQ_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; + switch (systemPlatform) { + case 'linux': + return `V1_LNX_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; + default: + return `V1_WIN_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; + } + } + + getAppidInternal() { + switch (systemPlatform) { + case 'linux': + return '537243600'; + default: + return '537243538'; + } } getAppidV2(): { appid: string; qua: string } { @@ -71,6 +82,6 @@ export class QQBasicInfoWrapper { // else this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`); this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,); - return { appid: systemPlatform === 'linux' ? '537243600' : '537243441', qua: this.getQUAInternal() }; + return { appid: this.getAppidInternal(), qua: this.getQUAInternal() }; } } diff --git a/src/core/index.ts b/src/core/index.ts index adc5e917..5fc2912e 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -42,9 +42,11 @@ export enum NapCatCoreWorkingEnv { } export function loadQQWrapper(QQVersion: string): WrapperNodeApi { - let wrapperNodePath = path.resolve(path.dirname(process.execPath), './resources/app/wrapper.node'); + let appPath; + appPath = path.resolve(path.dirname(process.execPath), './resources/app'); + let wrapperNodePath = path.resolve(appPath, 'wrapper.node'); if (!fs.existsSync(wrapperNodePath)) { - wrapperNodePath = path.join(path.dirname(process.execPath), `resources/app/versions/${QQVersion}/wrapper.node`); + wrapperNodePath = path.join(appPath, `versions/${QQVersion}/wrapper.node`); } const nativemodule: any = { exports: {} }; process.dlopen(nativemodule, wrapperNodePath); diff --git a/src/shell/napcat.ts b/src/shell/napcat.ts index 31857baa..044155df 100644 --- a/src/shell/napcat.ts +++ b/src/shell/napcat.ts @@ -49,12 +49,15 @@ export async function NCoreInitShell() { const session = new wrapper.NodeIQQNTWrapperSession(); // from get dataPath - let dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig(); - if (!dataPath) { - dataPath = path.resolve(os.homedir(), './.config/QQ'); - fs.mkdirSync(dataPath, { recursive: true }); - } - const dataPathGlobal = path.resolve(dataPath, './nt_qq/global'); + const [dataPath, dataPathGlobal] = (() => { + let dataPath = wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig(); + if (!dataPath) { + dataPath = path.resolve(os.homedir(), './.config/QQ'); + fs.mkdirSync(dataPath, { recursive: true }); + } + const dataPathGlobal = path.resolve(dataPath, './nt_qq/global'); + return [dataPath, dataPathGlobal]; + })(); // from initConfig engine.initWithDeskTopConfig( @@ -115,7 +118,7 @@ export async function NCoreInitShell() { const realBase64 = pngBase64QrcodeData.replace(/^data:image\/\w+;base64,/, ''); const buffer = Buffer.from(realBase64, 'base64'); logger.logWarn('请扫描下面的二维码,然后在手Q上授权登录:'); - const qrcodePath = path.join(pathWrapper.binaryPath, 'qrcode.png'); + const qrcodePath = path.join(pathWrapper.cachePath, 'qrcode.png'); qrcode.generate(qrcodeUrl, { small: true }, (res) => { logger.logWarn([ '\n', @@ -191,7 +194,7 @@ export async function NCoreInitShell() { logger.log(`可用于快速登录的 QQ:\n${historyLoginList .map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`) .join('\n') - }`); + }`); } loginService.getQRCodePicture(); }