From 5f7d998b0bd3a99cb93ff2773f6648f18b7daae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 10 Aug 2024 21:47:58 +0800 Subject: [PATCH] chore: fix --- manifest.json | 2 +- src/common/framework/napcat.ts | 12 ++++++++++++ src/common/utils/ConfigBase.ts | 10 +++------- src/framework/napcat.cjs | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/manifest.json b/manifest.json index 740894b1..b4ec933c 100644 --- a/manifest.json +++ b/manifest.json @@ -27,7 +27,7 @@ ], "injects": { "renderer": "./renderer.js", - "main": "./liteloader.cjs", + "main": "./napcat.cjs", "preload": "./preload.cjs" } } \ No newline at end of file diff --git a/src/common/framework/napcat.ts b/src/common/framework/napcat.ts index 19b70d91..ca08f1e3 100644 --- a/src/common/framework/napcat.ts +++ b/src/common/framework/napcat.ts @@ -1,5 +1,6 @@ import path, { dirname } from 'path'; import { fileURLToPath } from 'url'; +import fs from 'fs'; export const napcat_version = '2.0.0'; @@ -7,10 +8,21 @@ export class NapCatPathWrapper { binaryPath: string; logsPath: string; configPath: string; + cachePath: string; 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'); + if (fs.existsSync(this.logsPath)) { + fs.mkdirSync(this.logsPath, { recursive: true }); + } + if (fs.existsSync(this.configPath)) { + fs.mkdirSync(this.configPath, { recursive: true }); + } + if (fs.existsSync(this.cachePath)) { + fs.mkdirSync(this.cachePath, { recursive: true }); + } } } diff --git a/src/common/utils/ConfigBase.ts b/src/common/utils/ConfigBase.ts index 3f4ca9d4..679f34a6 100644 --- a/src/common/utils/ConfigBase.ts +++ b/src/common/utils/ConfigBase.ts @@ -12,6 +12,7 @@ export class ConfigBase { constructor(coreContext: NapCatCore, configPath: string) { this.coreContext = coreContext; this.configPath = configPath; + fs.mkdirSync(this.configPath, { recursive: true }); this.read(); } @@ -20,21 +21,16 @@ export class ConfigBase { return null; } - getConfigDir() { - const configDir = path.resolve(this.configPath, 'config'); - fs.mkdirSync(configDir, { recursive: true }); - return configDir; - } getConfigPath(pathName: string | null): string { const suffix = pathName ? `_${pathName}` : ''; const filename = `${this.name}${suffix}.json`; - return path.join(this.getConfigDir(), filename); + return path.join(this.configPath, filename); } read() { // 尝试加载当前账号配置 - if (this.read_from_file(this.coreContext.selfInfo.uin, false)) return this; + if (this.read_from_file(this.coreContext.selfInfo.uin, false)) return this.config; // 尝试加载默认配置 return this.read_from_file('', true); } diff --git a/src/framework/napcat.cjs b/src/framework/napcat.cjs index fc3a424c..44a0bb37 100644 --- a/src/framework/napcat.cjs +++ b/src/framework/napcat.cjs @@ -127,7 +127,7 @@ async function NCInit() { await NCoreInitFramework(wrapperSession, wrapperLoginService, registerInitCallback); //console.log("[NapCat] [Info] NapCat初始化完成"); } catch (error) { - console.error('[NapCat] [Error] 初始化NapCat失败', error); + console.log('[NapCat] [Error] 初始化NapCat失败', error); } }