diff --git a/.gitmodules b/.gitmodules index 3a6a3ff..b7ee6a9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "wmi"] +[submodule "native/src/wmi"] path = native/src/wmi - url = https://github.com/Thomas-Sparber/wmi + url = https://github.com/Thomas-Sparber/wmi.git diff --git a/appcenter.js b/appcenter.js index dd62d5e..1cf4d0d 100644 --- a/appcenter.js +++ b/appcenter.js @@ -1,62 +1,33 @@ -const cp = require("child_process") const axios = require("axios") const crypto = require("crypto") const { version } = require("./version") +const { getDeviceID, getDeviceInfo } = require("./native") const getTimestamp = (d = new Date()) => { const p = i => i.toString().padStart(2, "0") return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}T${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}.${p(d.getUTCMilliseconds())}Z` } -const readRegistry = (path, key, def) => { - try { - const i = cp.execSync(`reg query "${path}" /v ${key}`, { - encoding: "utf-8" - }).split("\n")[2].split(" ").filter(s => s.length > 0).map(s => s.trim()) - switch (i[1]) { - case "REG_SZ": - return i[2] - case "REG_DWORD": - return parseInt(i[2]) - default: - return def - } - } catch (e) { - return def - } -} - const queue = [] const session = crypto.randomUUID() const key = "648b83bf-d439-49bd-97f4-e1e506bdfe39" const install = (() => { - const s = readRegistry("HKCU\\SOFTWARE\\miHoYoSDK", "MIHOYOSDK_DEVICE_ID", crypto.randomUUID()) - return `${s.substring(0, 8)}-${s.substring(8, 12)}-${s.substring(12, 16)}-${s.substring(16, 20)}-${s.substring(20, 32)}` + const id = getDeviceID() + return id === undefined ? crypto.randomUUID() : id })() const device = (() => { - const csi = cp.execSync("wmic computersystem get manufacturer,model /format:csv", { - encoding: "utf-8" - }).split("\n")[2].split(",").map(s => s.trim()) - const osi = cp.execSync("wmic os get currentTimeZone, version /format:csv", { - encoding: "utf-8" - }).split("\n")[2].split(",").map(s => s.trim()) - return { - model: csi[2], - oemName: csi[1], - timeZoneOffset: parseInt(osi[1]), - osBuild: `${osi[2]}.${readRegistry("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "UBR")}`, - osVersion: osi[2], - locale: readRegistry("HKCU\\Control Panel\\International", "LocaleName", "zh-CN"), - carrierCountry: readRegistry("HKCU\\Control Panel\\International\\Geo", "Name", "CN"), - sdkName: "appcenter.wpf.netcore", - sdkVersion: "4.5.0", - osName: "WINDOWS", - appVersion: version.name, - appBuild: version.code, - appNamespace: "default" - } + console.time("Initialize device info") + const info = getDeviceInfo() + info.appBuild = version.code + info.appVersion = version.name + info.sdkName = "appcenter.wpf.netcore" + info.sdkVersion = "4.5.0" + info.osName = "WINDOWS" + info.appNamespace = "default" + console.timeEnd("Initialize device info") + return info })() const upload = () => { diff --git a/native.d.ts b/native.d.ts index 77e50bf..8afc179 100644 --- a/native.d.ts +++ b/native.d.ts @@ -1,5 +1,5 @@ export function selectGameExecutable(): string export function checkGameIsRunning(processName: string): boolean export function whoUseThePort(port: number): object -export function getDeviceInfo(): object +export function getDeviceInfo(): any export function getDeviceID(): string diff --git a/native/src/main.cc b/native/src/main.cc index c53bed2..cfd98ee 100644 --- a/native/src/main.cc +++ b/native/src/main.cc @@ -95,7 +95,7 @@ namespace native { return env.Null(); } string id = WStringToString(wd); - return Napi::String::New(env, id.substr(0, 8) + id.substr(8, 4) + id.substr(12, 4) + id.substr(16, 4) + id.substr(20, 12)); + return Napi::String::New(env, id.substr(0, 8) + "-" + id.substr(8, 4) + "-" + id.substr(12, 4) + "-" + id.substr(16, 4) + "-" + id.substr(20, 12)); } Value getDeviceInfo(const CallbackInfo &info) {