mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-14 02:18:13 +08:00
v1.0.0
This commit is contained in:
9
app.js
9
app.js
@@ -3,7 +3,7 @@ const proxy = require("udp-proxy")
|
||||
const cp = require("child_process")
|
||||
const rs = require("./regionServer")
|
||||
const appcenter = require("./appcenter")
|
||||
const { initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkCDN, checkUpdate, keypress} = require("./utils")
|
||||
const { initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, debug, checkCDN, checkUpdate } = require("./utils")
|
||||
const { exportData } = require("./export");
|
||||
|
||||
// TODO: i18n
|
||||
@@ -62,6 +62,7 @@ const { exportData } = require("./export");
|
||||
hServer.close()
|
||||
gameProcess.kill()
|
||||
clearInterval(monitor)
|
||||
setupHost(true)
|
||||
console.log("正在处理数据,请稍后...")
|
||||
let packets = Array.from(cache.values())
|
||||
cache.clear()
|
||||
@@ -94,8 +95,8 @@ const { exportData } = require("./export");
|
||||
const data = zlib.brotliDecompressSync(response.data)
|
||||
const proto = await decodeProto(data,"AllAchievement")
|
||||
await exportData(proto)
|
||||
console.log("按任意键退出.")
|
||||
await keypress()
|
||||
console.log("按任意键退出")
|
||||
cp.execSync("pause > nul", { stdio: "inherit" })
|
||||
}
|
||||
process.exit(0)
|
||||
}
|
||||
@@ -131,7 +132,7 @@ const { exportData } = require("./export");
|
||||
})
|
||||
})
|
||||
return server
|
||||
}).then(() => console.log("加载完毕."))
|
||||
}).then(() => console.log("加载完毕"))
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
appcenter.uploadError(e, true)
|
||||
|
||||
@@ -62,7 +62,7 @@ const exportToCocogoat = async proto => {
|
||||
})
|
||||
})
|
||||
spawnSync("clip", { input: JSON.stringify(out,null,2) })
|
||||
console.log("导出内容已复制到剪贴板.")
|
||||
console.log("导出内容已复制到剪贴板")
|
||||
}
|
||||
|
||||
const exportToCsv = async proto => {
|
||||
|
||||
18
utils.js
18
utils.js
@@ -172,7 +172,7 @@ const loadCache = async (fp, repo = "Dimbreath/GenshinData") => {
|
||||
validateStatus: _ => true
|
||||
})
|
||||
if (headResponse.status === 304) {
|
||||
debug("文件 %s 命中缓存", fp)
|
||||
console.log("文件 %s 命中缓存", fp)
|
||||
const etagLength = fd.readUInt8()
|
||||
return JSON.parse(fd.subarray(1 + etagLength).toString())
|
||||
} else {
|
||||
@@ -203,14 +203,6 @@ const upload = async data => {
|
||||
return await cloud.post("/achievement-export", data)
|
||||
}
|
||||
|
||||
const keypress = async () => {
|
||||
process.stdin.setRawMode(true)
|
||||
return new Promise(resolve => process.stdin.once("data", () => {
|
||||
process.stdin.setRawMode(false)
|
||||
resolve()
|
||||
}))
|
||||
}
|
||||
|
||||
const checkUpdate = async () => {
|
||||
const data = (await cloud.get("/latest-version")).data
|
||||
if (data["vc"] !== version.code) {
|
||||
@@ -231,9 +223,12 @@ const brotliDecompressSync = data => zlib.brotliDecompressSync(data)
|
||||
|
||||
let hostsContent = ""
|
||||
|
||||
const setupHost = _ => {
|
||||
const setupHost = (restore = false) => {
|
||||
const path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
|
||||
fs.chmodSync(path, 0o777)
|
||||
if (restore) {
|
||||
fs.writeFileSync(path, hostsContent)
|
||||
} else {
|
||||
hostsContent = fs.readFileSync(path, "utf-8")
|
||||
const requireHosts = new Map()
|
||||
requireHosts.set(conf.dispatchUrl, "127.0.0.1")
|
||||
@@ -259,6 +254,7 @@ const setupHost = _ => {
|
||||
return `${pair[1]} ${pair[0]}`
|
||||
}).join("\n")
|
||||
fs.writeFileSync(path, newContent)
|
||||
}
|
||||
debug("修改SystemHosts")
|
||||
process.on("exit", () => {
|
||||
fs.writeFileSync(path, hostsContent)
|
||||
@@ -290,5 +286,5 @@ class KPacket {
|
||||
|
||||
module.exports = {
|
||||
log, sleep, encodeProto, decodeProto, initConfig, splitPacket, upload, brotliCompressSync, brotliDecompressSync,
|
||||
setupHost, loadCache, debug, checkCDN, checkUpdate, keypress, KPacket, cdnUrlFormat
|
||||
setupHost, loadCache, debug, checkCDN, checkUpdate, KPacket, cdnUrlFormat
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user