Normalize Windows edition and install date parsing
This commit is contained in:
parent
694bda22cd
commit
6a8f7a63aa
1 changed files with 42 additions and 11 deletions
|
|
@ -273,7 +273,13 @@ function parseWindowsInstallDate(value: unknown): Date | null {
|
||||||
if (!value) return null
|
if (!value) return null
|
||||||
if (value instanceof Date) return value
|
if (value instanceof Date) return value
|
||||||
if (typeof value === "number" && Number.isFinite(value)) {
|
if (typeof value === "number" && Number.isFinite(value)) {
|
||||||
return new Date(value)
|
if (value > 10_000_000_000) {
|
||||||
|
return new Date(value)
|
||||||
|
}
|
||||||
|
if (value > 1_000_000_000) {
|
||||||
|
return new Date(value * 1000)
|
||||||
|
}
|
||||||
|
return new Date(value * 1000)
|
||||||
}
|
}
|
||||||
if (typeof value !== "string") return null
|
if (typeof value !== "string") return null
|
||||||
const trimmed = value.trim()
|
const trimmed = value.trim()
|
||||||
|
|
@ -329,6 +335,7 @@ function parseWindowsInstallDate(value: unknown): Date | null {
|
||||||
|
|
||||||
type WindowsOsInfo = {
|
type WindowsOsInfo = {
|
||||||
productName?: string
|
productName?: string
|
||||||
|
caption?: string
|
||||||
editionId?: string
|
editionId?: string
|
||||||
displayVersion?: string
|
displayVersion?: string
|
||||||
releaseId?: string
|
releaseId?: string
|
||||||
|
|
@ -355,10 +362,15 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
|
||||||
|
|
||||||
const family = read("Family")
|
const family = read("Family")
|
||||||
const edition = read("Edition")
|
const edition = read("Edition")
|
||||||
|
const captionRaw = readFlexible("Caption", "caption")
|
||||||
|
const captionNormalized = captionRaw ? captionRaw.replace(/^Microsoft\s+/i, "").trim() : undefined
|
||||||
|
|
||||||
const productName =
|
let productName =
|
||||||
readFlexible("ProductName", "productName", "Name", "name", "Caption", "caption") ??
|
readFlexible("ProductName", "productName", "Name", "name") ??
|
||||||
(family && edition ? `${family} ${edition}` : family ?? edition ?? undefined)
|
(family && edition ? `${family} ${edition}` : family ?? edition ?? undefined)
|
||||||
|
if (captionNormalized && /windows/i.test(captionNormalized)) {
|
||||||
|
productName = captionNormalized
|
||||||
|
}
|
||||||
|
|
||||||
const editionId =
|
const editionId =
|
||||||
readFlexible("EditionID", "editionId", "Edition", "edition", "SkuEdition", "skuEdition", "CompositionEditionID", "compositionEditionId") ??
|
readFlexible("EditionID", "editionId", "Edition", "edition", "SkuEdition", "skuEdition", "CompositionEditionID", "compositionEditionId") ??
|
||||||
|
|
@ -409,9 +421,16 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
|
||||||
parseWindowsInstallDate(value["InstallDateTime"]) ??
|
parseWindowsInstallDate(value["InstallDateTime"]) ??
|
||||||
parseWindowsInstallDate(value["InstalledOn"])
|
parseWindowsInstallDate(value["InstalledOn"])
|
||||||
|
|
||||||
const experience =
|
const experience = (() => {
|
||||||
readFlexible("Experience", "experience", "FeatureExperiencePack", "featureExperiencePack") ??
|
const exp = readFlexible("Experience", "experience")
|
||||||
(currentBuildNumber ? `OS Build ${currentBuildNumber}` : undefined)
|
if (exp) return exp
|
||||||
|
const pack = readFlexible("FeatureExperiencePack", "featureExperiencePack")
|
||||||
|
if (pack) {
|
||||||
|
const trimmed = pack.trim()
|
||||||
|
if (trimmed) return `Pacote de experiência ${trimmed}`
|
||||||
|
}
|
||||||
|
return currentBuildNumber ? `OS Build ${currentBuildNumber}` : undefined
|
||||||
|
})()
|
||||||
|
|
||||||
const productId = readFlexible("ProductID", "productID", "ProductId", "productId", "ProductKeyId", "productKeyId")
|
const productId = readFlexible("ProductID", "productID", "ProductId", "productId", "ProductKeyId", "productKeyId")
|
||||||
const partialProductKey = readFlexible("PartialProductKey", "partialProductKey")
|
const partialProductKey = readFlexible("PartialProductKey", "partialProductKey")
|
||||||
|
|
@ -435,6 +454,7 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
|
||||||
registeredOwner,
|
registeredOwner,
|
||||||
installDate,
|
installDate,
|
||||||
experience,
|
experience,
|
||||||
|
caption: captionNormalized ?? captionRaw ?? undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1209,7 +1229,15 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
||||||
return a.name.localeCompare(b.name, "pt-BR")
|
return a.name.localeCompare(b.name, "pt-BR")
|
||||||
})
|
})
|
||||||
}, [windowsSoftware])
|
}, [windowsSoftware])
|
||||||
const windowsEditionLabel = windowsOsInfo?.productName ?? windowsOsInfo?.editionId ?? null
|
const windowsEditionLabel = useMemo(() => {
|
||||||
|
const raw =
|
||||||
|
windowsOsInfo?.productName ??
|
||||||
|
windowsOsInfo?.caption ??
|
||||||
|
windowsOsInfo?.editionId ??
|
||||||
|
null
|
||||||
|
if (!raw) return null
|
||||||
|
return raw.replace(/^Microsoft\s+/i, "").trim()
|
||||||
|
}, [windowsOsInfo?.productName, windowsOsInfo?.caption, windowsOsInfo?.editionId])
|
||||||
const windowsVersionLabel = windowsOsInfo?.displayVersion ?? windowsOsInfo?.version ?? windowsOsInfo?.releaseId ?? null
|
const windowsVersionLabel = windowsOsInfo?.displayVersion ?? windowsOsInfo?.version ?? windowsOsInfo?.releaseId ?? null
|
||||||
const windowsBuildLabel = windowsOsInfo?.currentBuildNumber ?? windowsOsInfo?.currentBuild ?? null
|
const windowsBuildLabel = windowsOsInfo?.currentBuildNumber ?? windowsOsInfo?.currentBuild ?? null
|
||||||
const windowsInstallDateLabel = windowsOsInfo?.installDate ? formatAbsoluteDateTime(windowsOsInfo.installDate) : null
|
const windowsInstallDateLabel = windowsOsInfo?.installDate ? formatAbsoluteDateTime(windowsOsInfo.installDate) : null
|
||||||
|
|
@ -1455,13 +1483,16 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
||||||
const base = machine?.osName?.trim()
|
const base = machine?.osName?.trim()
|
||||||
const edition = windowsEditionLabel?.trim()
|
const edition = windowsEditionLabel?.trim()
|
||||||
if (edition) {
|
if (edition) {
|
||||||
if (base && edition.toLowerCase().includes(base.toLowerCase())) {
|
if (!base) return edition
|
||||||
|
const baseLower = base.toLowerCase()
|
||||||
|
const editionLower = edition.toLowerCase()
|
||||||
|
if (editionLower.includes(baseLower) || baseLower.includes(editionLower)) {
|
||||||
return edition
|
return edition
|
||||||
}
|
}
|
||||||
if (base) {
|
if (baseLower.startsWith("windows") && editionLower.startsWith("windows")) {
|
||||||
return `${base} ${edition}`.replace(/\s+/g, " ").trim()
|
return edition
|
||||||
}
|
}
|
||||||
return edition
|
return `${base} ${edition}`.replace(/\s+/g, " ").trim()
|
||||||
}
|
}
|
||||||
return base ?? ""
|
return base ?? ""
|
||||||
}, [machine?.osName, windowsEditionLabel])
|
}, [machine?.osName, windowsEditionLabel])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue