From 439fb46ac2612ee78d59f7bb9b0f333ca31d83fe Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 21 Oct 2026 12:51:47 -0700 Subject: [PATCH] fix(windows): look for the version in the usual string tables when a file lists none executable_version looked for ProductVersion only in the languages the file's \VarFileInfo\Translation lists, so a file without that entry had no version and its portable install was rolled back. After the listed languages it now also tries U.S. English in UTF-16, Windows-1252 and no code page (040904B0, 040904E4, 04090000), as .NET's FileVersionInfo does. --- crates/native/src/detect.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/native/src/detect.rs b/crates/native/src/detect.rs index 698939c7..9ca8833c 100644 --- a/crates/native/src/detect.rs +++ b/crates/native/src/detect.rs @@ -189,10 +189,20 @@ pub mod windows { pub fn executable_version(path: &std::path::Path) -> Option { let path = dunce::canonicalize(path).ok()?; let info = winsafe::HVERSIONINFO::GetFileVersionInfo(path.to_str()?).ok()?; - let product = info.langs_and_cps().ok()?.iter().find_map(|&lang| info.str_val(lang, "ProductVersion").ok())?; + let listed = info.langs_and_cps().map(<[_]>::to_vec).unwrap_or_default(); + let product = string_tables(&listed).into_iter().find_map(|table| info.str_val(table, "ProductVersion").ok())?; version::parse(product.trim()) } + /// The string tables to look in: the languages the file lists, then U.S. English in UTF-16, + /// Windows-1252 and no code page, as .NET's `FileVersionInfo` also tries when a file lists none + /// or its listed one has no strings. + pub(crate) fn string_tables(listed: &[(winsafe::LANGID, winsafe::co::CP)]) -> Vec<(winsafe::LANGID, winsafe::co::CP)> { + use winsafe::{LANGID, co}; + let us = LANGID::new(co::LANG::ENGLISH, co::SUBLANG::ENGLISH_US); + listed.iter().copied().chain([(us, co::CP::UTF16), (us, co::CP::WINDOWS_1252), (us, co::CP::ACP)]).collect() + } + /// An MSI install found in the registry. pub struct MsiInstall { pub product_code: String, @@ -517,6 +527,19 @@ mod tests { assert_eq!(windows::executable_version(&dir.path().join("missing.exe")), None); } + /// Without a listed language, the version is still looked for in the string tables .NET's + /// `FileVersionInfo` falls back to (040904B0, 040904E4, 04090000), after any listed one. + #[cfg(windows)] + #[test] + fn the_version_is_looked_for_in_the_usual_string_tables_too() { + use winsafe::{LANGID, co}; + let key = |(lang, cp): (LANGID, co::CP)| format!("{:04x}{:04x}", u16::from(lang), u16::from(cp)); + let keys = |listed: &[(LANGID, co::CP)]| windows::string_tables(listed).into_iter().map(key).collect::>(); + assert_eq!(keys(&[]), ["040904b0", "040904e4", "04090000"]); + let german = (LANGID::new(co::LANG::GERMAN, co::SUBLANG::GERMAN), co::CP::UTF16); + assert_eq!(keys(&[german]), ["040704b0", "040904b0", "040904e4", "04090000"]); + } + #[test] fn recognises_appimage_names_conservatively() { let pdf = ["pdfcraft", "printcraft"];