From 46ca11caadba03b0f1fc6d44d48a9ef45e720b94 Mon Sep 17 00:00:00 2001 From: Minoricew <154642983+Minoricew@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:51:01 +0800 Subject: [PATCH] =?UTF-8?q?[=F0=9F=9B=A0=EF=B8=8F=20Fix]=20Enc=20config=20?= =?UTF-8?q?detection=20issue=20&=20Add=20hosts=20file=20clean=20for=20Aika?= =?UTF-8?q?ri=20uninst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../init/main/ipcModules/aikariIpcHandler.js | 42 +++++++++++++++++++ src/aura/init/shared/configManager.js | 26 ++++++++++-- .../behaviourCtrl/aikariStatus.js | 6 ++- src/aura/utils/string.js | 5 +++ src/core/hook.js | 29 ++++++++----- 5 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 src/aura/utils/string.js diff --git a/src/aura/init/main/ipcModules/aikariIpcHandler.js b/src/aura/init/main/ipcModules/aikariIpcHandler.js index c2b2961..bf19d73 100644 --- a/src/aura/init/main/ipcModules/aikariIpcHandler.js +++ b/src/aura/init/main/ipcModules/aikariIpcHandler.js @@ -4,6 +4,7 @@ const __SCOPE = "main"; const { exec, execSync } = require("child_process"); const fs = require("fs"); +const os = require("os"); const path = require("path"); const nodeHttps = require("https"); const { fsComposables } = require("./fsIpcHandler"); @@ -268,6 +269,46 @@ const functions = { fs.unlinkSync(binPath); } }, + clearHostFileItem: async () => { + const AIKARI_HOST_STR = + "127.11.45.14 iot-broker-mis.seewo.com # This line is generated by HugoAura-Aikari, please do not edit or delete it"; + const hostPath = path.join( + process.env.SystemRoot || "C:\\WINDOWS", + "System32", + "drivers", + "etc", + "hosts" + ); + if (fs.existsSync(hostPath)) { + try { + const content = fs.readFileSync(hostPath, "utf-8"); + const lines = content.split(/\r?\n/); + const newContent = lines.filter((line) => { + const shouldKeep = !line.includes(AIKARI_HOST_STR); + if (!shouldKeep) { + console.log( + `[HugoAura / IPC / Aikari] Cleaned hosts file item: ${line}` + ); + } + return shouldKeep; + }); + if (lines.length === newContent.length) { + return false; + } + const newData = newContent.join(os.EOL); + fs.writeFileSync(hostPath, newData, "utf-8"); + return true; + } catch (err) { + console.error( + "[HugoAura / IPC / Aikari] Error cleaning hosts file: ", + err + ); + return false; + } + } else { + return false; + } + }, }; /** @@ -630,6 +671,7 @@ const applyAikariIpcHandler = (ipcMain) => { case "inst": // TODO: Impl Aikari INST case "uninst": + await functions.clearHostFileItem(); return await functions.execCommand( logHeader, AIKARI_UNINSTALLER_PATH, diff --git a/src/aura/init/shared/configManager.js b/src/aura/init/shared/configManager.js index f39e3ad..a102ef7 100755 --- a/src/aura/init/shared/configManager.js +++ b/src/aura/init/shared/configManager.js @@ -114,9 +114,16 @@ class ConfigManager { ); if (fs.existsSync(oldConfigPath)) { + console.log( + `[HugoAura / Config] Old plain config file detected at ${oldConfigPath}, migrating...` + ); fs.copyFileSync(oldConfigPath, this.configPath); fs.unlinkSync(oldConfigPath); + this.useEncConfig = false; } else if (fs.existsSync(oldEncConfigPath)) { + console.log( + `[HugoAura / Config] Old enc config file detected at ${oldEncConfigPath}, migrating...` + ); fs.copyFileSync(oldEncConfigPath, this.encConfigPath); fs.unlinkSync(oldEncConfigPath); this.useEncConfig = true; @@ -176,9 +183,14 @@ class ConfigManager { return this.getDefaultConfig(); // should be changed, too } } else { - console.error("[HugoAura / Config / ERROR] Failed to decrypt config"); + console.error( + "[HugoAura / Config / ERROR] Failed to decrypt config, falling back to use plain config" + ); + this.useEncConfig = false; this.isConfigReadFailed = true; - return this.getDefaultConfig(); // This behaviour should be changed later + config = JSON.parse(fs.readFileSync(this.configPath, "utf8")); + if (this.isConfigReadFailed) this.isConfigReadFailed = false; + return config; // This behaviour should be changed later } } else { config = JSON.parse(fs.readFileSync(this.configPath, "utf8")); @@ -208,7 +220,15 @@ class ConfigManager { console.error( "[HugoAura / Config / Write / ERROR] Failed to write config: Retrieve enc password failed" ); - return false; + console.warn( + "[HugoAura / Config / Write / WARN] Falling back to use plain config." + ); + fs.writeFileSync( + this.configPath, + JSON.stringify(config, null, 2), + "utf8" + ); + this.useEncConfig = false; } } else { fs.writeFileSync( diff --git a/src/aura/ui/pages/configSubPages/behaviourCtrl/aikariStatus.js b/src/aura/ui/pages/configSubPages/behaviourCtrl/aikariStatus.js index ebcf5b6..7e793ae 100644 --- a/src/aura/ui/pages/configSubPages/behaviourCtrl/aikariStatus.js +++ b/src/aura/ui/pages/configSubPages/behaviourCtrl/aikariStatus.js @@ -207,10 +207,12 @@ if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig) global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast( "success", "Aikari 已完成卸载", - null, + `
+ 您可能需要重启 SeewoCore 以重新建立 IoT 连接 +
`, true, true, - 2000 + 5000 ); } else { global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast( diff --git a/src/aura/utils/string.js b/src/aura/utils/string.js new file mode 100644 index 0000000..d60e1c7 --- /dev/null +++ b/src/aura/utils/string.js @@ -0,0 +1,5 @@ +const checkIfNonAscii = (str) => { + return Buffer.byteLength(str) !== str.length; +}; + +module.exports = { checkIfNonAscii }; diff --git a/src/core/hook.js b/src/core/hook.js index a2484e0..aa71cf6 100755 --- a/src/core/hook.js +++ b/src/core/hook.js @@ -48,6 +48,7 @@ const ConfigManager = require("../aura/init/shared/configManager"); const RegistryManager = require("../aura/init/shared/registryManager"); const { buildIpcMain } = require("../aura/init/main/ipcHandler"); const plsUtils = require("../aura/utils/pls"); +const stringUtils = require("../aura/utils/string"); const { initLogger } = require("../aura/init/main/logger"); @@ -60,18 +61,26 @@ const getUserDocumentsDirPath = () => { true, /REG_EXPAND_SZ\s+(.+)/ ); - if (pathInfo.success && pathInfo.data) { - const resolvedPath = pathInfo.data.replace( - /%([^%]+)%/g, - (match, varName) => { - return process.env[varName] || match; - } - ); + try { + if (pathInfo.success && pathInfo.data) { + const resolvedPath = pathInfo.data.replace( + /%([^%]+)%/g, + (match, varName) => { + return process.env[varName] || match; + } + ); - return resolvedPath; - } else { + if (stringUtils.checkIfNonAscii(resolvedPath)) { + console.warn("[HugoAura / Init] Detected non-ASCII char in resolved user personal folder: ", resolvedPath); + throw new Error("Non-ASCII char detected"); + } + return resolvedPath; + } else { + throw new Error("Registry data failed to get"); + } + } catch (err) { console.error( - "[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val." + "[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val. | Error: ", err ); return path.join(os.homedir(), "Documents"); }