--- a/Win32OperatingSystem.st Tue Mar 05 12:54:03 2019 +0100
+++ b/Win32OperatingSystem.st Wed Mar 06 16:08:23 2019 +0100
@@ -5872,37 +5872,29 @@
OBJ data;
if (__isByteArrayLike(aByteArray) && __isStringLike(which)) {
- if (VerQueryValue(__byteArrayVal(aByteArray), __stringVal(which), (LPVOID) &fileInfo, (PUINT) &uLen) == FALSE) {
- RETURN (nil);
- }
- data = __BYTEARRAY_UNINITIALIZED_NEW_INT(uLen);
- memcpy(__byteArrayVal(data), fileInfo, uLen);
- RETURN (data);
+ // be careful: fileInfo points into aByteArray!
+ // Beware of garbage collection after VerQueryValue()!
+ // We use a fixed max size of 1000 bytes here.
+ data = __BYTEARRAY_UNINITIALIZED_NEW_INT(1000);
+ if (VerQueryValue(__byteArrayVal(aByteArray), __stringVal(which), (LPVOID) &fileInfo, &uLen) == FALSE) {
+ RETURN (nil);
+ }
+ memcpy(__byteArrayVal(data), fileInfo, min(1000, uLen));
+ RETURN (data);
}
badArgument: ;
%}.
self primitiveFailed
"
- |bytes vfi lang codePage sfi assocs|
-
- bytes := self getFileVersionInfoOf:'./stx.exe'.
- self extractVersionValue:'\' from:bytes.
- vfi := self extractVersionValue:'\VarFileInfo\Translation' from:bytes.
- lang := vfi unsignedInt16At:1.
- codePage := vfi unsignedInt16At:3.
- assocs := #( 'CompanyName' 'FileDescription' 'FileVersion' 'ProductName') collect:[:each |
- sfi := self extractVersionValue:('\StringFileInfo\%1%2\%3'
- bindWith:(lang hexPrintString:4)
- with:(codePage hexPrintString:4)
- with:each)
- from:bytes.
- each -> (sfi zeroByteStringAt:1 maximumSize:999)
- ].
- Dictionary withAssociations:assocs
+ 100000 timesRepeat:[
+ OperatingSystem getFileInfos:#('ProductVersion' 'CompanyName' 'FileDescription' 'FileVersion' 'ProductName')
+ fromFile:'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
+ ].
"
"Created: / 23-04-2018 / 10:08:04 / Maren"
+ "Modified (comment): / 06-03-2019 / 16:07:21 / Stefan Vogel"
!
fileSeparator
@@ -6199,30 +6191,32 @@
"Retrieve version information from filename and return a dictionary with values for keys in infoKeys.
Returns nil, if fileInfo cannot be extracted."
- |bytes vfi lang codePage sfi assocs|
-
- bytes := self getFileVersionInfoOf:(filename asFilename pathName).
- bytes isEmptyOrNil ifTrue:[^ nil].
+ |bytes vfi lang codePage stringFileInfoBase|
+
+ bytes := self getFileVersionInfoOf:(filename asFilename osName).
+ bytes isEmptyOrNil ifTrue:[
+ ^ nil
+ ].
self extractVersionValue:'\' from:bytes.
vfi := self extractVersionValue:'\VarFileInfo\Translation' from:bytes.
lang := vfi unsignedInt16At:1.
codePage := vfi unsignedInt16At:3.
- assocs := infoKeys collect:[:each |
- sfi := self extractVersionValue:('\StringFileInfo\%1%2\%3'
- bindWith:(lang hexPrintString:4)
- with:(codePage hexPrintString:4)
- with:each)
- from:bytes.
- each -> (sfi zeroByteStringAt:1 maximumSize:999)
- ].
- ^ Dictionary withAssociations:assocs
-
- "
- self getFileInfos:#('CompanyName' 'FileDescription' 'ProductVersion') fromFile:'./stx.exe'
+ stringFileInfoBase := '\StringFileInfo\%1%2\'
+ bindWith:(lang hexPrintString:4)
+ with:(codePage hexPrintString:4).
+ ^ Dictionary withKeys:infoKeys valueBlock:[:eachKey|
+ |sfi|
+ sfi := self extractVersionValue:(stringFileInfoBase, eachKey) from:bytes.
+ sfi zeroByteStringAt:1 maximumSize:999
+ ].
+
+ "
+ self getFileInfos:#('ProductVersion' 'CompanyName' 'FileDescription' 'FileVersion' 'ProductName') fromFile:'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
"
"Created: / 23-04-2018 / 10:29:33 / Maren"
+ "Modified (comment): / 06-03-2019 / 15:47:56 / Stefan Vogel"
!
getFileVersionInfoOf:aPathName