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"
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 dbg_decl_str(ver
, 1024);
35 TRACE(ver
," structversion=%u.%u, fileversion=%u.%u.%u.%u, productversion=%u.%u.%u.%u, flagmask=0x%lx, flags=%s%s%s%s%s%s\n",
36 HIWORD(vffi
->dwStrucVersion
),LOWORD(vffi
->dwStrucVersion
),
37 HIWORD(vffi
->dwFileVersionMS
),LOWORD(vffi
->dwFileVersionMS
),
38 HIWORD(vffi
->dwFileVersionLS
),LOWORD(vffi
->dwFileVersionLS
),
39 HIWORD(vffi
->dwProductVersionMS
),LOWORD(vffi
->dwProductVersionMS
),
40 HIWORD(vffi
->dwProductVersionLS
),LOWORD(vffi
->dwProductVersionLS
),
41 vffi
->dwFileFlagsMask
,
42 (vffi
->dwFileFlags
& VS_FF_DEBUG
) ? "DEBUG," : "",
43 (vffi
->dwFileFlags
& VS_FF_PRERELEASE
) ? "PRERELEASE," : "",
44 (vffi
->dwFileFlags
& VS_FF_PATCHED
) ? "PATCHED," : "",
45 (vffi
->dwFileFlags
& VS_FF_PRIVATEBUILD
) ? "PRIVATEBUILD," : "",
46 (vffi
->dwFileFlags
& VS_FF_INFOINFERRED
) ? "INFOINFERRED," : "",
47 (vffi
->dwFileFlags
& VS_FF_SPECIALBUILD
) ? "SPECIALBUILD," : ""
50 dsprintf(ver
," OS=0x%x.0x%x ",
51 HIWORD(vffi
->dwFileOS
),
52 LOWORD(vffi
->dwFileOS
)
54 switch (vffi
->dwFileOS
&0xFFFF0000) {
55 case VOS_DOS
:dsprintf(ver
,"DOS,");break;
56 case VOS_OS216
:dsprintf(ver
,"OS/2-16,");break;
57 case VOS_OS232
:dsprintf(ver
,"OS/2-32,");break;
58 case VOS_NT
:dsprintf(ver
,"NT,");break;
61 dsprintf(ver
,"UNKNOWN(0x%lx),",vffi
->dwFileOS
&0xFFFF0000);break;
63 switch (LOWORD(vffi
->dwFileOS
)) {
64 case VOS__BASE
:dsprintf(ver
,"BASE");break;
65 case VOS__WINDOWS16
:dsprintf(ver
,"WIN16");break;
66 case VOS__WINDOWS32
:dsprintf(ver
,"WIN32");break;
67 case VOS__PM16
:dsprintf(ver
,"PM16");break;
68 case VOS__PM32
:dsprintf(ver
,"PM32");break;
69 default:dsprintf(ver
,"UNKNOWN(0x%x)",LOWORD(vffi
->dwFileOS
));break;
71 TRACE(ver
, "(%s)\n", dbg_str(ver
));
74 switch (vffi
->dwFileType
) {
77 dsprintf(ver
,"filetype=Unknown(0x%lx)",vffi
->dwFileType
);
79 case VFT_APP
:dsprintf(ver
,"filetype=APP,");break;
80 case VFT_DLL
:dsprintf(ver
,"filetype=DLL,");break;
82 dsprintf(ver
,"filetype=DRV,");
83 switch(vffi
->dwFileSubtype
) {
86 dsprintf(ver
,"UNKNOWN(0x%lx)",vffi
->dwFileSubtype
);
88 case VFT2_DRV_PRINTER
:
89 dsprintf(ver
,"PRINTER");
91 case VFT2_DRV_KEYBOARD
:
92 dsprintf(ver
,"KEYBOARD");
94 case VFT2_DRV_LANGUAGE
:
95 dsprintf(ver
,"LANGUAGE");
97 case VFT2_DRV_DISPLAY
:
98 dsprintf(ver
,"DISPLAY");
101 dsprintf(ver
,"MOUSE");
103 case VFT2_DRV_NETWORK
:
104 dsprintf(ver
,"NETWORK");
106 case VFT2_DRV_SYSTEM
:
107 dsprintf(ver
,"SYSTEM");
109 case VFT2_DRV_INSTALLABLE
:
110 dsprintf(ver
,"INSTALLABLE");
113 dsprintf(ver
,"SOUND");
116 dsprintf(ver
,"COMM");
118 case VFT2_DRV_INPUTMETHOD
:
119 dsprintf(ver
,"INPUTMETHOD");
124 dsprintf(ver
,"filetype=FONT.");
125 switch (vffi
->dwFileSubtype
) {
127 dsprintf(ver
,"UNKNOWN(0x%lx)",vffi
->dwFileSubtype
);
129 case VFT2_FONT_RASTER
:dsprintf(ver
,"RASTER");break;
130 case VFT2_FONT_VECTOR
:dsprintf(ver
,"VECTOR");break;
131 case VFT2_FONT_TRUETYPE
:dsprintf(ver
,"TRUETYPE");break;
134 case VFT_VXD
:dsprintf(ver
,"filetype=VXD");break;
135 case VFT_STATIC_LIB
:dsprintf(ver
,"filetype=STATIC_LIB");break;
137 TRACE(ver
, "%s\n", dbg_str(ver
));
139 TRACE(ver
, " filedata=0x%lx.0x%lx\n",
140 vffi
->dwFileDateMS
,vffi
->dwFileDateLS
);
144 /***********************************************************************
145 * Version Info Structure
153 #if 0 /* variable length structure */
157 VS_VERSION_INFO_STRUCT16 Children
[];
159 } VS_VERSION_INFO_STRUCT16
;
167 #if 0 /* variable length structure */
171 VS_VERSION_INFO_STRUCT32 Children
[];
173 } VS_VERSION_INFO_STRUCT32
;
175 #define VersionInfoIs16( ver ) \
176 ( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
178 #define VersionInfo16_Value( ver ) \
179 (LPBYTE)( ((DWORD)((ver)->szKey) + (lstrlenA((ver)->szKey)+1) + 3) & ~3 )
180 #define VersionInfo32_Value( ver ) \
181 (LPBYTE)( ((DWORD)((ver)->szKey) + 2*(lstrlenW((ver)->szKey)+1) + 3) & ~3 )
183 #define VersionInfo16_Children( ver ) \
184 (VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
185 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
186 #define VersionInfo32_Children( ver ) \
187 (VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
188 ( ( (ver)->wValueLength * \
189 ((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
191 #define VersionInfo16_Next( ver ) \
192 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
193 #define VersionInfo32_Next( ver ) \
194 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
196 /***********************************************************************
197 * ConvertVersionInfo32To16 [internal]
199 void ConvertVersionInfo32To16( VS_VERSION_INFO_STRUCT32
*info32
,
200 VS_VERSION_INFO_STRUCT16
*info16
)
202 /* Copy data onto local stack to prevent overwrites */
203 WORD wLength
= info32
->wLength
;
204 WORD wValueLength
= info32
->wValueLength
;
205 WORD bText
= info32
->bText
;
206 LPBYTE lpValue
= VersionInfo32_Value( info32
);
207 VS_VERSION_INFO_STRUCT32
*child32
= VersionInfo32_Children( info32
);
208 VS_VERSION_INFO_STRUCT16
*child16
;
210 TRACE( ver
, "Converting %p to %p\n", info32
, info16
);
211 TRACE( ver
, "wLength %d, wValueLength %d, bText %d, value %p, child %p\n",
212 wLength
, wValueLength
, bText
, lpValue
, child32
);
215 lstrcpyWtoA( info16
->szKey
, info32
->szKey
);
217 TRACE( ver
, "Copied key from %p to %p: %s\n", info32
->szKey
, info16
->szKey
,
218 debugstr_a(info16
->szKey
) );
221 if ( wValueLength
== 0 )
223 info16
->wValueLength
= 0;
224 TRACE( ver
, "No value present\n" );
228 info16
->wValueLength
= lstrlenW( (LPCWSTR
)lpValue
) + 1;
229 lstrcpyWtoA( VersionInfo16_Value( info16
), (LPCWSTR
)lpValue
);
231 TRACE( ver
, "Copied value from %p to %p: %s\n", lpValue
,
232 VersionInfo16_Value( info16
),
233 debugstr_a(VersionInfo16_Value( info16
)) );
237 info16
->wValueLength
= wValueLength
;
238 memmove( VersionInfo16_Value( info16
), lpValue
, wValueLength
);
240 TRACE( ver
, "Copied value from %p to %p: %d bytes\n", lpValue
,
241 VersionInfo16_Value( info16
), wValueLength
);
244 /* Convert children */
245 child16
= VersionInfo16_Children( info16
);
246 while ( (DWORD
)child32
< (DWORD
)info32
+ wLength
)
248 VS_VERSION_INFO_STRUCT32
*nextChild
= VersionInfo32_Next( child32
);
250 ConvertVersionInfo32To16( child32
, child16
);
252 child16
= VersionInfo16_Next( child16
);
257 info16
->wLength
= (DWORD
)child16
- (DWORD
)info16
;
259 TRACE( ver
, "Finished, length is %d (%p - %p)\n",
260 info16
->wLength
, info16
, child16
);
264 /***********************************************************************
265 * GetFileVersionInfoSize32A [VERSION.2]
267 DWORD WINAPI
GetFileVersionInfoSizeA( LPCSTR filename
, LPDWORD handle
)
269 VS_FIXEDFILEINFO
*vffi
;
270 DWORD len
, ret
, offset
;
273 TRACE( ver
, "(%s,%p)\n", debugstr_a(filename
), handle
);
275 len
= GetFileResourceSize( filename
,
276 MAKEINTRESOURCEA(VS_FILE_INFO
),
277 MAKEINTRESOURCEA(VS_VERSION_INFO
),
281 ret
= GetFileResource( filename
,
282 MAKEINTRESOURCEA(VS_FILE_INFO
),
283 MAKEINTRESOURCEA(VS_VERSION_INFO
),
284 offset
, sizeof( buf
), buf
);
287 if ( handle
) *handle
= offset
;
289 if ( VersionInfoIs16( buf
) )
290 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)buf
);
292 vffi
= (VS_FIXEDFILEINFO
*)VersionInfo32_Value( (VS_VERSION_INFO_STRUCT32
*)buf
);
294 if ( vffi
->dwSignature
!= VS_FFI_SIGNATURE
)
296 WARN( ver
, "vffi->dwSignature is 0x%08lx, but not 0x%08lx!\n",
297 vffi
->dwSignature
, VS_FFI_SIGNATURE
);
301 if ( ((VS_VERSION_INFO_STRUCT16
*)buf
)->wLength
< len
)
302 len
= ((VS_VERSION_INFO_STRUCT16
*)buf
)->wLength
;
304 if ( TRACE_ON( ver
) )
305 print_vffi_debug( vffi
);
310 /***********************************************************************
311 * GetFileVersionInfoSize32W [VERSION.3]
313 DWORD WINAPI
GetFileVersionInfoSizeW( LPCWSTR filename
, LPDWORD handle
)
315 LPSTR fn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
316 DWORD ret
= GetFileVersionInfoSizeA( fn
, handle
);
317 HeapFree( GetProcessHeap(), 0, fn
);
321 /***********************************************************************
322 * GetFileVersionInfo32A [VERSION.1]
324 DWORD WINAPI
GetFileVersionInfoA( LPCSTR filename
, DWORD handle
,
325 DWORD datasize
, LPVOID data
)
327 TRACE( ver
, "(%s,%ld,size=%ld,data=%p)\n",
328 debugstr_a(filename
), handle
, datasize
, data
);
330 if ( !GetFileResource( filename
, MAKEINTRESOURCEA(VS_FILE_INFO
),
331 MAKEINTRESOURCEA(VS_VERSION_INFO
),
332 handle
, datasize
, data
) )
335 if ( datasize
>= sizeof(VS_VERSION_INFO_STRUCT16
)
336 && datasize
>= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
337 && !VersionInfoIs16( data
) )
339 /* convert resource from PE format to NE format */
340 ConvertVersionInfo32To16( (VS_VERSION_INFO_STRUCT32
*)data
,
341 (VS_VERSION_INFO_STRUCT16
*)data
);
347 /***********************************************************************
348 * GetFileVersionInfo32W [VERSION.4]
350 DWORD WINAPI
GetFileVersionInfoW( LPCWSTR filename
, DWORD handle
,
351 DWORD datasize
, LPVOID data
)
353 LPSTR fn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
356 TRACE( ver
, "(%s,%ld,size=%ld,data=%p)\n",
357 debugstr_a(fn
), handle
, datasize
, data
);
359 if ( !GetFileResource( fn
, MAKEINTRESOURCEA(VS_FILE_INFO
),
360 MAKEINTRESOURCEA(VS_VERSION_INFO
),
361 handle
, datasize
, data
) )
364 else if ( datasize
>= sizeof(VS_VERSION_INFO_STRUCT16
)
365 && datasize
>= ((VS_VERSION_INFO_STRUCT16
*)data
)->wLength
366 && VersionInfoIs16( data
) )
368 ERR( ver
, "Cannot access NE resource in %s\n", debugstr_a(fn
) );
372 HeapFree( GetProcessHeap(), 0, fn
);
377 /***********************************************************************
378 * VersionInfo16_FindChild [internal]
380 VS_VERSION_INFO_STRUCT16
*VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16
*info
,
381 LPCSTR szKey
, UINT cbKey
)
383 VS_VERSION_INFO_STRUCT16
*child
= VersionInfo16_Children( info
);
385 while ( (DWORD
)child
< (DWORD
)info
+ info
->wLength
)
387 if ( !lstrncmpiA( child
->szKey
, szKey
, cbKey
) )
390 if (!(child
->wLength
)) return NULL
;
391 child
= VersionInfo16_Next( child
);
397 /***********************************************************************
398 * VersionInfo32_FindChild [internal]
400 VS_VERSION_INFO_STRUCT32
*VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32
*info
,
401 LPCWSTR szKey
, UINT cbKey
)
403 VS_VERSION_INFO_STRUCT32
*child
= VersionInfo32_Children( info
);
405 while ( (DWORD
)child
< (DWORD
)info
+ info
->wLength
)
407 if ( !lstrncmpiW( child
->szKey
, szKey
, cbKey
) )
410 child
= VersionInfo32_Next( child
);
416 /***********************************************************************
417 * VerQueryValue32A [VERSION.12]
419 DWORD WINAPI
VerQueryValueA( LPVOID pBlock
, LPCSTR lpSubBlock
,
420 LPVOID
*lplpBuffer
, UINT
*puLen
)
422 VS_VERSION_INFO_STRUCT16
*info
= (VS_VERSION_INFO_STRUCT16
*)pBlock
;
423 if ( !VersionInfoIs16( info
) )
425 ERR( ver
, "called on PE resource!\n" );
429 TRACE( ver
, "(%p,%s,%p,%p)\n",
430 pBlock
, debugstr_a(lpSubBlock
), lplpBuffer
, puLen
);
432 while ( *lpSubBlock
)
434 /* Find next path component */
436 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
437 if ( *lpNextSlash
== '\\' )
440 /* Skip empty components */
441 if ( lpNextSlash
== lpSubBlock
)
447 /* We have a non-empty component: search info for key */
448 info
= VersionInfo16_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
449 if ( !info
) return FALSE
;
451 /* Skip path component */
452 lpSubBlock
= lpNextSlash
;
456 *lplpBuffer
= VersionInfo16_Value( info
);
457 *puLen
= info
->wValueLength
;
462 /***********************************************************************
463 * VerQueryValue32W [VERSION.13]
465 DWORD WINAPI
VerQueryValueW( LPVOID pBlock
, LPCWSTR lpSubBlock
,
466 LPVOID
*lplpBuffer
, UINT
*puLen
)
468 VS_VERSION_INFO_STRUCT32
*info
= (VS_VERSION_INFO_STRUCT32
*)pBlock
;
469 if ( VersionInfoIs16( info
) )
471 ERR( ver
, "called on NE resource!\n" );
475 TRACE( ver
, "(%p,%s,%p,%p)\n",
476 pBlock
, debugstr_w(lpSubBlock
), lplpBuffer
, puLen
);
478 while ( *lpSubBlock
)
480 /* Find next path component */
482 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
483 if ( *lpNextSlash
== '\\' )
486 /* Skip empty components */
487 if ( lpNextSlash
== lpSubBlock
)
493 /* We have a non-empty component: search info for key */
494 info
= VersionInfo32_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
495 if ( !info
) return FALSE
;
497 /* Skip path component */
498 lpSubBlock
= lpNextSlash
;
502 *lplpBuffer
= VersionInfo32_Value( info
);
503 *puLen
= info
->wValueLength
;
508 extern LPCSTR
WINE_GetLanguageName( UINT langid
);
510 /***********************************************************************
511 * VerLanguageName32A [VERSION.9]
513 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
519 TRACE( ver
, "(%d,%p,%d)\n", wLang
, szLang
, nSize
);
522 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
527 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
530 result
= RegQueryValueA( HKEY_LOCAL_MACHINE
, buffer
, szLang
, (LPDWORD
)&nSize
);
531 if ( result
== ERROR_SUCCESS
|| result
== ERROR_MORE_DATA
)
535 * If that fails, use the internal table
536 * (actually, Windows stores the names in a string table resource ...)
539 name
= WINE_GetLanguageName( wLang
);
540 lstrcpynA( szLang
, name
, nSize
);
541 return lstrlenA( name
);
544 /***********************************************************************
545 * VerLanguageName32W [VERSION.10]
547 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
554 TRACE( ver
, "(%d,%p,%d)\n", wLang
, szLang
, nSize
);
557 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
562 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
565 keyname
= HEAP_strdupAtoW( GetProcessHeap(), 0, buffer
);
566 result
= RegQueryValueW( HKEY_LOCAL_MACHINE
, keyname
, szLang
, (LPDWORD
)&nSize
);
567 HeapFree( GetProcessHeap(), 0, keyname
);
569 if ( result
== ERROR_SUCCESS
|| result
== ERROR_MORE_DATA
)
573 * If that fails, use the internal table
574 * (actually, Windows stores the names in a string table resource ...)
577 name
= WINE_GetLanguageName( wLang
);
578 lstrcpynAtoW( szLang
, name
, nSize
);
579 return lstrlenA( name
);