This commit is contained in:
HolographicHat
2022-04-05 19:11:12 +08:00
parent a22ad8e87d
commit 18e3d3ffe3
4 changed files with 17 additions and 46 deletions

4
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "wmi"] [submodule "native/src/wmi"]
path = native/src/wmi path = native/src/wmi
url = https://github.com/Thomas-Sparber/wmi url = https://github.com/Thomas-Sparber/wmi.git

View File

@@ -1,62 +1,33 @@
const cp = require("child_process")
const axios = require("axios") const axios = require("axios")
const crypto = require("crypto") const crypto = require("crypto")
const { version } = require("./version") const { version } = require("./version")
const { getDeviceID, getDeviceInfo } = require("./native")
const getTimestamp = (d = new Date()) => { const getTimestamp = (d = new Date()) => {
const p = i => i.toString().padStart(2, "0") 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` 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 queue = []
const session = crypto.randomUUID() const session = crypto.randomUUID()
const key = "648b83bf-d439-49bd-97f4-e1e506bdfe39" const key = "648b83bf-d439-49bd-97f4-e1e506bdfe39"
const install = (() => { const install = (() => {
const s = readRegistry("HKCU\\SOFTWARE\\miHoYoSDK", "MIHOYOSDK_DEVICE_ID", crypto.randomUUID()) const id = getDeviceID()
return `${s.substring(0, 8)}-${s.substring(8, 12)}-${s.substring(12, 16)}-${s.substring(16, 20)}-${s.substring(20, 32)}` return id === undefined ? crypto.randomUUID() : id
})() })()
const device = (() => { const device = (() => {
const csi = cp.execSync("wmic computersystem get manufacturer,model /format:csv", { console.time("Initialize device info")
encoding: "utf-8" const info = getDeviceInfo()
}).split("\n")[2].split(",").map(s => s.trim()) info.appBuild = version.code
const osi = cp.execSync("wmic os get currentTimeZone, version /format:csv", { info.appVersion = version.name
encoding: "utf-8" info.sdkName = "appcenter.wpf.netcore"
}).split("\n")[2].split(",").map(s => s.trim()) info.sdkVersion = "4.5.0"
return { info.osName = "WINDOWS"
model: csi[2], info.appNamespace = "default"
oemName: csi[1], console.timeEnd("Initialize device info")
timeZoneOffset: parseInt(osi[1]), return info
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"
}
})() })()
const upload = () => { const upload = () => {

2
native.d.ts vendored
View File

@@ -1,5 +1,5 @@
export function selectGameExecutable(): string export function selectGameExecutable(): string
export function checkGameIsRunning(processName: string): boolean export function checkGameIsRunning(processName: string): boolean
export function whoUseThePort(port: number): object export function whoUseThePort(port: number): object
export function getDeviceInfo(): object export function getDeviceInfo(): any
export function getDeviceID(): string export function getDeviceID(): string

View File

@@ -95,7 +95,7 @@ namespace native {
return env.Null(); return env.Null();
} }
string id = WStringToString(wd); 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) { Value getDeviceInfo(const CallbackInfo &info) {