2 * Implementation of VERSION.DLL
4 * Copyright 1996,1997 Marcus Meissner
5 * Copyright 1997 David Cuthbert
6 * Copyright 1999 Ulrich Weigand
7 * Copyright 2005 Paul Vriens
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include <sys/types.h>
32 #define WIN32_NO_STATUS
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
44 #include "kernelbase.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ver
);
73 /***********************************************************************
74 * Version Info Structure
82 #if 0 /* variable length structure */
86 VS_VERSION_INFO_STRUCT16 Children
[];
88 } VS_VERSION_INFO_STRUCT16
;
94 WORD wType
; /* 1:Text, 0:Binary */
96 #if 0 /* variable length structure */
100 VS_VERSION_INFO_STRUCT32 Children
[];
102 } VS_VERSION_INFO_STRUCT32
;
104 #define VersionInfoIs16( ver ) \
105 ( ((const VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
107 #define DWORD_ALIGN( base, ptr ) \
108 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
110 #define VersionInfo16_Value( ver ) \
111 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
112 #define VersionInfo32_Value( ver ) \
113 DWORD_ALIGN( (ver), (ver)->szKey + lstrlenW((ver)->szKey) + 1 )
115 #define VersionInfo16_Children( ver ) \
116 (const VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
117 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
118 #define VersionInfo32_Children( ver ) \
119 (const VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
120 ( ( (ver)->wValueLength * \
121 ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
123 #define VersionInfo16_Next( ver ) \
124 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
125 #define VersionInfo32_Next( ver ) \
126 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
129 /***********************************************************************
130 * Win8 info, reported if app doesn't provide compat GUID in manifest.
132 static const struct version_info windows8_version_info
= { 6, 2, 0x23f0 };
135 /***********************************************************************
136 * Windows versions that need compatibility GUID specified in manifest
137 * in order to be reported by the APIs.
141 struct version_info info
;
148 {0x1f676c76,0x80e1,0x4239,{0x95,0xbb,0x83,0xd0,0xf6,0xd0,0xda,0x78}}
153 {0x8e0f7a12,0xbfb3,0x4fe8,{0xb9,0xa5,0x48,0xfd,0x50,0xa1,0x5a,0x9a}}
158 /******************************************************************************
159 * init_current_version
161 * Initialize the current_version variable.
163 * For compatibility, Windows 8.1 and later report Win8 version unless the app
164 * has a manifest that confirms its compatibility with newer versions of Windows.
167 static RTL_OSVERSIONINFOEXW current_version
;
169 static BOOL CALLBACK
init_current_version(PINIT_ONCE init_once
, PVOID parameter
, PVOID
*context
)
171 /*ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION*/DWORD
*acci
;
172 const struct version_info
*ver
;
176 current_version
.dwOSVersionInfoSize
= sizeof(current_version
);
177 if (!set_ntstatus( RtlGetVersion(¤t_version
) )) return FALSE
;
179 for (idx
= ARRAY_SIZE(version_data
); idx
--;)
180 if ( current_version
.dwMajorVersion
> version_data
[idx
].info
.major
||
181 (current_version
.dwMajorVersion
== version_data
[idx
].info
.major
&&
182 current_version
.dwMinorVersion
>= version_data
[idx
].info
.minor
))
185 if (idx
< 0) return TRUE
;
186 ver
= &windows8_version_info
;
188 if (RtlQueryInformationActivationContext(0, NtCurrentTeb()->Peb
->ActivationContextData
, NULL
,
189 CompatibilityInformationInActivationContext
, NULL
, 0, &req
) != STATUS_BUFFER_TOO_SMALL
193 if (!(acci
= HeapAlloc(GetProcessHeap(), 0, req
)))
195 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
199 if (RtlQueryInformationActivationContext(0, NtCurrentTeb()->Peb
->ActivationContextData
, NULL
,
200 CompatibilityInformationInActivationContext
, acci
, req
, &req
) == STATUS_SUCCESS
)
204 COMPATIBILITY_CONTEXT_ELEMENT
*elements
= (COMPATIBILITY_CONTEXT_ELEMENT
*)(acci
+ 1);
205 DWORD i
, count
= *acci
;
207 for (i
= 0; i
< count
; i
++)
209 if (elements
[i
].Type
== ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS
&&
210 IsEqualGUID(&elements
[i
].Id
, &version_data
[idx
].guid
))
212 ver
= &version_data
[idx
].info
;
214 if (ver
->major
== current_version
.dwMajorVersion
&&
215 ver
->minor
== current_version
.dwMinorVersion
)
218 idx
= 0; /* break from outer loop */
224 HeapFree(GetProcessHeap(), 0, acci
);
229 current_version
.dwMajorVersion
= ver
->major
;
230 current_version
.dwMinorVersion
= ver
->minor
;
231 current_version
.dwBuildNumber
= ver
->build
;
237 /**********************************************************************
240 * Find an entry by id in a resource directory
241 * Copied from loader/pe_resource.c
243 static const IMAGE_RESOURCE_DIRECTORY
*find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY
*dir
,
244 WORD id
, const void *root
,
247 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*entry
;
250 entry
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(dir
+ 1);
251 min
= dir
->NumberOfNamedEntries
;
252 max
= min
+ dir
->NumberOfIdEntries
- 1;
254 if (max
>= (root_size
- ((INT_PTR
)dir
- (INT_PTR
)root
) - sizeof(*dir
)) / sizeof(*entry
))
259 pos
= (min
+ max
) / 2;
260 if (entry
[pos
].u
.Id
== id
)
262 DWORD offset
= entry
[pos
].u2
.s2
.OffsetToDirectory
;
263 if (offset
> root_size
- sizeof(*dir
)) return NULL
;
264 return (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ offset
);
266 if (entry
[pos
].u
.Id
> id
) max
= pos
- 1;
273 /**********************************************************************
276 * Find a default entry in a resource directory
277 * Copied from loader/pe_resource.c
279 static const IMAGE_RESOURCE_DIRECTORY
*find_entry_default( const IMAGE_RESOURCE_DIRECTORY
*dir
,
282 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*entry
;
284 entry
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(dir
+ 1);
285 return (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ entry
->u2
.s2
.OffsetToDirectory
);
289 /**********************************************************************
292 * push a language onto the list of languages to try
294 static inline int push_language( WORD
*list
, int pos
, WORD lang
)
297 for (i
= 0; i
< pos
; i
++) if (list
[i
] == lang
) return pos
;
303 /**********************************************************************
304 * find_entry_language
306 static const IMAGE_RESOURCE_DIRECTORY
*find_entry_language( const IMAGE_RESOURCE_DIRECTORY
*dir
,
307 const void *root
, DWORD root_size
,
310 const IMAGE_RESOURCE_DIRECTORY
*ret
;
314 if (flags
& FILE_VER_GET_LOCALISED
)
316 /* cf. LdrFindResource_U */
317 pos
= push_language( list
, pos
, MAKELANGID( LANG_NEUTRAL
, SUBLANG_NEUTRAL
) );
318 pos
= push_language( list
, pos
, LANGIDFROMLCID( NtCurrentTeb()->CurrentLocale
) );
319 pos
= push_language( list
, pos
, GetUserDefaultLangID() );
320 pos
= push_language( list
, pos
, MAKELANGID( PRIMARYLANGID(GetUserDefaultLangID()), SUBLANG_NEUTRAL
));
321 pos
= push_language( list
, pos
, MAKELANGID( PRIMARYLANGID(GetUserDefaultLangID()), SUBLANG_DEFAULT
));
322 pos
= push_language( list
, pos
, GetSystemDefaultLangID() );
323 pos
= push_language( list
, pos
, MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_NEUTRAL
));
324 pos
= push_language( list
, pos
, MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_DEFAULT
));
325 pos
= push_language( list
, pos
, MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
) );
329 /* FIXME: resolve LN file here */
330 pos
= push_language( list
, pos
, MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
) );
333 for (i
= 0; i
< pos
; i
++) if ((ret
= find_entry_by_id( dir
, list
[i
], root
, root_size
))) return ret
;
334 return find_entry_default( dir
, root
);
338 static DWORD
read_data( HANDLE handle
, DWORD offset
, void *data
, DWORD len
)
342 SetFilePointer( handle
, offset
, NULL
, FILE_BEGIN
);
343 if (!ReadFile( handle
, data
, len
, &res
, NULL
)) res
= 0;
347 /***********************************************************************
348 * find_ne_resource [internal]
350 static BOOL
find_ne_resource( HANDLE handle
, DWORD
*resLen
, DWORD
*resOff
)
352 const WORD
typeid = VS_FILE_INFO
| 0x8000;
353 const WORD resid
= VS_VERSION_INFO
| 0x8000;
354 IMAGE_OS2_HEADER nehd
;
355 NE_TYPEINFO
*typeInfo
;
356 NE_NAMEINFO
*nameInfo
;
357 DWORD nehdoffset
= *resOff
;
362 /* Read in NE header */
363 if (read_data( handle
, nehdoffset
, &nehd
, sizeof(nehd
) ) != sizeof(nehd
)) return FALSE
;
365 resTabSize
= nehd
.ne_restab
- nehd
.ne_rsrctab
;
368 TRACE("No resources in NE dll\n" );
372 /* Read in resource table */
373 resTab
= HeapAlloc( GetProcessHeap(), 0, resTabSize
);
374 if ( !resTab
) return FALSE
;
376 if (read_data( handle
, nehd
.ne_rsrctab
+ nehdoffset
, resTab
, resTabSize
) != resTabSize
)
378 HeapFree( GetProcessHeap(), 0, resTab
);
383 typeInfo
= (NE_TYPEINFO
*)(resTab
+ 2);
384 while (typeInfo
->type_id
)
386 if (typeInfo
->type_id
== typeid) goto found_type
;
387 typeInfo
= (NE_TYPEINFO
*)((char *)(typeInfo
+ 1) +
388 typeInfo
->count
* sizeof(NE_NAMEINFO
));
390 TRACE("No typeid entry found\n" );
391 HeapFree( GetProcessHeap(), 0, resTab
);
395 nameInfo
= (NE_NAMEINFO
*)(typeInfo
+ 1);
397 for (count
= typeInfo
->count
; count
> 0; count
--, nameInfo
++)
398 if (nameInfo
->id
== resid
) goto found_name
;
400 TRACE("No resid entry found\n" );
401 HeapFree( GetProcessHeap(), 0, resTab
);
405 /* Return resource data */
406 *resLen
= nameInfo
->length
<< *(WORD
*)resTab
;
407 *resOff
= nameInfo
->offset
<< *(WORD
*)resTab
;
409 HeapFree( GetProcessHeap(), 0, resTab
);
413 /***********************************************************************
414 * find_pe_resource [internal]
416 static BOOL
find_pe_resource( HANDLE handle
, DWORD
*resLen
, DWORD
*resOff
, DWORD flags
)
420 IMAGE_NT_HEADERS32 nt32
;
421 IMAGE_NT_HEADERS64 nt64
;
423 DWORD pehdoffset
= *resOff
;
424 PIMAGE_DATA_DIRECTORY resDataDir
;
425 PIMAGE_SECTION_HEADER sections
;
427 DWORD len
, section_size
, data_size
, resDirSize
;
429 const IMAGE_RESOURCE_DIRECTORY
*resPtr
;
430 const IMAGE_RESOURCE_DATA_ENTRY
*resData
;
434 /* Read in PE header */
435 len
= read_data( handle
, pehdoffset
, &pehd
, sizeof(pehd
) );
436 if (len
< sizeof(pehd
.nt32
.FileHeader
)) return FALSE
;
437 if (len
< sizeof(pehd
)) memset( (char *)&pehd
+ len
, 0, sizeof(pehd
) - len
);
439 switch (pehd
.nt32
.OptionalHeader
.Magic
)
441 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
442 resDataDir
= pehd
.nt32
.OptionalHeader
.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_RESOURCE
;
444 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
445 resDataDir
= pehd
.nt64
.OptionalHeader
.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_RESOURCE
;
451 if ( !resDataDir
->Size
)
453 TRACE("No resources in PE dll\n" );
457 /* Read in section table */
458 nSections
= pehd
.nt32
.FileHeader
.NumberOfSections
;
459 sections
= HeapAlloc( GetProcessHeap(), 0,
460 nSections
* sizeof(IMAGE_SECTION_HEADER
) );
461 if ( !sections
) return FALSE
;
463 len
= FIELD_OFFSET( IMAGE_NT_HEADERS32
, OptionalHeader
) + pehd
.nt32
.FileHeader
.SizeOfOptionalHeader
;
464 if (read_data( handle
, pehdoffset
+ len
, sections
, nSections
* sizeof(IMAGE_SECTION_HEADER
) ) !=
465 nSections
* sizeof(IMAGE_SECTION_HEADER
))
467 HeapFree( GetProcessHeap(), 0, sections
);
471 /* Find resource section */
472 for ( i
= 0; i
< nSections
; i
++ )
473 if ( resDataDir
->VirtualAddress
>= sections
[i
].VirtualAddress
474 && resDataDir
->VirtualAddress
< sections
[i
].VirtualAddress
+
475 sections
[i
].SizeOfRawData
)
478 if ( i
== nSections
)
480 HeapFree( GetProcessHeap(), 0, sections
);
481 TRACE("Couldn't find resource section\n" );
485 /* Read in resource section */
486 data_size
= sections
[i
].SizeOfRawData
;
487 section_size
= max( data_size
, sections
[i
].Misc
.VirtualSize
);
488 resSection
= HeapAlloc( GetProcessHeap(), 0, section_size
);
491 HeapFree( GetProcessHeap(), 0, sections
);
495 if (read_data( handle
, sections
[i
].PointerToRawData
, resSection
, data_size
) != data_size
) goto done
;
496 if (data_size
< section_size
) memset( (char *)resSection
+ data_size
, 0, section_size
- data_size
);
499 resDir
= resSection
+ (resDataDir
->VirtualAddress
- sections
[i
].VirtualAddress
);
500 resDirSize
= section_size
- (resDataDir
->VirtualAddress
- sections
[i
].VirtualAddress
);
503 resPtr
= find_entry_by_id( resPtr
, VS_FILE_INFO
, resDir
, resDirSize
);
506 TRACE("No typeid entry found\n" );
509 resPtr
= find_entry_by_id( resPtr
, VS_VERSION_INFO
, resDir
, resDirSize
);
512 TRACE("No resid entry found\n" );
515 resPtr
= find_entry_language( resPtr
, resDir
, resDirSize
, flags
);
518 TRACE("No default language entry found\n" );
522 /* Find resource data section */
523 resData
= (const IMAGE_RESOURCE_DATA_ENTRY
*)resPtr
;
524 for ( i
= 0; i
< nSections
; i
++ )
525 if ( resData
->OffsetToData
>= sections
[i
].VirtualAddress
526 && resData
->OffsetToData
< sections
[i
].VirtualAddress
+
527 sections
[i
].SizeOfRawData
)
530 if ( i
== nSections
)
532 TRACE("Couldn't find resource data section\n" );
536 /* Return resource data */
537 *resLen
= resData
->Size
;
538 *resOff
= resData
->OffsetToData
- sections
[i
].VirtualAddress
+ sections
[i
].PointerToRawData
;
542 HeapFree( GetProcessHeap(), 0, resSection
);
543 HeapFree( GetProcessHeap(), 0, sections
);
548 /***********************************************************************
549 * find_version_resource [internal]
551 static DWORD
find_version_resource( HANDLE handle
, DWORD
*reslen
, DWORD
*offset
, DWORD flags
)
553 IMAGE_DOS_HEADER mzh
;
556 if (read_data( handle
, 0, &mzh
, sizeof(mzh
) ) != sizeof(mzh
)) return 0;
557 if (mzh
.e_magic
!= IMAGE_DOS_SIGNATURE
) return 0;
559 if (read_data( handle
, mzh
.e_lfanew
, &magic
, sizeof(magic
) ) != sizeof(magic
)) return 0;
560 *offset
= mzh
.e_lfanew
;
564 case IMAGE_OS2_SIGNATURE
:
565 if (!find_ne_resource( handle
, reslen
, offset
)) magic
= 0;
567 case IMAGE_NT_SIGNATURE
:
568 if (!find_pe_resource( handle
, reslen
, offset
, flags
)) magic
= 0;
571 WARN( "Can't handle %04x files.\n", magic
);
575 /******************************************************************************
576 * This function will print via standard TRACE, debug info regarding
577 * the file info structure vffi.
579 static void print_vffi_debug(const VS_FIXEDFILEINFO
*vffi
)
581 BOOL versioned_printer
= FALSE
;
583 if((vffi
->dwFileType
== VFT_DLL
) || (vffi
->dwFileType
== VFT_DRV
))
585 if(vffi
->dwFileSubtype
== VFT2_DRV_VERSIONED_PRINTER
)
586 /* this is documented for newer w2k Drivers and up */
587 versioned_printer
= TRUE
;
588 else if( (vffi
->dwFileSubtype
== VFT2_DRV_PRINTER
) &&
589 (vffi
->dwFileVersionMS
!= vffi
->dwProductVersionMS
) &&
590 (vffi
->dwFileVersionMS
> 0) &&
591 (vffi
->dwFileVersionMS
<= 3) )
592 /* found this on NT 3.51, NT4.0 and old w2k Drivers */
593 versioned_printer
= TRUE
;
596 TRACE("structversion=%u.%u, ",
597 HIWORD(vffi
->dwStrucVersion
),LOWORD(vffi
->dwStrucVersion
));
598 if(versioned_printer
)
600 WORD mode
= LOWORD(vffi
->dwFileVersionMS
);
601 WORD ver_rev
= HIWORD(vffi
->dwFileVersionLS
);
602 TRACE("fileversion=%u.%u.%u.%u (%s.major.minor.release), ",
603 (vffi
->dwFileVersionMS
),
604 HIBYTE(ver_rev
), LOBYTE(ver_rev
), LOWORD(vffi
->dwFileVersionLS
),
605 (mode
== 3) ? "Usermode" : ((mode
<= 2) ? "Kernelmode" : "?") );
609 TRACE("fileversion=%u.%u.%u.%u, ",
610 HIWORD(vffi
->dwFileVersionMS
),LOWORD(vffi
->dwFileVersionMS
),
611 HIWORD(vffi
->dwFileVersionLS
),LOWORD(vffi
->dwFileVersionLS
));
613 TRACE("productversion=%u.%u.%u.%u\n",
614 HIWORD(vffi
->dwProductVersionMS
),LOWORD(vffi
->dwProductVersionMS
),
615 HIWORD(vffi
->dwProductVersionLS
),LOWORD(vffi
->dwProductVersionLS
));
617 TRACE("flagmask=0x%x, flags=0x%x %s%s%s%s%s%s\n",
618 vffi
->dwFileFlagsMask
, vffi
->dwFileFlags
,
619 (vffi
->dwFileFlags
& VS_FF_DEBUG
) ? "DEBUG," : "",
620 (vffi
->dwFileFlags
& VS_FF_PRERELEASE
) ? "PRERELEASE," : "",
621 (vffi
->dwFileFlags
& VS_FF_PATCHED
) ? "PATCHED," : "",
622 (vffi
->dwFileFlags
& VS_FF_PRIVATEBUILD
) ? "PRIVATEBUILD," : "",
623 (vffi
->dwFileFlags
& VS_FF_INFOINFERRED
) ? "INFOINFERRED," : "",
624 (vffi
->dwFileFlags
& VS_FF_SPECIALBUILD
) ? "SPECIALBUILD," : "");
628 TRACE("OS=0x%x.0x%x ", HIWORD(vffi
->dwFileOS
), LOWORD(vffi
->dwFileOS
));
630 switch (vffi
->dwFileOS
&0xFFFF0000)
632 case VOS_DOS
:TRACE("DOS,");break;
633 case VOS_OS216
:TRACE("OS/2-16,");break;
634 case VOS_OS232
:TRACE("OS/2-32,");break;
635 case VOS_NT
:TRACE("NT,");break;
638 TRACE("UNKNOWN(0x%x),",vffi
->dwFileOS
&0xFFFF0000);break;
641 switch (LOWORD(vffi
->dwFileOS
))
643 case VOS__BASE
:TRACE("BASE");break;
644 case VOS__WINDOWS16
:TRACE("WIN16");break;
645 case VOS__WINDOWS32
:TRACE("WIN32");break;
646 case VOS__PM16
:TRACE("PM16");break;
647 case VOS__PM32
:TRACE("PM32");break;
649 TRACE("UNKNOWN(0x%x)",LOWORD(vffi
->dwFileOS
));break;
654 switch (vffi
->dwFileType
)
656 case VFT_APP
:TRACE("filetype=APP");break;
658 TRACE("filetype=DLL");
659 if(vffi
->dwFileSubtype
!= 0)
661 if(versioned_printer
) /* NT3.x/NT4.0 or old w2k Driver */
663 TRACE(" (subtype=0x%x)", vffi
->dwFileSubtype
);
667 TRACE("filetype=DRV,");
668 switch(vffi
->dwFileSubtype
)
670 case VFT2_DRV_PRINTER
:TRACE("PRINTER");break;
671 case VFT2_DRV_KEYBOARD
:TRACE("KEYBOARD");break;
672 case VFT2_DRV_LANGUAGE
:TRACE("LANGUAGE");break;
673 case VFT2_DRV_DISPLAY
:TRACE("DISPLAY");break;
674 case VFT2_DRV_MOUSE
:TRACE("MOUSE");break;
675 case VFT2_DRV_NETWORK
:TRACE("NETWORK");break;
676 case VFT2_DRV_SYSTEM
:TRACE("SYSTEM");break;
677 case VFT2_DRV_INSTALLABLE
:TRACE("INSTALLABLE");break;
678 case VFT2_DRV_SOUND
:TRACE("SOUND");break;
679 case VFT2_DRV_COMM
:TRACE("COMM");break;
680 case VFT2_DRV_INPUTMETHOD
:TRACE("INPUTMETHOD");break;
681 case VFT2_DRV_VERSIONED_PRINTER
:TRACE("VERSIONED_PRINTER");break;
684 TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
688 TRACE("filetype=FONT,");
689 switch (vffi
->dwFileSubtype
)
691 case VFT2_FONT_RASTER
:TRACE("RASTER");break;
692 case VFT2_FONT_VECTOR
:TRACE("VECTOR");break;
693 case VFT2_FONT_TRUETYPE
:TRACE("TRUETYPE");break;
694 default:TRACE("UNKNOWN(0x%x)",vffi
->dwFileSubtype
);break;
697 case VFT_VXD
:TRACE("filetype=VXD");break;
698 case VFT_STATIC_LIB
:TRACE("filetype=STATIC_LIB");break;
701 TRACE("filetype=Unknown(0x%x)",vffi
->dwFileType
);break;
705 TRACE("filedate=0x%x.0x%x\n",vffi
->dwFileDateMS
,vffi
->dwFileDateLS
);
708 /***********************************************************************
709 * GetFileVersionInfoSizeW (kernelbase.@)
711 DWORD WINAPI
GetFileVersionInfoSizeW( LPCWSTR filename
, LPDWORD handle
)
713 return GetFileVersionInfoSizeExW( FILE_VER_GET_LOCALISED
, filename
, handle
);
716 /***********************************************************************
717 * GetFileVersionInfoSizeA (kernelbase.@)
719 DWORD WINAPI
GetFileVersionInfoSizeA( LPCSTR filename
, LPDWORD handle
)
721 return GetFileVersionInfoSizeExA( FILE_VER_GET_LOCALISED
, filename
, handle
);
724 /******************************************************************************
725 * GetFileVersionInfoSizeExW (kernelbase.@)
727 DWORD WINAPI
GetFileVersionInfoSizeExW( DWORD flags
, LPCWSTR filename
, LPDWORD ret_handle
)
729 DWORD len
, offset
, magic
= 1;
732 TRACE("(0x%x,%s,%p)\n", flags
, debugstr_w(filename
), ret_handle
);
734 if (ret_handle
) *ret_handle
= 0;
738 SetLastError(ERROR_INVALID_PARAMETER
);
743 SetLastError(ERROR_BAD_PATHNAME
);
746 if (flags
& ~FILE_VER_GET_LOCALISED
)
747 FIXME("flags 0x%x ignored\n", flags
& ~FILE_VER_GET_LOCALISED
);
749 if ((hModule
= LoadLibraryExW( filename
, 0, LOAD_LIBRARY_AS_DATAFILE
)))
752 if (!(flags
& FILE_VER_GET_LOCALISED
))
754 LANGID english
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
755 hRsrc
= FindResourceExW( hModule
, MAKEINTRESOURCEW(VS_VERSION_INFO
),
756 (LPWSTR
)VS_FILE_INFO
, english
);
759 hRsrc
= FindResourceW( hModule
, MAKEINTRESOURCEW(VS_VERSION_INFO
),
760 (LPWSTR
)VS_FILE_INFO
);
763 magic
= IMAGE_NT_SIGNATURE
;
764 len
= SizeofResource( hModule
, hRsrc
);
766 FreeLibrary( hModule
);
771 HANDLE handle
= CreateFileW( filename
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
772 NULL
, OPEN_EXISTING
, 0, 0 );
773 if (handle
== INVALID_HANDLE_VALUE
) return 0;
774 magic
= find_version_resource( handle
, &len
, &offset
, flags
);
775 CloseHandle( handle
);
780 case IMAGE_OS2_SIGNATURE
:
781 /* We have a 16bit resource.
783 * XP/W2K/W2K3 uses a buffer which is more than the actual needed space:
785 * (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4
787 * This extra buffer is used for ANSI to Unicode conversions in W-Calls.
788 * info->wLength should be the same as len. Currently it isn't but that
789 * doesn't seem to be a problem (len is bigger than info->wLength).
792 return (len
- sizeof(VS_FIXEDFILEINFO
)) * 4;
794 case IMAGE_NT_SIGNATURE
:
795 /* We have a 32bit resource.
797 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
798 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
801 return (len
* 2) + 4;
804 if (GetVersion() & 0x80000000) /* Windows 95/98 */
805 SetLastError(ERROR_FILE_NOT_FOUND
);
807 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND
);
812 /******************************************************************************
813 * GetFileVersionInfoSizeExA (kernelbase.@)
815 DWORD WINAPI
GetFileVersionInfoSizeExA( DWORD flags
, LPCSTR filename
, LPDWORD handle
)
817 UNICODE_STRING filenameW
;
820 TRACE("(0x%x,%s,%p)\n", flags
, debugstr_a(filename
), handle
);
823 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
825 filenameW
.Buffer
= NULL
;
827 retval
= GetFileVersionInfoSizeExW(flags
, filenameW
.Buffer
, handle
);
829 RtlFreeUnicodeString(&filenameW
);
834 /***********************************************************************
835 * GetFileVersionInfoExW (kernelbase.@)
837 BOOL WINAPI
GetFileVersionInfoExW( DWORD flags
, LPCWSTR filename
, DWORD ignored
, DWORD datasize
, LPVOID data
)
839 static const char signature
[4] = "FE2X";
840 DWORD len
, offset
, magic
= 1;
842 VS_VERSION_INFO_STRUCT32
* vvis
= data
;
844 TRACE("(0x%x,%s,%d,size=%d,data=%p)\n",
845 flags
, debugstr_w(filename
), ignored
, datasize
, data
);
849 SetLastError(ERROR_INVALID_DATA
);
852 if (flags
& ~FILE_VER_GET_LOCALISED
)
853 FIXME("flags 0x%x ignored\n", flags
& ~FILE_VER_GET_LOCALISED
);
855 if ((hModule
= LoadLibraryExW( filename
, 0, LOAD_LIBRARY_AS_DATAFILE
)))
858 if (!(flags
& FILE_VER_GET_LOCALISED
))
860 LANGID english
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
861 hRsrc
= FindResourceExW( hModule
, MAKEINTRESOURCEW(VS_VERSION_INFO
),
862 (LPWSTR
)VS_FILE_INFO
, english
);
865 hRsrc
= FindResourceW( hModule
, MAKEINTRESOURCEW(VS_VERSION_INFO
),
866 (LPWSTR
)VS_FILE_INFO
);
869 HGLOBAL hMem
= LoadResource( hModule
, hRsrc
);
870 magic
= IMAGE_NT_SIGNATURE
;
871 len
= min( SizeofResource(hModule
, hRsrc
), datasize
);
872 memcpy( data
, LockResource( hMem
), len
);
873 FreeResource( hMem
);
875 FreeLibrary( hModule
);
880 HANDLE handle
= CreateFileW( filename
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
881 NULL
, OPEN_EXISTING
, 0, 0 );
882 if (handle
== INVALID_HANDLE_VALUE
) return 0;
883 if ((magic
= find_version_resource( handle
, &len
, &offset
, flags
)))
884 len
= read_data( handle
, offset
, data
, min( len
, datasize
));
885 CloseHandle( handle
);
890 case IMAGE_OS2_SIGNATURE
:
891 /* We have a 16bit resource. */
893 print_vffi_debug( (VS_FIXEDFILEINFO
*)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16
*)data
));
897 case IMAGE_NT_SIGNATURE
:
898 /* We have a 32bit resource.
900 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
901 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
903 len
= vvis
->wLength
+ sizeof(signature
);
904 if (datasize
>= len
) memcpy( (char*)data
+ vvis
->wLength
, signature
, sizeof(signature
) );
906 print_vffi_debug( (VS_FIXEDFILEINFO
*)VersionInfo32_Value( vvis
));
911 SetLastError( ERROR_RESOURCE_DATA_NOT_FOUND
);
916 /***********************************************************************
917 * GetFileVersionInfoExA (kernelbase.@)
919 BOOL WINAPI
GetFileVersionInfoExA( DWORD flags
, LPCSTR filename
, DWORD handle
, DWORD datasize
, LPVOID data
)
921 UNICODE_STRING filenameW
;
924 TRACE("(0x%x,%s,%d,size=%d,data=%p)\n",
925 flags
, debugstr_a(filename
), handle
, datasize
, data
);
928 RtlCreateUnicodeStringFromAsciiz(&filenameW
, filename
);
930 filenameW
.Buffer
= NULL
;
932 retval
= GetFileVersionInfoExW(flags
, filenameW
.Buffer
, handle
, datasize
, data
);
934 RtlFreeUnicodeString(&filenameW
);
939 /***********************************************************************
940 * GetFileVersionInfoW (kernelbase.@)
942 BOOL WINAPI
GetFileVersionInfoW( LPCWSTR filename
, DWORD handle
, DWORD datasize
, LPVOID data
)
944 return GetFileVersionInfoExW(FILE_VER_GET_LOCALISED
, filename
, handle
, datasize
, data
);
947 /***********************************************************************
948 * GetFileVersionInfoA (kernelbase.@)
950 BOOL WINAPI
GetFileVersionInfoA( LPCSTR filename
, DWORD handle
, DWORD datasize
, LPVOID data
)
952 return GetFileVersionInfoExA(FILE_VER_GET_LOCALISED
, filename
, handle
, datasize
, data
);
955 /***********************************************************************
956 * VersionInfo16_FindChild [internal]
958 static const VS_VERSION_INFO_STRUCT16
*VersionInfo16_FindChild( const VS_VERSION_INFO_STRUCT16
*info
,
959 LPCSTR key
, UINT len
)
961 const VS_VERSION_INFO_STRUCT16
*child
= VersionInfo16_Children( info
);
963 while ((char *)child
< (char *)info
+ info
->wLength
)
965 if (!strnicmp( child
->szKey
, key
, len
) && !child
->szKey
[len
])
968 if (!(child
->wLength
)) return NULL
;
969 child
= VersionInfo16_Next( child
);
975 /***********************************************************************
976 * VersionInfo32_FindChild [internal]
978 static const VS_VERSION_INFO_STRUCT32
*VersionInfo32_FindChild( const VS_VERSION_INFO_STRUCT32
*info
,
979 LPCWSTR key
, UINT len
)
981 const VS_VERSION_INFO_STRUCT32
*child
= VersionInfo32_Children( info
);
983 while ((char *)child
< (char *)info
+ info
->wLength
)
985 if (!wcsnicmp( child
->szKey
, key
, len
) && !child
->szKey
[len
])
988 if (!(child
->wLength
)) return NULL
;
989 child
= VersionInfo32_Next( child
);
995 /***********************************************************************
996 * VersionInfo16_QueryValue [internal]
998 * Gets a value from a 16-bit NE resource
1000 static BOOL
VersionInfo16_QueryValue( const VS_VERSION_INFO_STRUCT16
*info
, LPCSTR lpSubBlock
,
1001 LPVOID
*lplpBuffer
, UINT
*puLen
)
1003 while ( *lpSubBlock
)
1005 /* Find next path component */
1007 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
1008 if ( *lpNextSlash
== '\\' )
1011 /* Skip empty components */
1012 if ( lpNextSlash
== lpSubBlock
)
1018 /* We have a non-empty component: search info for key */
1019 info
= VersionInfo16_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
1022 if (puLen
) *puLen
= 0 ;
1023 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
1027 /* Skip path component */
1028 lpSubBlock
= lpNextSlash
;
1032 *lplpBuffer
= VersionInfo16_Value( info
);
1034 *puLen
= info
->wValueLength
;
1039 /***********************************************************************
1040 * VersionInfo32_QueryValue [internal]
1042 * Gets a value from a 32-bit PE resource
1044 static BOOL
VersionInfo32_QueryValue( const VS_VERSION_INFO_STRUCT32
*info
, LPCWSTR lpSubBlock
,
1045 LPVOID
*lplpBuffer
, UINT
*puLen
, BOOL
*pbText
)
1047 TRACE("lpSubBlock : (%s)\n", debugstr_w(lpSubBlock
));
1049 while ( *lpSubBlock
)
1051 /* Find next path component */
1052 LPCWSTR lpNextSlash
;
1053 for ( lpNextSlash
= lpSubBlock
; *lpNextSlash
; lpNextSlash
++ )
1054 if ( *lpNextSlash
== '\\' )
1057 /* Skip empty components */
1058 if ( lpNextSlash
== lpSubBlock
)
1064 /* We have a non-empty component: search info for key */
1065 info
= VersionInfo32_FindChild( info
, lpSubBlock
, lpNextSlash
-lpSubBlock
);
1068 if (puLen
) *puLen
= 0 ;
1069 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND
);
1073 /* Skip path component */
1074 lpSubBlock
= lpNextSlash
;
1078 *lplpBuffer
= VersionInfo32_Value( info
);
1080 *puLen
= info
->wValueLength
;
1082 *pbText
= info
->wType
;
1087 /***********************************************************************
1088 * VerQueryValueA (kernelbase.@)
1090 BOOL WINAPI
VerQueryValueA( LPCVOID pBlock
, LPCSTR lpSubBlock
,
1091 LPVOID
*lplpBuffer
, PUINT puLen
)
1093 static const char rootA
[] = "\\";
1094 const VS_VERSION_INFO_STRUCT16
*info
= pBlock
;
1096 TRACE("(%p,%s,%p,%p)\n",
1097 pBlock
, debugstr_a(lpSubBlock
), lplpBuffer
, puLen
);
1102 if (lpSubBlock
== NULL
|| lpSubBlock
[0] == '\0')
1105 if ( !VersionInfoIs16( info
) )
1112 len
= MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0);
1113 lpSubBlockW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1118 MultiByteToWideChar(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockW
, len
);
1120 ret
= VersionInfo32_QueryValue(pBlock
, lpSubBlockW
, lplpBuffer
, &value_len
, &isText
);
1121 if (puLen
) *puLen
= value_len
;
1123 HeapFree(GetProcessHeap(), 0, lpSubBlockW
);
1127 /* Set lpBuffer so it points to the 'empty' area where we store
1128 * the converted strings
1130 LPSTR lpBufferA
= (LPSTR
)pBlock
+ info
->wLength
+ 4;
1131 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
1132 len
= WideCharToMultiByte(CP_ACP
, 0, *lplpBuffer
, value_len
,
1133 lpBufferA
+ pos
, info
->wLength
- pos
, NULL
, NULL
);
1134 *lplpBuffer
= lpBufferA
+ pos
;
1135 if (puLen
) *puLen
= len
;
1140 return VersionInfo16_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
);
1143 /***********************************************************************
1144 * VerQueryValueW (kernelbase.@)
1146 BOOL WINAPI
VerQueryValueW( LPCVOID pBlock
, LPCWSTR lpSubBlock
,
1147 LPVOID
*lplpBuffer
, PUINT puLen
)
1149 const VS_VERSION_INFO_STRUCT32
*info
= pBlock
;
1151 TRACE("(%p,%s,%p,%p)\n",
1152 pBlock
, debugstr_w(lpSubBlock
), lplpBuffer
, puLen
);
1157 if (!lpSubBlock
|| !lpSubBlock
[0])
1160 if ( VersionInfoIs16( info
) )
1166 len
= WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, NULL
, 0, NULL
, NULL
);
1167 lpSubBlockA
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
1172 WideCharToMultiByte(CP_ACP
, 0, lpSubBlock
, -1, lpSubBlockA
, len
, NULL
, NULL
);
1174 ret
= VersionInfo16_QueryValue(pBlock
, lpSubBlockA
, lplpBuffer
, puLen
);
1176 HeapFree(GetProcessHeap(), 0, lpSubBlockA
);
1178 if (ret
&& wcscmp( lpSubBlock
, L
"\\" ) && wcsicmp( lpSubBlock
, L
"\\VarFileInfo\\Translation" ))
1180 /* Set lpBuffer so it points to the 'empty' area where we store
1181 * the converted strings
1183 LPWSTR lpBufferW
= (LPWSTR
)((LPSTR
)pBlock
+ info
->wLength
);
1184 DWORD pos
= (LPCSTR
)*lplpBuffer
- (LPCSTR
)pBlock
;
1185 DWORD max
= (info
->wLength
- sizeof(VS_FIXEDFILEINFO
)) * 4 - info
->wLength
;
1187 len
= MultiByteToWideChar(CP_ACP
, 0, *lplpBuffer
, -1,
1188 lpBufferW
+ pos
, max
/sizeof(WCHAR
) - pos
);
1189 *lplpBuffer
= lpBufferW
+ pos
;
1190 if (puLen
) *puLen
= len
;
1195 return VersionInfo32_QueryValue(info
, lpSubBlock
, lplpBuffer
, puLen
, NULL
);
1199 /******************************************************************************
1202 static BOOL
file_existsA( char const * path
, char const * file
, BOOL excl
)
1204 DWORD sharing
= excl
? 0 : FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1205 char filename
[MAX_PATH
];
1211 strcpy( filename
, path
);
1212 len
= strlen(filename
);
1213 if (len
&& filename
[len
- 1] != '\\') strcat( filename
, "\\" );
1214 strcat( filename
, file
);
1216 else if (!SearchPathA( NULL
, file
, NULL
, MAX_PATH
, filename
, NULL
)) return FALSE
;
1218 handle
= CreateFileA( filename
, 0, sharing
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0 );
1219 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
1220 CloseHandle( handle
);
1224 /******************************************************************************
1227 static BOOL
file_existsW( const WCHAR
*path
, const WCHAR
*file
, BOOL excl
)
1229 DWORD sharing
= excl
? 0 : FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1230 WCHAR filename
[MAX_PATH
];
1236 lstrcpyW( filename
, path
);
1237 len
= lstrlenW(filename
);
1238 if (len
&& filename
[len
- 1] != '\\') lstrcatW( filename
, L
"\\" );
1239 lstrcatW( filename
, file
);
1241 else if (!SearchPathW( NULL
, file
, NULL
, MAX_PATH
, filename
, NULL
)) return FALSE
;
1243 handle
= CreateFileW( filename
, 0, sharing
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0 );
1244 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
1245 CloseHandle( handle
);
1249 /*****************************************************************************
1250 * VerFindFileA (kernelbase.@)
1252 * Determines where to install a file based on whether it locates another
1253 * version of the file in the system. The values VerFindFile returns are
1254 * used in a subsequent call to the VerInstallFile function.
1256 DWORD WINAPI
VerFindFileA( DWORD flags
, LPCSTR filename
, LPCSTR win_dir
, LPCSTR app_dir
,
1257 LPSTR cur_dir
, PUINT curdir_len
, LPSTR dest
, PUINT dest_len
)
1261 const char *destDir
;
1262 char winDir
[MAX_PATH
], systemDir
[MAX_PATH
];
1264 TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
1265 flags
, debugstr_a(filename
), debugstr_a(win_dir
), debugstr_a(app_dir
),
1266 curdir_len
, curdir_len
? *curdir_len
: 0, dest_len
, dest_len
? *dest_len
: 0 );
1268 /* Figure out where the file should go; shared files default to the
1271 GetSystemDirectoryA(systemDir
, sizeof(systemDir
));
1274 if(flags
& VFFF_ISSHAREDFILE
)
1276 destDir
= systemDir
;
1277 /* Were we given a filename? If so, try to find the file. */
1280 if(file_existsA(destDir
, filename
, FALSE
)) curDir
= destDir
;
1281 else if(app_dir
&& file_existsA(app_dir
, filename
, FALSE
))
1284 if(!file_existsA(systemDir
, filename
, FALSE
))
1285 retval
|= VFF_CURNEDEST
;
1288 else /* not a shared file */
1290 destDir
= app_dir
? app_dir
: "";
1293 GetWindowsDirectoryA( winDir
, MAX_PATH
);
1294 if(file_existsA(destDir
, filename
, FALSE
)) curDir
= destDir
;
1295 else if(file_existsA(winDir
, filename
, FALSE
))
1297 else if(file_existsA(systemDir
, filename
, FALSE
))
1300 if (app_dir
&& app_dir
[0])
1302 if(!file_existsA(app_dir
, filename
, FALSE
))
1303 retval
|= VFF_CURNEDEST
;
1305 else if(file_existsA(NULL
, filename
, FALSE
))
1306 retval
|= VFF_CURNEDEST
;
1310 /* Check to see if the file exists and is in use by another application */
1311 if (filename
&& file_existsA(curDir
, filename
, FALSE
))
1313 if (filename
&& !file_existsA(curDir
, filename
, TRUE
))
1314 retval
|= VFF_FILEINUSE
;
1317 if (dest_len
&& dest
)
1319 UINT len
= strlen(destDir
) + 1;
1320 if (*dest_len
< len
) retval
|= VFF_BUFFTOOSMALL
;
1321 lstrcpynA(dest
, destDir
, *dest_len
);
1324 if (curdir_len
&& cur_dir
)
1326 UINT len
= strlen(curDir
) + 1;
1327 if (*curdir_len
< len
) retval
|= VFF_BUFFTOOSMALL
;
1328 lstrcpynA(cur_dir
, curDir
, *curdir_len
);
1332 TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval
,
1333 (retval
& VFF_CURNEDEST
) ? "VFF_CURNEDEST " : "",
1334 (retval
& VFF_FILEINUSE
) ? "VFF_FILEINUSE " : "",
1335 (retval
& VFF_BUFFTOOSMALL
) ? "VFF_BUFFTOOSMALL " : "",
1336 debugstr_a(cur_dir
), debugstr_a(dest
));
1341 /*****************************************************************************
1342 * VerFindFileW (kernelbase.@)
1344 DWORD WINAPI
VerFindFileW( DWORD flags
, LPCWSTR filename
, LPCWSTR win_dir
, LPCWSTR app_dir
,
1345 LPWSTR cur_dir
, PUINT curdir_len
, LPWSTR dest
, PUINT dest_len
)
1348 const WCHAR
*curDir
;
1349 const WCHAR
*destDir
;
1351 TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
1352 flags
, debugstr_w(filename
), debugstr_w(win_dir
), debugstr_w(app_dir
),
1353 curdir_len
, curdir_len
? *curdir_len
: 0, dest_len
, dest_len
? *dest_len
: 0 );
1355 /* Figure out where the file should go; shared files default to the
1360 if(flags
& VFFF_ISSHAREDFILE
)
1362 destDir
= system_dir
;
1363 /* Were we given a filename? If so, try to find the file. */
1366 if(file_existsW(destDir
, filename
, FALSE
)) curDir
= destDir
;
1367 else if(app_dir
&& file_existsW(app_dir
, filename
, FALSE
))
1370 retval
|= VFF_CURNEDEST
;
1374 else /* not a shared file */
1376 destDir
= app_dir
? app_dir
: L
"";
1379 if(file_existsW(destDir
, filename
, FALSE
)) curDir
= destDir
;
1380 else if(file_existsW(windows_dir
, filename
, FALSE
))
1382 curDir
= windows_dir
;
1383 retval
|= VFF_CURNEDEST
;
1385 else if (file_existsW(system_dir
, filename
, FALSE
))
1387 curDir
= system_dir
;
1388 retval
|= VFF_CURNEDEST
;
1393 if (filename
&& !file_existsW(curDir
, filename
, TRUE
))
1394 retval
|= VFF_FILEINUSE
;
1396 if (dest_len
&& dest
)
1398 UINT len
= lstrlenW(destDir
) + 1;
1399 if (*dest_len
< len
) retval
|= VFF_BUFFTOOSMALL
;
1400 lstrcpynW(dest
, destDir
, *dest_len
);
1403 if (curdir_len
&& cur_dir
)
1405 UINT len
= lstrlenW(curDir
) + 1;
1406 if (*curdir_len
< len
) retval
|= VFF_BUFFTOOSMALL
;
1407 lstrcpynW(cur_dir
, curDir
, *curdir_len
);
1411 TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval
,
1412 (retval
& VFF_CURNEDEST
) ? "VFF_CURNEDEST " : "",
1413 (retval
& VFF_FILEINUSE
) ? "VFF_FILEINUSE " : "",
1414 (retval
& VFF_BUFFTOOSMALL
) ? "VFF_BUFFTOOSMALL " : "",
1415 debugstr_w(cur_dir
), debugstr_w(dest
));
1420 /***********************************************************************
1421 * GetProductInfo (kernelbase.@)
1423 BOOL WINAPI DECLSPEC_HOTPATCH
GetProductInfo( DWORD os_major
, DWORD os_minor
,
1424 DWORD sp_major
, DWORD sp_minor
, DWORD
*type
)
1426 return RtlGetProductInfo( os_major
, os_minor
, sp_major
, sp_minor
, type
);
1430 /***********************************************************************
1431 * GetVersion (kernelbase.@)
1433 DWORD WINAPI
GetVersion(void)
1435 OSVERSIONINFOEXW info
;
1438 info
.dwOSVersionInfoSize
= sizeof(info
);
1439 if (!GetVersionExW( (OSVERSIONINFOW
*)&info
)) return 0;
1441 result
= MAKELONG( MAKEWORD( info
.dwMajorVersion
, info
.dwMinorVersion
),
1442 (info
.dwPlatformId
^ 2) << 14 );
1444 if (info
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1445 result
|= LOWORD(info
.dwBuildNumber
) << 16;
1450 /***********************************************************************
1451 * GetVersionExA (kernelbase.@)
1453 BOOL WINAPI
GetVersionExA( OSVERSIONINFOA
*info
)
1455 OSVERSIONINFOEXW infoW
;
1457 if (info
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
) &&
1458 info
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOEXA
))
1460 WARN( "wrong OSVERSIONINFO size from app (got: %d)\n", info
->dwOSVersionInfoSize
);
1461 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1465 infoW
.dwOSVersionInfoSize
= sizeof(infoW
);
1466 if (!GetVersionExW( (OSVERSIONINFOW
*)&infoW
)) return FALSE
;
1468 info
->dwMajorVersion
= infoW
.dwMajorVersion
;
1469 info
->dwMinorVersion
= infoW
.dwMinorVersion
;
1470 info
->dwBuildNumber
= infoW
.dwBuildNumber
;
1471 info
->dwPlatformId
= infoW
.dwPlatformId
;
1472 WideCharToMultiByte( CP_ACP
, 0, infoW
.szCSDVersion
, -1,
1473 info
->szCSDVersion
, sizeof(info
->szCSDVersion
), NULL
, NULL
);
1475 if (info
->dwOSVersionInfoSize
== sizeof(OSVERSIONINFOEXA
))
1477 OSVERSIONINFOEXA
*vex
= (OSVERSIONINFOEXA
*)info
;
1478 vex
->wServicePackMajor
= infoW
.wServicePackMajor
;
1479 vex
->wServicePackMinor
= infoW
.wServicePackMinor
;
1480 vex
->wSuiteMask
= infoW
.wSuiteMask
;
1481 vex
->wProductType
= infoW
.wProductType
;
1487 /***********************************************************************
1488 * GetVersionExW (kernelbase.@)
1490 BOOL WINAPI
GetVersionExW( OSVERSIONINFOW
*info
)
1492 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
1494 if (info
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOW
) &&
1495 info
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOEXW
))
1497 WARN( "wrong OSVERSIONINFO size from app (got: %d)\n", info
->dwOSVersionInfoSize
);
1501 if (!InitOnceExecuteOnce(&init_once
, init_current_version
, NULL
, NULL
)) return FALSE
;
1503 info
->dwMajorVersion
= current_version
.dwMajorVersion
;
1504 info
->dwMinorVersion
= current_version
.dwMinorVersion
;
1505 info
->dwBuildNumber
= current_version
.dwBuildNumber
;
1506 info
->dwPlatformId
= current_version
.dwPlatformId
;
1507 wcscpy( info
->szCSDVersion
, current_version
.szCSDVersion
);
1509 if (info
->dwOSVersionInfoSize
== sizeof(OSVERSIONINFOEXW
))
1511 OSVERSIONINFOEXW
*vex
= (OSVERSIONINFOEXW
*)info
;
1512 vex
->wServicePackMajor
= current_version
.wServicePackMajor
;
1513 vex
->wServicePackMinor
= current_version
.wServicePackMinor
;
1514 vex
->wSuiteMask
= current_version
.wSuiteMask
;
1515 vex
->wProductType
= current_version
.wProductType
;
1521 /***********************************************************************
1522 * GetCurrentPackageFamilyName (kernelbase.@)
1524 LONG WINAPI
/* DECLSPEC_HOTPATCH */ GetCurrentPackageFamilyName( UINT32
*length
, WCHAR
*name
)
1526 FIXME( "(%p %p): stub\n", length
, name
);
1527 return APPMODEL_ERROR_NO_PACKAGE
;
1531 /***********************************************************************
1532 * GetCurrentPackageFullName (kernelbase.@)
1534 LONG WINAPI
/* DECLSPEC_HOTPATCH */ GetCurrentPackageFullName( UINT32
*length
, WCHAR
*name
)
1536 FIXME( "(%p %p): stub\n", length
, name
);
1537 return APPMODEL_ERROR_NO_PACKAGE
;
1541 /***********************************************************************
1542 * GetCurrentPackageId (kernelbase.@)
1544 LONG WINAPI
/* DECLSPEC_HOTPATCH */ GetCurrentPackageId( UINT32
*len
, BYTE
*buffer
)
1546 FIXME( "(%p %p): stub\n", len
, buffer
);
1547 return APPMODEL_ERROR_NO_PACKAGE
;
1551 /***********************************************************************
1552 * GetPackageFullName (kernelbase.@)
1554 LONG WINAPI
/* DECLSPEC_HOTPATCH */ GetPackageFullName( HANDLE process
, UINT32
*length
, WCHAR
*name
)
1556 FIXME( "(%p %p %p): stub\n", process
, length
, name
);
1557 return APPMODEL_ERROR_NO_PACKAGE
;
1561 /***********************************************************************
1562 * GetPackageFamilyName (kernelbase.@)
1564 LONG WINAPI
/* DECLSPEC_HOTPATCH */ GetPackageFamilyName( HANDLE process
, UINT32
*length
, WCHAR
*name
)
1566 FIXME( "(%p %p %p): stub\n", process
, length
, name
);
1567 return APPMODEL_ERROR_NO_PACKAGE
;
1578 {PROCESSOR_ARCHITECTURE_INTEL
, L
"x86"},
1579 {PROCESSOR_ARCHITECTURE_ARM
, L
"arm"},
1580 {PROCESSOR_ARCHITECTURE_AMD64
, L
"x64"},
1581 {PROCESSOR_ARCHITECTURE_NEUTRAL
, L
"neutral"},
1582 {PROCESSOR_ARCHITECTURE_ARM64
, L
"arm64"},
1583 {PROCESSOR_ARCHITECTURE_UNKNOWN
, L
"unknown"},
1586 static UINT32
processor_arch_from_string(const WCHAR
*str
, unsigned int len
)
1590 for (i
= 0; i
< ARRAY_SIZE(arch_names
); ++i
)
1591 if (lstrlenW(arch_names
[i
].name
) == len
&& !wcsnicmp(str
, arch_names
[i
].name
, len
))
1592 return arch_names
[i
].code
;
1596 /***********************************************************************
1597 * PackageIdFromFullName (kernelbase.@)
1599 LONG WINAPI
PackageIdFromFullName(const WCHAR
*full_name
, UINT32 flags
, UINT32
*buffer_length
, BYTE
*buffer
)
1601 const WCHAR
*name
, *version_str
, *arch_str
, *resource_id
, *publisher_id
, *s
;
1602 PACKAGE_ID
*id
= (PACKAGE_ID
*)buffer
;
1603 UINT32 size
, buffer_size
, len
;
1605 TRACE("full_name %s, flags %#x, buffer_length %p, buffer %p.\n",
1606 debugstr_w(full_name
), flags
, buffer_length
, buffer
);
1609 FIXME("Flags %#x are not supported.\n", flags
);
1611 if (!full_name
|| !buffer_length
)
1612 return ERROR_INVALID_PARAMETER
;
1614 if (!buffer
&& *buffer_length
)
1615 return ERROR_INVALID_PARAMETER
;
1618 if (!(version_str
= wcschr(name
, L
'_')))
1619 return ERROR_INVALID_PARAMETER
;
1622 if (!(arch_str
= wcschr(version_str
, L
'_')))
1623 return ERROR_INVALID_PARAMETER
;
1626 if (!(resource_id
= wcschr(arch_str
, L
'_')))
1627 return ERROR_INVALID_PARAMETER
;
1630 if (!(publisher_id
= wcschr(resource_id
, L
'_')))
1631 return ERROR_INVALID_PARAMETER
;
1634 /* Publisher id length should be 13. */
1635 size
= sizeof(*id
) + sizeof(WCHAR
) * ((version_str
- name
) + (publisher_id
- resource_id
) + 13 + 1);
1636 buffer_size
= *buffer_length
;
1637 *buffer_length
= size
;
1638 if (buffer_size
< size
)
1639 return ERROR_INSUFFICIENT_BUFFER
;
1641 memset(id
, 0, sizeof(*id
));
1642 if ((id
->processorArchitecture
= processor_arch_from_string(arch_str
, resource_id
- arch_str
- 1)) == ~0u)
1644 FIXME("Unrecognized arch %s.\n", debugstr_w(arch_str
));
1645 return ERROR_INVALID_PARAMETER
;
1647 buffer
+= sizeof(*id
);
1649 id
->version
.u
.s
.Major
= wcstol(version_str
, NULL
, 10);
1650 if (!(s
= wcschr(version_str
, L
'.')))
1651 return ERROR_INVALID_PARAMETER
;
1653 id
->version
.u
.s
.Minor
= wcstol(s
, NULL
, 10);
1654 if (!(s
= wcschr(s
, L
'.')))
1655 return ERROR_INVALID_PARAMETER
;
1657 id
->version
.u
.s
.Build
= wcstol(s
, NULL
, 10);
1658 if (!(s
= wcschr(s
, L
'.')))
1659 return ERROR_INVALID_PARAMETER
;
1661 id
->version
.u
.s
.Revision
= wcstol(s
, NULL
, 10);
1663 id
->name
= (WCHAR
*)buffer
;
1664 len
= version_str
- name
- 1;
1665 memcpy(id
->name
, name
, sizeof(*id
->name
) * len
);
1667 buffer
+= sizeof(*id
->name
) * (len
+ 1);
1669 id
->resourceId
= (WCHAR
*)buffer
;
1670 len
= publisher_id
- resource_id
- 1;
1671 memcpy(id
->resourceId
, resource_id
, sizeof(*id
->resourceId
) * len
);
1672 id
->resourceId
[len
] = 0;
1673 buffer
+= sizeof(*id
->resourceId
) * (len
+ 1);
1675 id
->publisherId
= (WCHAR
*)buffer
;
1676 len
= lstrlenW(publisher_id
);
1678 return ERROR_INVALID_PARAMETER
;
1679 memcpy(id
->publisherId
, publisher_id
, sizeof(*id
->publisherId
) * len
);
1680 id
->publisherId
[len
] = 0;
1682 return ERROR_SUCCESS
;