From ab47ff2b065cf82543e938c9aabdbc1cf3ad15b4 Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Fri, 1 Apr 2022 20:31:49 +0800 Subject: [PATCH] fix crash when hosts not exist --- app.js | 4 ++-- utils.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index b0c0ba9..67c7793 100644 --- a/app.js +++ b/app.js @@ -111,12 +111,12 @@ const onExit = () => { const merged = Buffer.concat(packets) const compressed = zlib.brotliCompressSync(merged) const response = await upload(compressed) + const data = zlib.brotliDecompressSync(response.data) if (response.status !== 200) { - log(`发生错误: ${response.data.toString()}`) + log(`发生错误: ${data}`) log(`请求ID: ${response.headers["x-api-requestid"]}`) log("请联系开发者以获取帮助") } else { - const data = zlib.brotliDecompressSync(response.data) const proto = await decodeProto(data,"AllAchievement") await exportData(proto) } diff --git a/utils.js b/utils.js index c2a512a..715f566 100644 --- a/utils.js +++ b/utils.js @@ -228,6 +228,9 @@ let hostsContent = "" const setupHost = (restore = false) => { const path = "C:\\Windows\\System32\\drivers\\etc\\hosts" + if (!fs.existsSync(path)) { + fs.writeFileSync(path, "") + } fs.chmodSync(path, 0o777) if (restore) { fs.writeFileSync(path, hostsContent)