fix crash when hosts not exist

This commit is contained in:
HolographicHat
2022-04-01 20:31:49 +08:00
parent 5fe6e80cc8
commit ab47ff2b06
2 changed files with 5 additions and 2 deletions

4
app.js
View File

@@ -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)
}

View File

@@ -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)