2 * Implementation of VERSION.DLL - Version Info access
4 * Copyright 1996,1997 Marcus Meissner
5 * Copyright 1997 David Cuthbert
6 * Copyright 1999 Ulrich Weigand
14 #include "wine/winestring.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(ver
)
23 /******************************************************************************
25 * This function will print via dprintf[_]ver to stddeb debug info regarding
26 * the file info structure vffi.
27 * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
28 * Added this function to clean up the code.
30 *****************************************************************************/
31 static void print_vffi_debug(VS_FIXEDFILEINFO
*vffi
)
33 TRACE(" structversion=%u.%u, fileversion=%u.%u.%u.%u, productversion=%u.%u.%u.%u, flagmask=0x%lx, flags=%s%s%s%s%s%s\n",
34 HIWORD(vffi
->dwStrucVersion
),LOWORD(vffi
->dwStrucVersion
),
35 HIWORD(vffi
->dwFileVersionMS
),LOWORD(vffi
->dwFileVersionMS
),
36 HIWORD(vffi
->dwFileVersionLS
),LOWORD(vffi
->dwFileVersionLS
),
37 HIWORD(vffi
->dwProductVersionMS
),LOWORD(vffi
->dwProductVersionMS
),
38 HIWORD(vffi
->dwProductVersionLS
),LOWORD(vffi
->dwProductVersionLS
),
39 vffi
->dwFileFlagsMask
,
40 (vffi
->dwFileFlags
& VS_FF_DEBUG
) ? "DEBUG," : "",
41 (vffi
->dwFileFlags
& VS_FF_PRERELEASE
) ? "PRERELEASE," : "",
42 (vffi
->dwFileFlags
& VS_FF_PATCHED
) ? "PATCHED," : "",
43 (vffi
->dwFileFlags
& VS_FF_PRIVATEBUILD
) ? "PRIVATEBUILD," : "",
44 (vffi
->dwFileFlags
& VS_FF_INFOINFERRED
) ? "INFOINFERRED," : "",
45 (vffi
->dwFileFlags
& VS_FF_SPECIALBUILD
) ? "SPECIALBUILD," : ""
49 DPRINTF(" OS=0x%x.0x%x ",
50 HIWORD(vffi
->dwFileOS
),
51 LOWORD(vffi
->dwFileOS
)
53 switch (vffi
->dwFileOS
&0xFFFF0000) {
54 case VOS_DOS
:DPRINTF("DOS,");break;
55 case VOS_OS216
:DPRINTF("OS/2-16,");break;
56 case VOS_OS232
:DPRINTF("OS/2-32,");break;
57 case VOS_NT
:DPRINTF("NT,");break;
60 DPRINTF("UNKNOWN(0x%lx),",vffi
->dwFileOS
&0xFFFF0000);break;
62 switch (LOWORD(vffi
->dwFileOS
)) {
63 case VOS__BASE
:DPRINTF("BASE");break;
64 case VOS__WINDOWS16
:DPRINTF("WIN16");break;
65 case VOS__WINDOWS32
:DPRINTF("WIN32");break;
66 case VOS__PM16
:DPRINTF("PM16");break;
67 case VOS__PM32
:DPRINTF("PM32");break;
68 default:DPRINTF("UNKNOWN(0x%x)",LOWORD(vffi
->dwFileOS
));break;
72 switch (vffi
->dwFileType
) {
75 TRACE("filetype=Unknown(0x%lx)",vffi
->dwFileType
);
77 case VFT_APP
:TRACE("filetype=APP,");break;
78 case VFT_DLL
:TRACE("filetype=DLL,");break;
80 TRACE("filetype=DRV,");
81 switch(vffi
->dwFileSubtype
) {
84 DPRINTF("UNKNOWN(0x%lx)",vffi
->dwFileSubtype
);
86 case VFT2_DRV_PRINTER
:
89 case VFT2_DRV_KEYBOARD
:
92 case VFT2_DRV_LANGUAGE
:
95 case VFT2_DRV_DISPLAY
:
101 case VFT2_DRV_NETWORK
:
104 case VFT2_DRV_SYSTEM
:
107 case VFT2_DRV_INSTALLABLE
:
108 DPRINTF("INSTALLABLE");
116 case VFT2_DRV_INPUTMETHOD
:
117 DPRINTF("INPUTMETHOD");
122 TRACE("filetype=FONT.");
123 switch (vffi
->dwFileSubtype
) {
125 DPRINTF("UNKNOWN(0x%lx)",vffi
->dwFileSubtype
);
127 case VFT2_FONT_RASTER
:DPRINTF("RASTER");break;
128 case VFT2_FONT_VECTOR
:DPRINTF("VECTOR");break;
129 case VFT2_FONT_TRUETYPE
:DPRINTF("TRUETYPE");break;
132 case VFT_VXD
:TRACE("filetype=VXD");break;
133 case VFT_STATIC_LIB
:TRACE("filetype=STATIC_LIB");break;
136 TRACE(" filedata=0x%lx.0x%lx\n",
137 vffi
->dwFileDateMS
,vffi
->dwFileDateLS
);
141 /***********************************************************************
142 * Version Info Structure
150 #if 0 /* variable length structure */
154 VS_VERSION_INFO_STRUCT16 Children
[];
156 } VS_VERSION_INFO_STRUCT16
;
164 #if 0 /* variable length structure */
168 VS_VERSION_INFO_STRUCT32 Children
[];
170 } VS_VERSION_INFO_STRUCT32
;
172 #define VersionInfoIs16( ver ) \
173 ( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
175 #define VersionInfo16_Value( ver ) \
176 (LPBYTE)( (DWORD)((ver)->szKey) + (((lstrlenA((ver)->szKey)+1) + 3) & ~3 ))
177 #define VersionInfo32_Value( ver ) \
178 (LPBYTE)( (DWORD)((ver)->szKey) + ((2*(lstrlenW((ver)->szKey)+1) + 3) & ~3 ))
180 #define VersionInfo16_Children( ver ) \
181 (VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
182 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
183 #define VersionInfo32_Children( ver ) \
184 (VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
185 ( ( (ver)->wValueLength * \
186 ((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
188 #define VersionInfo16_Next( ver ) \
189 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
190 #define VersionInfo32_Next( ver ) \
191 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
193 /***********************************************************************
194 * ConvertVersionInfo32To16 [internal]
196 void ConvertVersionInfo32To16( VS_VERSION_INFO_STRUCT32
*info32
,
197 VS_VERSION_INFO_STRUCT16
*info16
)
199 /* Copy data onto local stack to prevent overwrites */
200 WORD wLength
= info32
->wLength
;
201 WORD wValueLength
= info32
->wValueLength
;
202 WORD bText
= info32
->bText
;
203 LPBYTE lpValue
= VersionInfo32_Value( info32
);
204 VS_VERSION_INFO_STRUCT32
*child32
= VersionInfo32_Children( info32
);
205 VS_VERSION_INFO_STRUCT16
*child16
;
207 TRACE("Converting %p to %p\n", info32
, info16
);
208 TRACE("wLength %d, wValueLength %d, bText %d, value %p, child %p\n",
209 wLength
, wValueLength
, bText
, lpValue
, child32
);
212 lstrcpyWtoA( info16
->szKey
, info32
->szKey
);
214 TRACE("Copied key from %p to %p: %s\n", info32
->szKey
, info16
->szKey
,
215 debugstr_a(info16
->szKey
) );
218 if ( wValueLength
== 0 )
220 info16
->wValueLength
= 0;
221 TRACE("No value present\n" );
225 info16
->wValueLength
= lstrlenW( (LPCWSTR
)lpValue
) + 1;
226 lstrcpyWtoA( VersionInfo16_Value( info16
), (LPCWSTR
)lpValue
);
228 TRACE("Copied value from %p to %p: %s\n", lpValue
,
229 VersionInfo16_Value( info16
),
230 debugstr_a(VersionInfo16_Value( info16
)) );
234 info16
->wValueLength
= wValueLength
;
235 memmove( VersionInfo16_Value( info16
), lpValue
, wValueLength
);
237 TRACE("Copied value from %p to %p: %d bytes\n", lpValue
,
238 VersionInfo16_Value( info16
), wValueLength
);
241 /* Convert children */
242 child16
= VersionInfo16_Children( info16
);
243 while ( (DWORD
)child32
< (DWORD
)info32
+ wLength
)
245 VS_VERSION_INFO_STRUCT32
*nextChild
= VersionInfo32_Next( child32
);
247 ConvertVersionInfo32To16( child32
, child16
);
249 child16
= VersionInfo16_Next( child16
);
254 info16
->wLength
= (DWORD
)child16
- (DWORD
)info16
;
256 TRACE("Finished, length is %d (%p - %p)\n",
257 info16
->wLength
, info16
, child16
);
261 /***********************************************************************
262 * GetFileVersionInfoSize32A [VERSION.2]
264 DWORD WINAPI
GetFileVersionInfoSizeA( LPCSTR filename
, LPDWORD handle
)
266 VS_FIXEDFILEINFO
*vffi
;
267 DWORD len
, ret
, offset
;
270 TRACE("(%s,%p)\n", debugstr_a(filename
), handle
);
272 len
= GetFileResourceSize( filename
,
273 MAKEINTRESOURCEA(VS_FILE_INFO
),
274 MAKEINTRESOURCEA(VS_VERSION_INFO
),
278 ret
= GetFileResource( filename
,
279 MAKEINTRESOURCEA(VS_FILE_INFO
),
280 MAKEINTRESOURCEA(VS_VERSION_INFO
),
281 offset
, sizeof( buf
), buf
);
284 if ( handle
) *handle
= offset
;
286 if ( VersionInfoIs16( buf
) )
287 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)buf
);
289 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32
*)buf
);
291 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
293 WARN("vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
294 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
298 if ( ((VS_VERSION_INFO_STRUCT16
*)buf
)->wLength
< len
)
299 len
= ((VS_VERSION_INFO_STRUCT16
*)buf
)->wLength
;
302 print_vffi_debug( vffi
);
307 /***********************************************************************
308 * GetFileVersionInfoSize32W [VERSION.3]
310 DWORD WINAPI
GetFileVersionInfoSizeW( LPCWSTR filename
, LPDWORD handle
)
312 LPSTR fn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
313 DWORD ret
= GetFileVersionInfoSizeA( fn
, handle
);
314 HeapFree( GetProcessHeap(), 0, fn
);
318 /***********************************************************************
319 * GetFileVersionInfo32A [VERSION.1]
321 DWORD WINAPI
GetFileVersionInfoA( LPCSTR filename
, DWORD handle
,
322 DWORD datasize
, LPVOID data
)
324 TRACE("(%s,%ld,size=%ld,data=%p)\n",
325 debugstr_a(filename
), handle
, datasize
, data
);
327 if ( !GetFileResource( filename
, MAKEINTRESOURCEA(VS_FILE_INFO
),
328 MAKEINTRESOURCEA(VS_VERSION_INFO
),
329 handle
, datasize
, data
) )
332 if ( datasize
>= sizeof(VS_VERSION_INFO_STRUCT16
)
333 && datasize
>= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
334 && !VersionInfoIs16( data
) )
336 /* convert resource from PE format to NE format */
337 ConvertVersionInfo32To16( (VS_VERSION_INFO_STRUCT32
*)data
,
338 (VS_VERSION_INFO_STRUCT16
*)data
);
344 /***********************************************************************
345 * GetFileVersionInfo32W [VERSION.4]
347 DWORD WINAPI
GetFileVersionInfoW( LPCWSTR filename
, DWORD handle
,
348 DWORD datasize
, LPVOID data
)
350 LPSTR fn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
353 TRACE("(%s,%ld,size=%ld,data=%p)\n",
354 debugstr_a(fn
), handle
, datasize
, data
);
356 if ( !GetFileResource( fn
, MAKEINTRESOURCEA(VS_FILE_INFO
),
357 MAKEINTRESOURCEA(VS_VERSION_INFO
),
358 handle
, datasize
, data
) )
361 else if ( datasize
>= sizeof(VS_VERSION_INFO_STRUCT16
)
362 && datasize
>= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
363 && VersionInfoIs16( data
) )
365 ERR("Cannot access NE resource in %s\n", debugstr_a(fn
) );
369 HeapFree( GetProcessHeap(), 0, fn
);
374 /***********************************************************************
375 * VersionInfo16_FindChild [internal]
377 VS_VERSION_INFO_STRUCT16
*VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16
*info
,
378 LPCSTR szKey
, UINT cbKey
)
380 VS_VERSION_INFO_STRUCT16
*child
= VersionInfo16_Children( info
);
382 while ( (DWORD
)child
< (DWORD
)info
+ info
->wLength
)
384 if ( !lstrncmpiA( child
->szKey
, szKey
, cbKey
) )
387 if (!(child
->wLength
)) return NULL
;
388 child
= VersionInfo16_Next( child
);
394 /***********************************************************************
395 * VersionInfo32_FindChild [internal]
397 VS_VERSION_INFO_STRUCT32
*VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32
*info
,
398 LPCWSTR szKey
, UINT cbKey
)
400 VS_VERSION_INFO_STRUCT32
*child
= VersionInfo32_Children( info
);
402 while ( (DWORD
)child
< (DWORD
)info
+ info
->wLength
)
404 if ( !CRTDLL__wcsnicmp( child
->szKey
, szKey
, cbKey
) )
407 child
= VersionInfo32_Next( child
);
413 /***********************************************************************
414 * VerQueryValue32A [VERSION.12]
416 DWORD WINAPI
VerQueryValueA( LPVOID pBlock
, LPCSTR lpSubBlock
,
417 LPVOID
*lplpBuffer
, UINT
*puLen
)
419 VS_VERSION_INFO_STRUCT16
*info
= (VS_VERSION_INFO_STRUCT16
*)pBlock
;
420 if ( !VersionInfoIs16( info
) )
422 ERR("called on PE resource!\n" );
426 TRACE("(%p,%s,%p,%p)\n",
427 pBlock
, debugstr_a(lpSubBlock
), lplpBuffer
, puLen
);
429 while ( *lpSubBlock
)
431 /* Find next path component */
433 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
434 if ( *lpNextSlash
== '\\' )
437 /* Skip empty components */
438 if ( lpNextSlash
== lpSubBlock
)
444 /* We have a non-empty component: search info for key */
445 info
= VersionInfo16_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
446 if ( !info
) return FALSE
;
448 /* Skip path component */
449 lpSubBlock
= lpNextSlash
;
453 *lplpBuffer
= VersionInfo16_Value( info
);
454 *puLen
= info
->wValueLength
;
459 /***********************************************************************
460 * VerQueryValue32W [VERSION.13]
462 DWORD WINAPI
VerQueryValueW( LPVOID pBlock
, LPCWSTR lpSubBlock
,
463 LPVOID
*lplpBuffer
, UINT
*puLen
)
465 VS_VERSION_INFO_STRUCT32
*info
= (VS_VERSION_INFO_STRUCT32
*)pBlock
;
466 if ( VersionInfoIs16( info
) )
468 ERR("called on NE resource!\n" );
472 TRACE("(%p,%s,%p,%p)\n",
473 pBlock
, debugstr_w(lpSubBlock
), lplpBuffer
, puLen
);
475 while ( *lpSubBlock
)
477 /* Find next path component */
479 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
480 if ( *lpNextSlash
== '\\' )
483 /* Skip empty components */
484 if ( lpNextSlash
== lpSubBlock
)
490 /* We have a non-empty component: search info for key */
491 info
= VersionInfo32_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
492 if ( !info
) return FALSE
;
494 /* Skip path component */
495 lpSubBlock
= lpNextSlash
;
499 *lplpBuffer
= VersionInfo32_Value( info
);
500 *puLen
= info
->wValueLength
;
505 extern LPCSTR
WINE_GetLanguageName( UINT langid
);
507 /***********************************************************************
508 * VerLanguageName32A [VERSION.9]
510 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
516 TRACE("(%d,%p,%d)\n", wLang
, szLang
, nSize
);
519 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
524 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
527 result
= RegQueryValueA( HKEY_LOCAL_MACHINE
, buffer
, szLang
, (LPDWORD
)&nSize
);
528 if ( result
== ERROR_SUCCESS
|| result
== ERROR_MORE_DATA
)
532 * If that fails, use the internal table
533 * (actually, Windows stores the names in a string table resource ...)
536 name
= WINE_GetLanguageName( wLang
);
537 lstrcpynA( szLang
, name
, nSize
);
538 return lstrlenA( name
);
541 /***********************************************************************
542 * VerLanguageName32W [VERSION.10]
544 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
551 TRACE("(%d,%p,%d)\n", wLang
, szLang
, nSize
);
554 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
559 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
562 keyname
= HEAP_strdupAtoW( GetProcessHeap(), 0, buffer
);
563 result
= RegQueryValueW( HKEY_LOCAL_MACHINE
, keyname
, szLang
, (LPDWORD
)&nSize
);
564 HeapFree( GetProcessHeap(), 0, keyname
);
566 if ( result
== ERROR_SUCCESS
|| result
== ERROR_MORE_DATA
)
570 * If that fails, use the internal table
571 * (actually, Windows stores the names in a string table resource ...)
574 name
= WINE_GetLanguageName( wLang
);
575 lstrcpynAtoW( szLang
, name
, nSize
);
576 return lstrlenA( name
);