mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-22 16:24:27 +08:00
[🛠️ Fix] Invalid log dir path (#24) & Remove PLS trust token
1. [-] 删除了 PLS 的 Trust token 认证机制 2. [+] 现在可以在 `偏好设置` - `调试选项` 中直接打开日志文件夹了 3. [/] 日志目录不再使用 `%USERPROFILE%\Documents\HugoAura\logs` 为基准, 而是从注册表获取值 4. [/] 配置文件目录同理, 旧版配置文件将会自动迁移到新位置
This commit is contained in:
@@ -69,7 +69,7 @@ const deepMerge = (target, source) => {
|
||||
|
||||
class ConfigManager {
|
||||
constructor() {
|
||||
this.configDir = path.join(os.homedir(), "Documents", "HugoAura");
|
||||
this.configDir = path.join(global.__HUGO_AURA__.logDir, "..");
|
||||
this.configPath = path.join(this.configDir, "config.json");
|
||||
this.encConfigPath = path.join(this.configDir, ".cache_2eafc8d0.dat"); // (雾
|
||||
/* ↑ 不使用 .tmp 扩展名, 不然容易真被清理了 */
|
||||
@@ -95,6 +95,33 @@ class ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
migrateOldConfigFile() {
|
||||
const oldConfigPath = path.join(
|
||||
os.homedir(),
|
||||
"Documents",
|
||||
"HugoAura",
|
||||
"config.json"
|
||||
);
|
||||
const oldEncConfigPath = path.join(
|
||||
os.homedir(),
|
||||
"Documents",
|
||||
"HugoAura",
|
||||
".cache_2eafc8d0.dat"
|
||||
);
|
||||
if (fs.existsSync(oldConfigPath)) {
|
||||
fs.copyFileSync(oldConfigPath, this.configPath);
|
||||
fs.unlinkSync(oldConfigPath);
|
||||
} else if (fs.existsSync(oldEncConfigPath)) {
|
||||
fs.copyFileSync(oldEncConfigPath, this.encConfigPath);
|
||||
fs.unlinkSync(oldEncConfigPath);
|
||||
this.useEncConfig = true;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[HugoAura / Config] Moved old config file to ${this.configDir}`
|
||||
);
|
||||
}
|
||||
|
||||
getHugoAuraConfigPath() {
|
||||
return path.dirname(
|
||||
this.useEncConfig ? this.encConfigPath : this.configPath
|
||||
|
||||
@@ -6,7 +6,12 @@ const { exec, execSync } = require("child_process");
|
||||
|
||||
const LOG_PREFIX = "[HugoAura / Init / Reg";
|
||||
const LOG_PREFIX_FUNC = "[HugoAura / Reg";
|
||||
const AURA_REGISTRY_PATH = ["HKEY_USERS", ".DEFAULT", "SOFTWARE", "HugoAura"].join("\\");
|
||||
const AURA_REGISTRY_PATH = [
|
||||
"HKEY_USERS",
|
||||
".DEFAULT",
|
||||
"SOFTWARE",
|
||||
"HugoAura",
|
||||
].join("\\");
|
||||
|
||||
class RegistryManager {
|
||||
/**
|
||||
@@ -341,19 +346,27 @@ class RegistryManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} relativePath
|
||||
* @param {string} keyPath
|
||||
* @param {string} keyName
|
||||
* @param {boolean | undefined} silent
|
||||
* @param {boolean} absolute
|
||||
* @param {any} regex
|
||||
* @returns {Promise<{ success: boolean, data: string | null, error: Error | null }>}
|
||||
*/
|
||||
async readRegKey(relativePath, keyName, silent = false) {
|
||||
async readRegKey(
|
||||
keyPath,
|
||||
keyName,
|
||||
silent = false,
|
||||
absolute = false,
|
||||
regex = null
|
||||
) {
|
||||
try {
|
||||
const { stdout } = await new Promise((resolve, reject) => {
|
||||
exec(
|
||||
[
|
||||
"reg",
|
||||
"query",
|
||||
[AURA_REGISTRY_PATH, relativePath].join("\\"),
|
||||
absolute ? keyPath : [AURA_REGISTRY_PATH, keyPath].join("\\"),
|
||||
"/v",
|
||||
`\"${keyName}\"`,
|
||||
].join(" "),
|
||||
@@ -367,12 +380,12 @@ class RegistryManager {
|
||||
|
||||
if (!silent) {
|
||||
console.debug(
|
||||
`${LOG_PREFIX_FUNC} / SUCCESS] Successfully read reg key ${relativePath}/${keyName}, stdout:`,
|
||||
`${LOG_PREFIX_FUNC} / SUCCESS] Successfully read reg key ${keyPath}/${keyName}, stdout:`,
|
||||
stdout
|
||||
);
|
||||
}
|
||||
|
||||
const match = stdout.match(/REG_SZ\s+(.+)/);
|
||||
const match = regex ? stdout.match(regex) : stdout.match(/REG_SZ\s+(.+)/);
|
||||
|
||||
if (!match) {
|
||||
console.warn(`${LOG_PREFIX} / WARN] Data not found in stdout`);
|
||||
@@ -390,10 +403,7 @@ class RegistryManager {
|
||||
error: null,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`${LOG_PREFIX} / ERROR] Failed to read reg key, error:`,
|
||||
e
|
||||
);
|
||||
console.error(`${LOG_PREFIX} / ERROR] Failed to read reg key, error:`, e);
|
||||
return {
|
||||
success: false,
|
||||
data: null,
|
||||
@@ -403,18 +413,26 @@ class RegistryManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} relativePath
|
||||
* @param {string} keyPath
|
||||
* @param {string} keyName
|
||||
* @param {boolean | undefined} silent
|
||||
* @param {boolean} absolute
|
||||
* @param {any} regex
|
||||
* @returns {{ success: boolean, data: string | null, error: Error | null }}
|
||||
*/
|
||||
readRegKeySync(relativePath, keyName, silent = false) {
|
||||
readRegKeySync(
|
||||
keyPath,
|
||||
keyName,
|
||||
silent = false,
|
||||
absolute = false,
|
||||
regex = null
|
||||
) {
|
||||
try {
|
||||
const readResult = execSync(
|
||||
[
|
||||
"reg",
|
||||
"query",
|
||||
[AURA_REGISTRY_PATH, relativePath].join("\\"),
|
||||
absolute ? keyPath : [AURA_REGISTRY_PATH, keyPath].join("\\"),
|
||||
"/v",
|
||||
`\"${keyName}\"`,
|
||||
].join(" "),
|
||||
@@ -424,11 +442,13 @@ class RegistryManager {
|
||||
if (readResult) {
|
||||
if (!silent) {
|
||||
console.debug(
|
||||
`${LOG_PREFIX_FUNC} / SUCCESS] Successfully read reg key ${relativePath}/${keyName}, stdout:`,
|
||||
`${LOG_PREFIX_FUNC} / SUCCESS] Successfully read reg key ${keyPath}/${keyName}, stdout:`,
|
||||
readResult
|
||||
);
|
||||
}
|
||||
const match = readResult.match(/REG_SZ\s+(.+)/);
|
||||
const match = regex
|
||||
? readResult.match(regex)
|
||||
: readResult.match(/REG_SZ\s+(.+)/);
|
||||
|
||||
if (!match) {
|
||||
console.warn(`${LOG_PREFIX} / WARN] Data not found in stdout`);
|
||||
|
||||
Reference in New Issue
Block a user