From 41af9c7cdb44a73bf61b59c9ad51866842f671aa Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Wed, 6 Apr 2022 13:05:20 +0800 Subject: [PATCH] better pause impl --- app.js | 4 ++-- export.js | 6 +++--- native.d.ts | 1 + native/src/main.cc | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 8f526b7..da23367 100644 --- a/app.js +++ b/app.js @@ -7,12 +7,12 @@ const { brotliCompressSync, brotliDecompressSync, checkGameIsRunning, checkPortIsUsing } = require("./utils") const { exportData } = require("./export") -const { enablePrivilege } = require("./native") +const { enablePrivilege, pause } = require("./native") const onExit = () => { setupHost(true) console.log("按任意键退出") - cp.execSync("pause > nul", { stdio: "inherit" }) + pause() }; (async () => { diff --git a/export.js b/export.js index 67cf158..d4dc200 100644 --- a/export.js +++ b/export.js @@ -5,7 +5,7 @@ const { copyToClipboard } = require("./native") const exportToSeelie = proto => { const out = { achievements: {} } - proto.list.filter(achievement => achievement.status === 3).forEach(({id}) => { + proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({id}) => { out.achievements[id] = { done: true } }) const fp = `./export-${Date.now()}-seelie.json` @@ -20,7 +20,7 @@ const exportToPaimon = async proto => { excel.forEach(({GoalId, Id}) => { achTable.set(Id, GoalId === undefined ? 0 : GoalId) }) - proto.list.filter(achievement => achievement.status === 3).forEach(({id}) => { + proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({id}) => { const gid = achTable.get(id) if (out.achievement[gid] === undefined) { out.achievement[gid] = {} @@ -52,7 +52,7 @@ const exportToCocogoat = async proto => { const d = new Date(parseInt(`${ts}000`)) return `${d.getFullYear()}/${p(d.getMonth()+1)}/${p(d.getDate())}` } - proto.list.filter(achievement => achievement.status === 3).forEach(({current, finishTimestamp, id, require}) => { + proto.list.filter(a => a.status === 3 || a.status === 2).forEach(({current, finishTimestamp, id, require}) => { out.value.achievements.push({ id: id, status: current === undefined || current === 0 || preStageAchievementIdList.includes(id) ? `${require}/${require}` : `${current}/${require}`, diff --git a/native.d.ts b/native.d.ts index ddfd121..c274af6 100644 --- a/native.d.ts +++ b/native.d.ts @@ -5,3 +5,4 @@ export function copyToClipboard(value: string): any export function enablePrivilege(): any export function getDeviceInfo(): any export function getDeviceID(): string +export function pause(): any diff --git a/native/src/main.cc b/native/src/main.cc index 939378b..204dd9a 100644 --- a/native/src/main.cc +++ b/native/src/main.cc @@ -3,6 +3,7 @@ #include "wmi/wmi.hpp" #include "wmi/wmiclasses.hpp" #include "registry/registry.hpp" +#include #include #pragma comment(lib,"ws2_32.lib") #pragma comment(lib,"iphlpapi.lib") @@ -161,7 +162,15 @@ namespace native { return env.Undefined(); } + Value pause(const CallbackInfo &info) { + while(!_kbhit()) { + Sleep(10); + } + return info.Env().Undefined(); + } + Object init(Env env, Object exports) { + exports.Set("pause", Function::New(env, pause)); exports.Set("getDeviceID", Function::New(env, getDeviceID)); exports.Set("getDeviceInfo", Function::New(env, getDeviceInfo)); exports.Set("whoUseThePort", Function::New(env, whoUseThePort));