getValue method
Implementation
String? getValue(String name) {
final langCodepages = [
// try the language and codepage from the EXE
[_data.lpLang!.ref.wLanguage, _data.lpLang!.ref.wCodePage],
// try the default language and codepage from the EXE
[_GetUserDefaultLangID(), _data.lpLang!.ref.wCodePage],
// try the language from the EXE and Latin codepage (most common)
[_data.lpLang!.ref.wLanguage, 1252],
// try the default language and Latin codepage (most common)
[_GetUserDefaultLangID(), 1252],
];
String? value;
final Pointer<IntPtr>? lplpBuffer = calloc<IntPtr>();
final Pointer<Uint32>? puLen = calloc<Uint32>();
String toHex4(int val) => val.toRadixString(16).padLeft(4, '0');
for (final langCodepage in langCodepages) {
final lang = toHex4(langCodepage[0]!);
final codepage = toHex4(langCodepage[1]!);
final lpSubBlock = TEXT('\\StringFileInfo\\$lang$codepage\\$name');
final res =
VerQueryValue(_data.lpBlock!, lpSubBlock, lplpBuffer!.cast(), puLen!);
calloc.free(lpSubBlock);
if (res != 0 && lplpBuffer.value != 0 && puLen.value > 0) {
final ptr = Pointer<Utf16>.fromAddress(lplpBuffer.value);
value = ptr.toDartString();
break;
}
}
calloc.free(lplpBuffer!);
calloc.free(puLen!);
return value;
}