wbemprox: Add class SystemRestore stub implementation.
[wine.git] / dlls / kernelbase / version.c
blob58c49aa148b4c9aa425da1fae878b1356ed133d1
1 /*
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
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <sys/types.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "winnls.h"
40 #include "winternl.h"
41 #include "winerror.h"
43 #include "kernelbase.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(ver);
48 typedef struct
50 WORD offset;
51 WORD length;
52 WORD flags;
53 WORD id;
54 WORD handle;
55 WORD usage;
56 } NE_NAMEINFO;
58 typedef struct
60 WORD type_id;
61 WORD count;
62 DWORD resloader;
63 } NE_TYPEINFO;
65 struct version_info
67 DWORD major;
68 DWORD minor;
69 DWORD build;
72 /***********************************************************************
73 * Version Info Structure
76 typedef struct
78 WORD wLength;
79 WORD wValueLength;
80 CHAR szKey[1];
81 #if 0 /* variable length structure */
82 /* DWORD aligned */
83 BYTE Value[];
84 /* DWORD aligned */
85 VS_VERSION_INFO_STRUCT16 Children[];
86 #endif
87 } VS_VERSION_INFO_STRUCT16;
89 typedef struct
91 WORD wLength;
92 WORD wValueLength;
93 WORD wType; /* 1:Text, 0:Binary */
94 WCHAR szKey[1];
95 #if 0 /* variable length structure */
96 /* DWORD aligned */
97 BYTE Value[];
98 /* DWORD aligned */
99 VS_VERSION_INFO_STRUCT32 Children[];
100 #endif
101 } VS_VERSION_INFO_STRUCT32;
103 #define VersionInfoIs16( ver ) \
104 ( ((const VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
106 #define DWORD_ALIGN( base, ptr ) \
107 ( (LPBYTE)(base) + ((((LPBYTE)(ptr) - (LPBYTE)(base)) + 3) & ~3) )
109 #define VersionInfo16_Value( ver ) \
110 DWORD_ALIGN( (ver), (ver)->szKey + strlen((ver)->szKey) + 1 )
111 #define VersionInfo32_Value( ver ) \
112 DWORD_ALIGN( (ver), (ver)->szKey + lstrlenW((ver)->szKey) + 1 )
114 #define VersionInfo16_Children( ver ) \
115 (const VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
116 ( ( (ver)->wValueLength + 3 ) & ~3 ) )
117 #define VersionInfo32_Children( ver ) \
118 (const VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
119 ( ( (ver)->wValueLength * \
120 ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
122 #define VersionInfo16_Next( ver ) \
123 (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
124 #define VersionInfo32_Next( ver ) \
125 (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
128 /***********************************************************************
129 * Win8 info, reported if app doesn't provide compat GUID in manifest.
131 static const struct version_info windows8_version_info = { 6, 2, 0x23f0 };
134 /***********************************************************************
135 * Windows versions that need compatibility GUID specified in manifest
136 * in order to be reported by the APIs.
138 static const struct
140 struct version_info info;
141 GUID guid;
142 } version_data[] =
144 /* Windows 8.1 */
146 { 6, 3, 0x2580 },
147 {0x1f676c76,0x80e1,0x4239,{0x95,0xbb,0x83,0xd0,0xf6,0xd0,0xda,0x78}}
149 /* Windows 10 */
151 { 10, 0, 0x42ee },
152 {0x8e0f7a12,0xbfb3,0x4fe8,{0xb9,0xa5,0x48,0xfd,0x50,0xa1,0x5a,0x9a}}
157 /******************************************************************************
158 * init_current_version
160 * Initialize the current_version variable.
162 * For compatibility, Windows 8.1 and later report Win8 version unless the app
163 * has a manifest that confirms its compatibility with newer versions of Windows.
166 static RTL_OSVERSIONINFOEXW current_version;
168 static BOOL CALLBACK init_current_version(PINIT_ONCE init_once, PVOID parameter, PVOID *context)
170 /*ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION*/DWORD *acci;
171 const struct version_info *ver;
172 SIZE_T req;
173 int idx;
175 current_version.dwOSVersionInfoSize = sizeof(current_version);
176 if (!set_ntstatus( RtlGetVersion(&current_version) )) return FALSE;
178 for (idx = ARRAY_SIZE(version_data); idx--;)
179 if ( current_version.dwMajorVersion > version_data[idx].info.major ||
180 (current_version.dwMajorVersion == version_data[idx].info.major &&
181 current_version.dwMinorVersion >= version_data[idx].info.minor))
182 break;
184 if (idx < 0) return TRUE;
185 ver = &windows8_version_info;
187 if (RtlQueryInformationActivationContext(0, NtCurrentTeb()->Peb->ActivationContextData, NULL,
188 CompatibilityInformationInActivationContext, NULL, 0, &req) != STATUS_BUFFER_TOO_SMALL
189 || !req)
190 goto done;
192 if (!(acci = HeapAlloc(GetProcessHeap(), 0, req)))
194 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
195 return FALSE;
198 if (RtlQueryInformationActivationContext(0, NtCurrentTeb()->Peb->ActivationContextData, NULL,
199 CompatibilityInformationInActivationContext, acci, req, &req) == STATUS_SUCCESS)
203 COMPATIBILITY_CONTEXT_ELEMENT *elements = (COMPATIBILITY_CONTEXT_ELEMENT*)(acci + 1);
204 DWORD i, count = *acci;
206 for (i = 0; i < count; i++)
208 if (elements[i].Type == ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS &&
209 IsEqualGUID(&elements[i].Id, &version_data[idx].guid))
211 ver = &version_data[idx].info;
213 if (ver->major == current_version.dwMajorVersion &&
214 ver->minor == current_version.dwMinorVersion)
215 ver = NULL;
217 idx = 0; /* break from outer loop */
218 break;
221 } while (idx--);
223 HeapFree(GetProcessHeap(), 0, acci);
225 done:
226 if (ver)
228 current_version.dwMajorVersion = ver->major;
229 current_version.dwMinorVersion = ver->minor;
230 current_version.dwBuildNumber = ver->build;
232 return TRUE;
236 /**********************************************************************
237 * find_entry_by_id
239 * Find an entry by id in a resource directory
240 * Copied from loader/pe_resource.c
242 static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_id( const IMAGE_RESOURCE_DIRECTORY *dir,
243 WORD id, const void *root )
245 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
246 int min, max, pos;
248 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
249 min = dir->NumberOfNamedEntries;
250 max = min + dir->NumberOfIdEntries - 1;
251 while (min <= max)
253 pos = (min + max) / 2;
254 if (entry[pos].u.Id == id)
255 return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s2.OffsetToDirectory);
256 if (entry[pos].u.Id > id) max = pos - 1;
257 else min = pos + 1;
259 return NULL;
263 /**********************************************************************
264 * find_entry_default
266 * Find a default entry in a resource directory
267 * Copied from loader/pe_resource.c
269 static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
270 const void *root )
272 const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
274 entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
275 return (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry->u2.s2.OffsetToDirectory);
279 /**********************************************************************
280 * push_language
282 * push a language onto the list of languages to try
284 static inline int push_language( WORD *list, int pos, WORD lang )
286 int i;
287 for (i = 0; i < pos; i++) if (list[i] == lang) return pos;
288 list[pos++] = lang;
289 return pos;
293 /**********************************************************************
294 * find_entry_language
296 static const IMAGE_RESOURCE_DIRECTORY *find_entry_language( const IMAGE_RESOURCE_DIRECTORY *dir,
297 const void *root, DWORD flags )
299 const IMAGE_RESOURCE_DIRECTORY *ret;
300 WORD list[9];
301 int i, pos = 0;
303 if (flags & FILE_VER_GET_LOCALISED)
305 /* cf. LdrFindResource_U */
306 pos = push_language( list, pos, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) );
307 pos = push_language( list, pos, LANGIDFROMLCID( NtCurrentTeb()->CurrentLocale ) );
308 pos = push_language( list, pos, GetUserDefaultLangID() );
309 pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(GetUserDefaultLangID()), SUBLANG_NEUTRAL ));
310 pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(GetUserDefaultLangID()), SUBLANG_DEFAULT ));
311 pos = push_language( list, pos, GetSystemDefaultLangID() );
312 pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_NEUTRAL ));
313 pos = push_language( list, pos, MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_DEFAULT ));
314 pos = push_language( list, pos, MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) );
316 else
318 /* FIXME: resolve LN file here */
319 pos = push_language( list, pos, MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ) );
322 for (i = 0; i < pos; i++) if ((ret = find_entry_by_id( dir, list[i], root ))) return ret;
323 return find_entry_default( dir, root );
327 static DWORD read_data( HANDLE handle, DWORD offset, void *data, DWORD len )
329 DWORD res;
331 SetFilePointer( handle, offset, NULL, FILE_BEGIN );
332 if (!ReadFile( handle, data, len, &res, NULL )) res = 0;
333 return res;
336 /***********************************************************************
337 * find_ne_resource [internal]
339 static BOOL find_ne_resource( HANDLE handle, DWORD *resLen, DWORD *resOff )
341 const WORD typeid = VS_FILE_INFO | 0x8000;
342 const WORD resid = VS_VERSION_INFO | 0x8000;
343 IMAGE_OS2_HEADER nehd;
344 NE_TYPEINFO *typeInfo;
345 NE_NAMEINFO *nameInfo;
346 DWORD nehdoffset = *resOff;
347 LPBYTE resTab;
348 DWORD resTabSize;
349 int count;
351 /* Read in NE header */
352 if (read_data( handle, nehdoffset, &nehd, sizeof(nehd) ) != sizeof(nehd)) return FALSE;
354 resTabSize = nehd.ne_restab - nehd.ne_rsrctab;
355 if ( !resTabSize )
357 TRACE("No resources in NE dll\n" );
358 return FALSE;
361 /* Read in resource table */
362 resTab = HeapAlloc( GetProcessHeap(), 0, resTabSize );
363 if ( !resTab ) return FALSE;
365 if (read_data( handle, nehd.ne_rsrctab + nehdoffset, resTab, resTabSize ) != resTabSize)
367 HeapFree( GetProcessHeap(), 0, resTab );
368 return FALSE;
371 /* Find resource */
372 typeInfo = (NE_TYPEINFO *)(resTab + 2);
373 while (typeInfo->type_id)
375 if (typeInfo->type_id == typeid) goto found_type;
376 typeInfo = (NE_TYPEINFO *)((char *)(typeInfo + 1) +
377 typeInfo->count * sizeof(NE_NAMEINFO));
379 TRACE("No typeid entry found\n" );
380 HeapFree( GetProcessHeap(), 0, resTab );
381 return FALSE;
383 found_type:
384 nameInfo = (NE_NAMEINFO *)(typeInfo + 1);
386 for (count = typeInfo->count; count > 0; count--, nameInfo++)
387 if (nameInfo->id == resid) goto found_name;
389 TRACE("No resid entry found\n" );
390 HeapFree( GetProcessHeap(), 0, resTab );
391 return FALSE;
393 found_name:
394 /* Return resource data */
395 *resLen = nameInfo->length << *(WORD *)resTab;
396 *resOff = nameInfo->offset << *(WORD *)resTab;
398 HeapFree( GetProcessHeap(), 0, resTab );
399 return TRUE;
402 /***********************************************************************
403 * find_pe_resource [internal]
405 static BOOL find_pe_resource( HANDLE handle, DWORD *resLen, DWORD *resOff, DWORD flags )
407 union
409 IMAGE_NT_HEADERS32 nt32;
410 IMAGE_NT_HEADERS64 nt64;
411 } pehd;
412 DWORD pehdoffset = *resOff;
413 PIMAGE_DATA_DIRECTORY resDataDir;
414 PIMAGE_SECTION_HEADER sections;
415 LPBYTE resSection;
416 DWORD len, section_size, data_size;
417 const void *resDir;
418 const IMAGE_RESOURCE_DIRECTORY *resPtr;
419 const IMAGE_RESOURCE_DATA_ENTRY *resData;
420 int i, nSections;
421 BOOL ret = FALSE;
423 /* Read in PE header */
424 len = read_data( handle, pehdoffset, &pehd, sizeof(pehd) );
425 if (len < sizeof(pehd.nt32.FileHeader)) return FALSE;
426 if (len < sizeof(pehd)) memset( (char *)&pehd + len, 0, sizeof(pehd) - len );
428 switch (pehd.nt32.OptionalHeader.Magic)
430 case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
431 resDataDir = pehd.nt32.OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_RESOURCE;
432 break;
433 case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
434 resDataDir = pehd.nt64.OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_RESOURCE;
435 break;
436 default:
437 return FALSE;
440 if ( !resDataDir->Size )
442 TRACE("No resources in PE dll\n" );
443 return FALSE;
446 /* Read in section table */
447 nSections = pehd.nt32.FileHeader.NumberOfSections;
448 sections = HeapAlloc( GetProcessHeap(), 0,
449 nSections * sizeof(IMAGE_SECTION_HEADER) );
450 if ( !sections ) return FALSE;
452 len = FIELD_OFFSET( IMAGE_NT_HEADERS32, OptionalHeader ) + pehd.nt32.FileHeader.SizeOfOptionalHeader;
453 if (read_data( handle, pehdoffset + len, sections, nSections * sizeof(IMAGE_SECTION_HEADER) ) !=
454 nSections * sizeof(IMAGE_SECTION_HEADER))
456 HeapFree( GetProcessHeap(), 0, sections );
457 return FALSE;
460 /* Find resource section */
461 for ( i = 0; i < nSections; i++ )
462 if ( resDataDir->VirtualAddress >= sections[i].VirtualAddress
463 && resDataDir->VirtualAddress < sections[i].VirtualAddress +
464 sections[i].SizeOfRawData )
465 break;
467 if ( i == nSections )
469 HeapFree( GetProcessHeap(), 0, sections );
470 TRACE("Couldn't find resource section\n" );
471 return FALSE;
474 /* Read in resource section */
475 data_size = sections[i].SizeOfRawData;
476 section_size = max( data_size, sections[i].Misc.VirtualSize );
477 resSection = HeapAlloc( GetProcessHeap(), 0, section_size );
478 if ( !resSection )
480 HeapFree( GetProcessHeap(), 0, sections );
481 return FALSE;
484 if (read_data( handle, sections[i].PointerToRawData, resSection, data_size ) != data_size) goto done;
485 if (data_size < section_size) memset( (char *)resSection + data_size, 0, section_size - data_size );
487 /* Find resource */
488 resDir = resSection + (resDataDir->VirtualAddress - sections[i].VirtualAddress);
490 resPtr = resDir;
491 resPtr = find_entry_by_id( resPtr, VS_FILE_INFO, resDir );
492 if ( !resPtr )
494 TRACE("No typeid entry found\n" );
495 goto done;
497 resPtr = find_entry_by_id( resPtr, VS_VERSION_INFO, resDir );
498 if ( !resPtr )
500 TRACE("No resid entry found\n" );
501 goto done;
503 resPtr = find_entry_language( resPtr, resDir, flags );
504 if ( !resPtr )
506 TRACE("No default language entry found\n" );
507 goto done;
510 /* Find resource data section */
511 resData = (const IMAGE_RESOURCE_DATA_ENTRY*)resPtr;
512 for ( i = 0; i < nSections; i++ )
513 if ( resData->OffsetToData >= sections[i].VirtualAddress
514 && resData->OffsetToData < sections[i].VirtualAddress +
515 sections[i].SizeOfRawData )
516 break;
518 if ( i == nSections )
520 TRACE("Couldn't find resource data section\n" );
521 goto done;
524 /* Return resource data */
525 *resLen = resData->Size;
526 *resOff = resData->OffsetToData - sections[i].VirtualAddress + sections[i].PointerToRawData;
527 ret = TRUE;
529 done:
530 HeapFree( GetProcessHeap(), 0, resSection );
531 HeapFree( GetProcessHeap(), 0, sections );
532 return ret;
536 /***********************************************************************
537 * find_version_resource [internal]
539 static DWORD find_version_resource( HANDLE handle, DWORD *reslen, DWORD *offset, DWORD flags )
541 IMAGE_DOS_HEADER mzh;
542 WORD magic;
544 if (read_data( handle, 0, &mzh, sizeof(mzh) ) != sizeof(mzh)) return 0;
545 if (mzh.e_magic != IMAGE_DOS_SIGNATURE) return 0;
547 if (read_data( handle, mzh.e_lfanew, &magic, sizeof(magic) ) != sizeof(magic)) return 0;
548 *offset = mzh.e_lfanew;
550 switch (magic)
552 case IMAGE_OS2_SIGNATURE:
553 if (!find_ne_resource( handle, reslen, offset )) magic = 0;
554 break;
555 case IMAGE_NT_SIGNATURE:
556 if (!find_pe_resource( handle, reslen, offset, flags )) magic = 0;
557 break;
559 WARN( "Can't handle %04x files.\n", magic );
560 return magic;
563 /******************************************************************************
564 * This function will print via standard TRACE, debug info regarding
565 * the file info structure vffi.
567 static void print_vffi_debug(const VS_FIXEDFILEINFO *vffi)
569 BOOL versioned_printer = FALSE;
571 if((vffi->dwFileType == VFT_DLL) || (vffi->dwFileType == VFT_DRV))
573 if(vffi->dwFileSubtype == VFT2_DRV_VERSIONED_PRINTER)
574 /* this is documented for newer w2k Drivers and up */
575 versioned_printer = TRUE;
576 else if( (vffi->dwFileSubtype == VFT2_DRV_PRINTER) &&
577 (vffi->dwFileVersionMS != vffi->dwProductVersionMS) &&
578 (vffi->dwFileVersionMS > 0) &&
579 (vffi->dwFileVersionMS <= 3) )
580 /* found this on NT 3.51, NT4.0 and old w2k Drivers */
581 versioned_printer = TRUE;
584 TRACE("structversion=%u.%u, ",
585 HIWORD(vffi->dwStrucVersion),LOWORD(vffi->dwStrucVersion));
586 if(versioned_printer)
588 WORD mode = LOWORD(vffi->dwFileVersionMS);
589 WORD ver_rev = HIWORD(vffi->dwFileVersionLS);
590 TRACE("fileversion=%u.%u.%u.%u (%s.major.minor.release), ",
591 (vffi->dwFileVersionMS),
592 HIBYTE(ver_rev), LOBYTE(ver_rev), LOWORD(vffi->dwFileVersionLS),
593 (mode == 3) ? "Usermode" : ((mode <= 2) ? "Kernelmode" : "?") );
595 else
597 TRACE("fileversion=%u.%u.%u.%u, ",
598 HIWORD(vffi->dwFileVersionMS),LOWORD(vffi->dwFileVersionMS),
599 HIWORD(vffi->dwFileVersionLS),LOWORD(vffi->dwFileVersionLS));
601 TRACE("productversion=%u.%u.%u.%u\n",
602 HIWORD(vffi->dwProductVersionMS),LOWORD(vffi->dwProductVersionMS),
603 HIWORD(vffi->dwProductVersionLS),LOWORD(vffi->dwProductVersionLS));
605 TRACE("flagmask=0x%x, flags=0x%x %s%s%s%s%s%s\n",
606 vffi->dwFileFlagsMask, vffi->dwFileFlags,
607 (vffi->dwFileFlags & VS_FF_DEBUG) ? "DEBUG," : "",
608 (vffi->dwFileFlags & VS_FF_PRERELEASE) ? "PRERELEASE," : "",
609 (vffi->dwFileFlags & VS_FF_PATCHED) ? "PATCHED," : "",
610 (vffi->dwFileFlags & VS_FF_PRIVATEBUILD) ? "PRIVATEBUILD," : "",
611 (vffi->dwFileFlags & VS_FF_INFOINFERRED) ? "INFOINFERRED," : "",
612 (vffi->dwFileFlags & VS_FF_SPECIALBUILD) ? "SPECIALBUILD," : "");
614 TRACE("(");
616 TRACE("OS=0x%x.0x%x ", HIWORD(vffi->dwFileOS), LOWORD(vffi->dwFileOS));
618 switch (vffi->dwFileOS&0xFFFF0000)
620 case VOS_DOS:TRACE("DOS,");break;
621 case VOS_OS216:TRACE("OS/2-16,");break;
622 case VOS_OS232:TRACE("OS/2-32,");break;
623 case VOS_NT:TRACE("NT,");break;
624 case VOS_UNKNOWN:
625 default:
626 TRACE("UNKNOWN(0x%x),",vffi->dwFileOS&0xFFFF0000);break;
629 switch (LOWORD(vffi->dwFileOS))
631 case VOS__BASE:TRACE("BASE");break;
632 case VOS__WINDOWS16:TRACE("WIN16");break;
633 case VOS__WINDOWS32:TRACE("WIN32");break;
634 case VOS__PM16:TRACE("PM16");break;
635 case VOS__PM32:TRACE("PM32");break;
636 default:
637 TRACE("UNKNOWN(0x%x)",LOWORD(vffi->dwFileOS));break;
640 TRACE(")\n");
642 switch (vffi->dwFileType)
644 case VFT_APP:TRACE("filetype=APP");break;
645 case VFT_DLL:
646 TRACE("filetype=DLL");
647 if(vffi->dwFileSubtype != 0)
649 if(versioned_printer) /* NT3.x/NT4.0 or old w2k Driver */
650 TRACE(",PRINTER");
651 TRACE(" (subtype=0x%x)", vffi->dwFileSubtype);
653 break;
654 case VFT_DRV:
655 TRACE("filetype=DRV,");
656 switch(vffi->dwFileSubtype)
658 case VFT2_DRV_PRINTER:TRACE("PRINTER");break;
659 case VFT2_DRV_KEYBOARD:TRACE("KEYBOARD");break;
660 case VFT2_DRV_LANGUAGE:TRACE("LANGUAGE");break;
661 case VFT2_DRV_DISPLAY:TRACE("DISPLAY");break;
662 case VFT2_DRV_MOUSE:TRACE("MOUSE");break;
663 case VFT2_DRV_NETWORK:TRACE("NETWORK");break;
664 case VFT2_DRV_SYSTEM:TRACE("SYSTEM");break;
665 case VFT2_DRV_INSTALLABLE:TRACE("INSTALLABLE");break;
666 case VFT2_DRV_SOUND:TRACE("SOUND");break;
667 case VFT2_DRV_COMM:TRACE("COMM");break;
668 case VFT2_DRV_INPUTMETHOD:TRACE("INPUTMETHOD");break;
669 case VFT2_DRV_VERSIONED_PRINTER:TRACE("VERSIONED_PRINTER");break;
670 case VFT2_UNKNOWN:
671 default:
672 TRACE("UNKNOWN(0x%x)",vffi->dwFileSubtype);break;
674 break;
675 case VFT_FONT:
676 TRACE("filetype=FONT,");
677 switch (vffi->dwFileSubtype)
679 case VFT2_FONT_RASTER:TRACE("RASTER");break;
680 case VFT2_FONT_VECTOR:TRACE("VECTOR");break;
681 case VFT2_FONT_TRUETYPE:TRACE("TRUETYPE");break;
682 default:TRACE("UNKNOWN(0x%x)",vffi->dwFileSubtype);break;
684 break;
685 case VFT_VXD:TRACE("filetype=VXD");break;
686 case VFT_STATIC_LIB:TRACE("filetype=STATIC_LIB");break;
687 case VFT_UNKNOWN:
688 default:
689 TRACE("filetype=Unknown(0x%x)",vffi->dwFileType);break;
692 TRACE("\n");
693 TRACE("filedate=0x%x.0x%x\n",vffi->dwFileDateMS,vffi->dwFileDateLS);
696 /***********************************************************************
697 * GetFileVersionInfoSizeW (kernelbase.@)
699 DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
701 return GetFileVersionInfoSizeExW( FILE_VER_GET_LOCALISED, filename, handle );
704 /***********************************************************************
705 * GetFileVersionInfoSizeA (kernelbase.@)
707 DWORD WINAPI GetFileVersionInfoSizeA( LPCSTR filename, LPDWORD handle )
709 return GetFileVersionInfoSizeExA( FILE_VER_GET_LOCALISED, filename, handle );
712 /******************************************************************************
713 * GetFileVersionInfoSizeExW (kernelbase.@)
715 DWORD WINAPI GetFileVersionInfoSizeExW( DWORD flags, LPCWSTR filename, LPDWORD ret_handle )
717 DWORD len, offset, magic = 1;
718 HMODULE hModule;
720 TRACE("(0x%x,%s,%p)\n", flags, debugstr_w(filename), ret_handle );
722 if (ret_handle) *ret_handle = 0;
724 if (!filename)
726 SetLastError(ERROR_INVALID_PARAMETER);
727 return 0;
729 if (!*filename)
731 SetLastError(ERROR_BAD_PATHNAME);
732 return 0;
734 if (flags & ~FILE_VER_GET_LOCALISED)
735 FIXME("flags 0x%x ignored\n", flags & ~FILE_VER_GET_LOCALISED);
737 if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
739 HRSRC hRsrc = NULL;
740 if (!(flags & FILE_VER_GET_LOCALISED))
742 LANGID english = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
743 hRsrc = FindResourceExW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
744 (LPWSTR)VS_FILE_INFO, english );
746 if (!hRsrc)
747 hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
748 (LPWSTR)VS_FILE_INFO );
749 if (hRsrc)
751 magic = IMAGE_NT_SIGNATURE;
752 len = SizeofResource( hModule, hRsrc );
754 FreeLibrary( hModule );
757 if (magic == 1)
759 HANDLE handle = CreateFileW( filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
760 NULL, OPEN_EXISTING, 0, 0 );
761 if (handle == INVALID_HANDLE_VALUE) return 0;
762 magic = find_version_resource( handle, &len, &offset, flags );
763 CloseHandle( handle );
766 switch (magic)
768 case IMAGE_OS2_SIGNATURE:
769 /* We have a 16bit resource.
771 * XP/W2K/W2K3 uses a buffer which is more than the actual needed space:
773 * (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4
775 * This extra buffer is used for ANSI to Unicode conversions in W-Calls.
776 * info->wLength should be the same as len. Currently it isn't but that
777 * doesn't seem to be a problem (len is bigger than info->wLength).
779 SetLastError(0);
780 return (len - sizeof(VS_FIXEDFILEINFO)) * 4;
782 case IMAGE_NT_SIGNATURE:
783 /* We have a 32bit resource.
785 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
786 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
788 SetLastError(0);
789 return (len * 2) + 4;
791 default:
792 if (GetVersion() & 0x80000000) /* Windows 95/98 */
793 SetLastError(ERROR_FILE_NOT_FOUND);
794 else
795 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
796 return 0;
800 /******************************************************************************
801 * GetFileVersionInfoSizeExA (kernelbase.@)
803 DWORD WINAPI GetFileVersionInfoSizeExA( DWORD flags, LPCSTR filename, LPDWORD handle )
805 UNICODE_STRING filenameW;
806 DWORD retval;
808 TRACE("(0x%x,%s,%p)\n", flags, debugstr_a(filename), handle );
810 if(filename)
811 RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
812 else
813 filenameW.Buffer = NULL;
815 retval = GetFileVersionInfoSizeExW(flags, filenameW.Buffer, handle);
817 RtlFreeUnicodeString(&filenameW);
819 return retval;
822 /***********************************************************************
823 * GetFileVersionInfoExW (kernelbase.@)
825 BOOL WINAPI GetFileVersionInfoExW( DWORD flags, LPCWSTR filename, DWORD ignored, DWORD datasize, LPVOID data )
827 static const char signature[4] = "FE2X";
828 DWORD len, offset, magic = 1;
829 HMODULE hModule;
830 VS_VERSION_INFO_STRUCT32* vvis = data;
832 TRACE("(0x%x,%s,%d,size=%d,data=%p)\n",
833 flags, debugstr_w(filename), ignored, datasize, data );
835 if (!data)
837 SetLastError(ERROR_INVALID_DATA);
838 return FALSE;
840 if (flags & ~FILE_VER_GET_LOCALISED)
841 FIXME("flags 0x%x ignored\n", flags & ~FILE_VER_GET_LOCALISED);
843 if ((hModule = LoadLibraryExW( filename, 0, LOAD_LIBRARY_AS_DATAFILE )))
845 HRSRC hRsrc = NULL;
846 if (!(flags & FILE_VER_GET_LOCALISED))
848 LANGID english = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
849 hRsrc = FindResourceExW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
850 (LPWSTR)VS_FILE_INFO, english );
852 if (!hRsrc)
853 hRsrc = FindResourceW( hModule, MAKEINTRESOURCEW(VS_VERSION_INFO),
854 (LPWSTR)VS_FILE_INFO );
855 if (hRsrc)
857 HGLOBAL hMem = LoadResource( hModule, hRsrc );
858 magic = IMAGE_NT_SIGNATURE;
859 len = min( SizeofResource(hModule, hRsrc), datasize );
860 memcpy( data, LockResource( hMem ), len );
861 FreeResource( hMem );
863 FreeLibrary( hModule );
866 if (magic == 1)
868 HANDLE handle = CreateFileW( filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
869 NULL, OPEN_EXISTING, 0, 0 );
870 if (handle == INVALID_HANDLE_VALUE) return 0;
871 if ((magic = find_version_resource( handle, &len, &offset, flags )))
872 len = read_data( handle, offset, data, min( len, datasize ));
873 CloseHandle( handle );
876 switch (magic)
878 case IMAGE_OS2_SIGNATURE:
879 /* We have a 16bit resource. */
880 if (TRACE_ON(ver))
881 print_vffi_debug( (VS_FIXEDFILEINFO *)VersionInfo16_Value( (VS_VERSION_INFO_STRUCT16 *)data ));
882 SetLastError(0);
883 return TRUE;
885 case IMAGE_NT_SIGNATURE:
886 /* We have a 32bit resource.
888 * XP/W2K/W2K3 uses a buffer which is 2 times the actual needed space + 4 bytes "FE2X"
889 * This extra buffer is used for Unicode to ANSI conversions in A-Calls
891 len = vvis->wLength + sizeof(signature);
892 if (datasize >= len) memcpy( (char*)data + vvis->wLength, signature, sizeof(signature) );
893 if (TRACE_ON(ver))
894 print_vffi_debug( (VS_FIXEDFILEINFO *)VersionInfo32_Value( vvis ));
895 SetLastError(0);
896 return TRUE;
898 default:
899 SetLastError( ERROR_RESOURCE_DATA_NOT_FOUND );
900 return FALSE;
904 /***********************************************************************
905 * GetFileVersionInfoExA (kernelbase.@)
907 BOOL WINAPI GetFileVersionInfoExA( DWORD flags, LPCSTR filename, DWORD handle, DWORD datasize, LPVOID data )
909 UNICODE_STRING filenameW;
910 BOOL retval;
912 TRACE("(0x%x,%s,%d,size=%d,data=%p)\n",
913 flags, debugstr_a(filename), handle, datasize, data );
915 if(filename)
916 RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
917 else
918 filenameW.Buffer = NULL;
920 retval = GetFileVersionInfoExW(flags, filenameW.Buffer, handle, datasize, data);
922 RtlFreeUnicodeString(&filenameW);
924 return retval;
927 /***********************************************************************
928 * GetFileVersionInfoW (kernelbase.@)
930 BOOL WINAPI GetFileVersionInfoW( LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data )
932 return GetFileVersionInfoExW(FILE_VER_GET_LOCALISED, filename, handle, datasize, data);
935 /***********************************************************************
936 * GetFileVersionInfoA (kernelbase.@)
938 BOOL WINAPI GetFileVersionInfoA( LPCSTR filename, DWORD handle, DWORD datasize, LPVOID data )
940 return GetFileVersionInfoExA(FILE_VER_GET_LOCALISED, filename, handle, datasize, data);
943 /***********************************************************************
944 * VersionInfo16_FindChild [internal]
946 static const VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( const VS_VERSION_INFO_STRUCT16 *info,
947 LPCSTR key, UINT len )
949 const VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
951 while ((char *)child < (char *)info + info->wLength )
953 if (!strnicmp( child->szKey, key, len ) && !child->szKey[len])
954 return child;
956 if (!(child->wLength)) return NULL;
957 child = VersionInfo16_Next( child );
960 return NULL;
963 /***********************************************************************
964 * VersionInfo32_FindChild [internal]
966 static const VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( const VS_VERSION_INFO_STRUCT32 *info,
967 LPCWSTR key, UINT len )
969 const VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
971 while ((char *)child < (char *)info + info->wLength )
973 if (!wcsnicmp( child->szKey, key, len ) && !child->szKey[len])
974 return child;
976 if (!(child->wLength)) return NULL;
977 child = VersionInfo32_Next( child );
980 return NULL;
983 /***********************************************************************
984 * VersionInfo16_QueryValue [internal]
986 * Gets a value from a 16-bit NE resource
988 static BOOL VersionInfo16_QueryValue( const VS_VERSION_INFO_STRUCT16 *info, LPCSTR lpSubBlock,
989 LPVOID *lplpBuffer, UINT *puLen )
991 while ( *lpSubBlock )
993 /* Find next path component */
994 LPCSTR lpNextSlash;
995 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
996 if ( *lpNextSlash == '\\' )
997 break;
999 /* Skip empty components */
1000 if ( lpNextSlash == lpSubBlock )
1002 lpSubBlock++;
1003 continue;
1006 /* We have a non-empty component: search info for key */
1007 info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
1008 if ( !info )
1010 if (puLen) *puLen = 0 ;
1011 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND );
1012 return FALSE;
1015 /* Skip path component */
1016 lpSubBlock = lpNextSlash;
1019 /* Return value */
1020 *lplpBuffer = VersionInfo16_Value( info );
1021 if (puLen)
1022 *puLen = info->wValueLength;
1024 return TRUE;
1027 /***********************************************************************
1028 * VersionInfo32_QueryValue [internal]
1030 * Gets a value from a 32-bit PE resource
1032 static BOOL VersionInfo32_QueryValue( const VS_VERSION_INFO_STRUCT32 *info, LPCWSTR lpSubBlock,
1033 LPVOID *lplpBuffer, UINT *puLen, BOOL *pbText )
1035 TRACE("lpSubBlock : (%s)\n", debugstr_w(lpSubBlock));
1037 while ( *lpSubBlock )
1039 /* Find next path component */
1040 LPCWSTR lpNextSlash;
1041 for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
1042 if ( *lpNextSlash == '\\' )
1043 break;
1045 /* Skip empty components */
1046 if ( lpNextSlash == lpSubBlock )
1048 lpSubBlock++;
1049 continue;
1052 /* We have a non-empty component: search info for key */
1053 info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
1054 if ( !info )
1056 if (puLen) *puLen = 0 ;
1057 SetLastError( ERROR_RESOURCE_TYPE_NOT_FOUND );
1058 return FALSE;
1061 /* Skip path component */
1062 lpSubBlock = lpNextSlash;
1065 /* Return value */
1066 *lplpBuffer = VersionInfo32_Value( info );
1067 if (puLen)
1068 *puLen = info->wValueLength;
1069 if (pbText)
1070 *pbText = info->wType;
1072 return TRUE;
1075 /***********************************************************************
1076 * VerQueryValueA (kernelbase.@)
1078 BOOL WINAPI VerQueryValueA( LPCVOID pBlock, LPCSTR lpSubBlock,
1079 LPVOID *lplpBuffer, PUINT puLen )
1081 static const char rootA[] = "\\";
1082 const VS_VERSION_INFO_STRUCT16 *info = pBlock;
1084 TRACE("(%p,%s,%p,%p)\n",
1085 pBlock, debugstr_a(lpSubBlock), lplpBuffer, puLen );
1087 if (!pBlock)
1088 return FALSE;
1090 if (lpSubBlock == NULL || lpSubBlock[0] == '\0')
1091 lpSubBlock = rootA;
1093 if ( !VersionInfoIs16( info ) )
1095 BOOL ret, isText;
1096 INT len;
1097 LPWSTR lpSubBlockW;
1098 UINT value_len;
1100 len = MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, NULL, 0);
1101 lpSubBlockW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1103 if (!lpSubBlockW)
1104 return FALSE;
1106 MultiByteToWideChar(CP_ACP, 0, lpSubBlock, -1, lpSubBlockW, len);
1108 ret = VersionInfo32_QueryValue(pBlock, lpSubBlockW, lplpBuffer, &value_len, &isText);
1109 if (puLen) *puLen = value_len;
1111 HeapFree(GetProcessHeap(), 0, lpSubBlockW);
1113 if (ret && isText)
1115 /* Set lpBuffer so it points to the 'empty' area where we store
1116 * the converted strings
1118 LPSTR lpBufferA = (LPSTR)pBlock + info->wLength + 4;
1119 DWORD pos = (LPCSTR)*lplpBuffer - (LPCSTR)pBlock;
1120 len = WideCharToMultiByte(CP_ACP, 0, *lplpBuffer, value_len,
1121 lpBufferA + pos, info->wLength - pos, NULL, NULL);
1122 *lplpBuffer = lpBufferA + pos;
1123 if (puLen) *puLen = len;
1125 return ret;
1128 return VersionInfo16_QueryValue(info, lpSubBlock, lplpBuffer, puLen);
1131 /***********************************************************************
1132 * VerQueryValueW (kernelbase.@)
1134 BOOL WINAPI VerQueryValueW( LPCVOID pBlock, LPCWSTR lpSubBlock,
1135 LPVOID *lplpBuffer, PUINT puLen )
1137 const VS_VERSION_INFO_STRUCT32 *info = pBlock;
1139 TRACE("(%p,%s,%p,%p)\n",
1140 pBlock, debugstr_w(lpSubBlock), lplpBuffer, puLen );
1142 if (!pBlock)
1143 return FALSE;
1145 if (!lpSubBlock || !lpSubBlock[0])
1146 lpSubBlock = L"\\";
1148 if ( VersionInfoIs16( info ) )
1150 BOOL ret;
1151 int len;
1152 LPSTR lpSubBlockA;
1154 len = WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, NULL, 0, NULL, NULL);
1155 lpSubBlockA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
1157 if (!lpSubBlockA)
1158 return FALSE;
1160 WideCharToMultiByte(CP_ACP, 0, lpSubBlock, -1, lpSubBlockA, len, NULL, NULL);
1162 ret = VersionInfo16_QueryValue(pBlock, lpSubBlockA, lplpBuffer, puLen);
1164 HeapFree(GetProcessHeap(), 0, lpSubBlockA);
1166 if (ret && wcscmp( lpSubBlock, L"\\" ) && wcsicmp( lpSubBlock, L"\\VarFileInfo\\Translation" ))
1168 /* Set lpBuffer so it points to the 'empty' area where we store
1169 * the converted strings
1171 LPWSTR lpBufferW = (LPWSTR)((LPSTR)pBlock + info->wLength);
1172 DWORD pos = (LPCSTR)*lplpBuffer - (LPCSTR)pBlock;
1173 DWORD max = (info->wLength - sizeof(VS_FIXEDFILEINFO)) * 4 - info->wLength;
1175 len = MultiByteToWideChar(CP_ACP, 0, *lplpBuffer, -1,
1176 lpBufferW + pos, max/sizeof(WCHAR) - pos );
1177 *lplpBuffer = lpBufferW + pos;
1178 if (puLen) *puLen = len;
1180 return ret;
1183 return VersionInfo32_QueryValue(info, lpSubBlock, lplpBuffer, puLen, NULL);
1187 /******************************************************************************
1188 * file_existsA
1190 static BOOL file_existsA( char const * path, char const * file, BOOL excl )
1192 DWORD sharing = excl ? 0 : FILE_SHARE_READ | FILE_SHARE_WRITE;
1193 char filename[MAX_PATH];
1194 int len;
1195 HANDLE handle;
1197 if (path)
1199 strcpy( filename, path );
1200 len = strlen(filename);
1201 if (len && filename[len - 1] != '\\') strcat( filename, "\\" );
1202 strcat( filename, file );
1204 else if (!SearchPathA( NULL, file, NULL, MAX_PATH, filename, NULL )) return FALSE;
1206 handle = CreateFileA( filename, 0, sharing, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
1207 if (handle == INVALID_HANDLE_VALUE) return FALSE;
1208 CloseHandle( handle );
1209 return TRUE;
1212 /******************************************************************************
1213 * file_existsW
1215 static BOOL file_existsW( const WCHAR *path, const WCHAR *file, BOOL excl )
1217 DWORD sharing = excl ? 0 : FILE_SHARE_READ | FILE_SHARE_WRITE;
1218 WCHAR filename[MAX_PATH];
1219 int len;
1220 HANDLE handle;
1222 if (path)
1224 lstrcpyW( filename, path );
1225 len = lstrlenW(filename);
1226 if (len && filename[len - 1] != '\\') lstrcatW( filename, L"\\" );
1227 lstrcatW( filename, file );
1229 else if (!SearchPathW( NULL, file, NULL, MAX_PATH, filename, NULL )) return FALSE;
1231 handle = CreateFileW( filename, 0, sharing, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
1232 if (handle == INVALID_HANDLE_VALUE) return FALSE;
1233 CloseHandle( handle );
1234 return TRUE;
1237 /*****************************************************************************
1238 * VerFindFileA (kernelbase.@)
1240 * Determines where to install a file based on whether it locates another
1241 * version of the file in the system. The values VerFindFile returns are
1242 * used in a subsequent call to the VerInstallFile function.
1244 DWORD WINAPI VerFindFileA( DWORD flags, LPCSTR filename, LPCSTR win_dir, LPCSTR app_dir,
1245 LPSTR cur_dir, PUINT curdir_len, LPSTR dest, PUINT dest_len )
1247 DWORD retval = 0;
1248 const char *curDir;
1249 const char *destDir;
1250 char winDir[MAX_PATH], systemDir[MAX_PATH];
1252 TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
1253 flags, debugstr_a(filename), debugstr_a(win_dir), debugstr_a(app_dir),
1254 curdir_len, curdir_len ? *curdir_len : 0, dest_len, dest_len ? *dest_len : 0 );
1256 /* Figure out where the file should go; shared files default to the
1257 system directory */
1259 GetSystemDirectoryA(systemDir, sizeof(systemDir));
1260 curDir = "";
1262 if(flags & VFFF_ISSHAREDFILE)
1264 destDir = systemDir;
1265 /* Were we given a filename? If so, try to find the file. */
1266 if(filename)
1268 if(file_existsA(destDir, filename, FALSE)) curDir = destDir;
1269 else if(app_dir && file_existsA(app_dir, filename, FALSE))
1270 curDir = app_dir;
1272 if(!file_existsA(systemDir, filename, FALSE))
1273 retval |= VFF_CURNEDEST;
1276 else /* not a shared file */
1278 destDir = app_dir ? app_dir : "";
1279 if(filename)
1281 GetWindowsDirectoryA( winDir, MAX_PATH );
1282 if(file_existsA(destDir, filename, FALSE)) curDir = destDir;
1283 else if(file_existsA(winDir, filename, FALSE))
1284 curDir = winDir;
1285 else if(file_existsA(systemDir, filename, FALSE))
1286 curDir = systemDir;
1288 if (app_dir && app_dir[0])
1290 if(!file_existsA(app_dir, filename, FALSE))
1291 retval |= VFF_CURNEDEST;
1293 else if(file_existsA(NULL, filename, FALSE))
1294 retval |= VFF_CURNEDEST;
1298 /* Check to see if the file exists and is in use by another application */
1299 if (filename && file_existsA(curDir, filename, FALSE))
1301 if (filename && !file_existsA(curDir, filename, TRUE))
1302 retval |= VFF_FILEINUSE;
1305 if (dest_len && dest)
1307 UINT len = strlen(destDir) + 1;
1308 if (*dest_len < len) retval |= VFF_BUFFTOOSMALL;
1309 lstrcpynA(dest, destDir, *dest_len);
1310 *dest_len = len;
1312 if (curdir_len && cur_dir)
1314 UINT len = strlen(curDir) + 1;
1315 if (*curdir_len < len) retval |= VFF_BUFFTOOSMALL;
1316 lstrcpynA(cur_dir, curDir, *curdir_len);
1317 *curdir_len = len;
1320 TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval,
1321 (retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
1322 (retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
1323 (retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
1324 debugstr_a(cur_dir), debugstr_a(dest));
1326 return retval;
1329 /*****************************************************************************
1330 * VerFindFileW (kernelbase.@)
1332 DWORD WINAPI VerFindFileW( DWORD flags, LPCWSTR filename, LPCWSTR win_dir, LPCWSTR app_dir,
1333 LPWSTR cur_dir, PUINT curdir_len, LPWSTR dest, PUINT dest_len )
1335 DWORD retval = 0;
1336 const WCHAR *curDir;
1337 const WCHAR *destDir;
1339 TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
1340 flags, debugstr_w(filename), debugstr_w(win_dir), debugstr_w(app_dir),
1341 curdir_len, curdir_len ? *curdir_len : 0, dest_len, dest_len ? *dest_len : 0 );
1343 /* Figure out where the file should go; shared files default to the
1344 system directory */
1346 curDir = L"";
1348 if(flags & VFFF_ISSHAREDFILE)
1350 destDir = system_dir;
1351 /* Were we given a filename? If so, try to find the file. */
1352 if(filename)
1354 if(file_existsW(destDir, filename, FALSE)) curDir = destDir;
1355 else if(app_dir && file_existsW(app_dir, filename, FALSE))
1357 curDir = app_dir;
1358 retval |= VFF_CURNEDEST;
1362 else /* not a shared file */
1364 destDir = app_dir ? app_dir : L"";
1365 if(filename)
1367 if(file_existsW(destDir, filename, FALSE)) curDir = destDir;
1368 else if(file_existsW(windows_dir, filename, FALSE))
1370 curDir = windows_dir;
1371 retval |= VFF_CURNEDEST;
1373 else if (file_existsW(system_dir, filename, FALSE))
1375 curDir = system_dir;
1376 retval |= VFF_CURNEDEST;
1381 if (filename && !file_existsW(curDir, filename, TRUE))
1382 retval |= VFF_FILEINUSE;
1384 if (dest_len && dest)
1386 UINT len = lstrlenW(destDir) + 1;
1387 if (*dest_len < len) retval |= VFF_BUFFTOOSMALL;
1388 lstrcpynW(dest, destDir, *dest_len);
1389 *dest_len = len;
1391 if (curdir_len && cur_dir)
1393 UINT len = lstrlenW(curDir) + 1;
1394 if (*curdir_len < len) retval |= VFF_BUFFTOOSMALL;
1395 lstrcpynW(cur_dir, curDir, *curdir_len);
1396 *curdir_len = len;
1399 TRACE("ret = %u (%s%s%s) curdir=%s destdir=%s\n", retval,
1400 (retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
1401 (retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
1402 (retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
1403 debugstr_w(cur_dir), debugstr_w(dest));
1404 return retval;
1408 /***********************************************************************
1409 * GetProductInfo (kernelbase.@)
1411 BOOL WINAPI DECLSPEC_HOTPATCH GetProductInfo( DWORD os_major, DWORD os_minor,
1412 DWORD sp_major, DWORD sp_minor, DWORD *type )
1414 return RtlGetProductInfo( os_major, os_minor, sp_major, sp_minor, type );
1418 /***********************************************************************
1419 * GetVersion (kernelbase.@)
1421 DWORD WINAPI GetVersion(void)
1423 OSVERSIONINFOEXW info;
1424 DWORD result;
1426 info.dwOSVersionInfoSize = sizeof(info);
1427 if (!GetVersionExW( (OSVERSIONINFOW *)&info )) return 0;
1429 result = MAKELONG( MAKEWORD( info.dwMajorVersion, info.dwMinorVersion ),
1430 (info.dwPlatformId ^ 2) << 14 );
1432 if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
1433 result |= LOWORD(info.dwBuildNumber) << 16;
1434 return result;
1438 /***********************************************************************
1439 * GetVersionExA (kernelbase.@)
1441 BOOL WINAPI GetVersionExA( OSVERSIONINFOA *info )
1443 OSVERSIONINFOEXW infoW;
1445 if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
1446 info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
1448 WARN( "wrong OSVERSIONINFO size from app (got: %d)\n", info->dwOSVersionInfoSize );
1449 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1450 return FALSE;
1453 infoW.dwOSVersionInfoSize = sizeof(infoW);
1454 if (!GetVersionExW( (OSVERSIONINFOW *)&infoW )) return FALSE;
1456 info->dwMajorVersion = infoW.dwMajorVersion;
1457 info->dwMinorVersion = infoW.dwMinorVersion;
1458 info->dwBuildNumber = infoW.dwBuildNumber;
1459 info->dwPlatformId = infoW.dwPlatformId;
1460 WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
1461 info->szCSDVersion, sizeof(info->szCSDVersion), NULL, NULL );
1463 if (info->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
1465 OSVERSIONINFOEXA *vex = (OSVERSIONINFOEXA *)info;
1466 vex->wServicePackMajor = infoW.wServicePackMajor;
1467 vex->wServicePackMinor = infoW.wServicePackMinor;
1468 vex->wSuiteMask = infoW.wSuiteMask;
1469 vex->wProductType = infoW.wProductType;
1471 return TRUE;
1475 /***********************************************************************
1476 * GetVersionExW (kernelbase.@)
1478 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
1480 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
1482 if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
1483 info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
1485 WARN( "wrong OSVERSIONINFO size from app (got: %d)\n", info->dwOSVersionInfoSize );
1486 return FALSE;
1489 if (!InitOnceExecuteOnce(&init_once, init_current_version, NULL, NULL)) return FALSE;
1491 info->dwMajorVersion = current_version.dwMajorVersion;
1492 info->dwMinorVersion = current_version.dwMinorVersion;
1493 info->dwBuildNumber = current_version.dwBuildNumber;
1494 info->dwPlatformId = current_version.dwPlatformId;
1495 wcscpy( info->szCSDVersion, current_version.szCSDVersion );
1497 if (info->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW))
1499 OSVERSIONINFOEXW *vex = (OSVERSIONINFOEXW *)info;
1500 vex->wServicePackMajor = current_version.wServicePackMajor;
1501 vex->wServicePackMinor = current_version.wServicePackMinor;
1502 vex->wSuiteMask = current_version.wSuiteMask;
1503 vex->wProductType = current_version.wProductType;
1505 return TRUE;
1509 /***********************************************************************
1510 * GetCurrentPackageFamilyName (kernelbase.@)
1512 LONG WINAPI /* DECLSPEC_HOTPATCH */ GetCurrentPackageFamilyName( UINT32 *length, WCHAR *name )
1514 FIXME( "(%p %p): stub\n", length, name );
1515 return APPMODEL_ERROR_NO_PACKAGE;
1519 /***********************************************************************
1520 * GetCurrentPackageFullName (kernelbase.@)
1522 LONG WINAPI /* DECLSPEC_HOTPATCH */ GetCurrentPackageFullName( UINT32 *length, WCHAR *name )
1524 FIXME( "(%p %p): stub\n", length, name );
1525 return APPMODEL_ERROR_NO_PACKAGE;
1529 /***********************************************************************
1530 * GetCurrentPackageId (kernelbase.@)
1532 LONG WINAPI /* DECLSPEC_HOTPATCH */ GetCurrentPackageId( UINT32 *len, BYTE *buffer )
1534 FIXME( "(%p %p): stub\n", len, buffer );
1535 return APPMODEL_ERROR_NO_PACKAGE;
1539 /***********************************************************************
1540 * GetPackageFullName (kernelbase.@)
1542 LONG WINAPI /* DECLSPEC_HOTPATCH */ GetPackageFullName( HANDLE process, UINT32 *length, WCHAR *name )
1544 FIXME( "(%p %p %p): stub\n", process, length, name );
1545 return APPMODEL_ERROR_NO_PACKAGE;
1549 /***********************************************************************
1550 * GetPackageFamilyName (kernelbase.@)
1552 LONG WINAPI /* DECLSPEC_HOTPATCH */ GetPackageFamilyName( HANDLE process, UINT32 *length, WCHAR *name )
1554 FIXME( "(%p %p %p): stub\n", process, length, name );
1555 return APPMODEL_ERROR_NO_PACKAGE;