Release 961222
[wine/gsoc-2012-control.git] / misc / ver.c
blob84740c8f94b6e56b0fe3ae370e6932ab7bebfd32
1 /*
2 * Implementation of VER.DLL
3 *
4 * Copyright 1996 Marcus Meissner
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include "windows.h"
12 #include "win.h"
13 #include "winerror.h"
14 #include "heap.h"
15 #include "ver.h"
16 #include "lzexpand.h"
17 #include "module.h"
18 #include "neexe.h"
19 #include "stddebug.h"
20 #include "debug.h"
21 #include "xmalloc.h"
22 #include "winreg.h"
24 #define LZREAD(what) \
25 if (sizeof(*what)!=LZRead32(lzfd,what,sizeof(*what))) return 0;
26 #define LZTELL(lzfd) LZSeek(lzfd, 0, SEEK_CUR);
28 int
29 read_ne_header(HFILE lzfd,struct ne_header_s *nehd) {
30 struct mz_header_s mzh;
32 LZSeek(lzfd,0,SEEK_SET);
33 if (sizeof(mzh)!=LZRead32(lzfd,&mzh,sizeof(mzh)))
34 return 0;
35 if (mzh.mz_magic!=MZ_SIGNATURE)
36 return 0;
37 LZSeek(lzfd,mzh.ne_offset,SEEK_SET);
38 LZREAD(nehd);
39 if (nehd->ne_magic == NE_SIGNATURE) {
40 LZSeek(lzfd,mzh.ne_offset,SEEK_SET);
41 return 1;
43 /* must handle PE files too. Later. */
44 return 0;
48 int
49 find_ne_resource(
50 HFILE lzfd,struct ne_header_s *nehd,SEGPTR typeid,SEGPTR resid,
51 BYTE **resdata,int *reslen,DWORD *off
52 ) {
53 NE_TYPEINFO ti;
54 NE_NAMEINFO ni;
55 int i;
56 WORD shiftcount;
57 DWORD nehdoffset;
59 nehdoffset = LZTELL(lzfd);
60 LZSeek(lzfd,nehd->resource_tab_offset,SEEK_CUR);
61 LZREAD(&shiftcount);
62 dprintf_ver(stddeb,"shiftcount is %d\n",shiftcount);
63 dprintf_ver(stddeb,"reading resource typeinfo dir.\n");
65 if (!HIWORD(typeid)) typeid = (SEGPTR)(LOWORD(typeid) | 0x8000);
66 if (!HIWORD(resid)) resid = (SEGPTR)(LOWORD(resid) | 0x8000);
67 while (1) {
68 int skipflag;
70 LZREAD(&ti);
71 if (!ti.type_id)
72 return 0;
73 dprintf_ver(stddeb," ti.typeid =%04x,count=%d\n",ti.type_id,ti.count);
74 skipflag=0;
75 if (!HIWORD(typeid)) {
76 if ((ti.type_id&0x8000)&&(typeid!=ti.type_id))
77 skipflag=1;
78 } else {
79 if (ti.type_id & 0x8000) {
80 skipflag=1;
81 } else {
82 BYTE len;
83 char *str;
84 DWORD whereleft;
86 whereleft = LZTELL(lzfd);
87 LZSeek(
88 lzfd,
89 nehdoffset+nehd->resource_tab_offset+ti.type_id,
90 SEEK_SET
92 LZREAD(&len);
93 str=xmalloc(len);
94 if (len!=LZRead32(lzfd,str,len))
95 return 0;
96 dprintf_ver(stddeb,"read %s to compare it with %s\n",
97 str,(char*)PTR_SEG_TO_LIN(typeid)
99 if (lstrcmpi32A(str,(char*)PTR_SEG_TO_LIN(typeid)))
100 skipflag=1;
101 free(str);
102 LZSeek(lzfd,whereleft,SEEK_SET);
105 if (skipflag) {
106 LZSeek(lzfd,ti.count*sizeof(ni),SEEK_CUR);
107 continue;
109 for (i=0;i<ti.count;i++) {
110 WORD *rdata;
111 int len;
113 LZREAD(&ni);
114 dprintf_ver(stddeb," ni.id=%4x,offset=%d,length=%d\n",
115 ni.id,ni.offset,ni.length
117 skipflag=1;
118 if (!HIWORD(resid)) {
119 if (ni.id == resid)
120 skipflag=0;
121 } else {
122 if (!(ni.id & 0x8000)) {
123 BYTE len;
124 char *str;
125 DWORD whereleft;
127 whereleft = LZTELL(lzfd);
128 LZSeek(
129 lzfd,
130 nehdoffset+nehd->resource_tab_offset+ni.id,
131 SEEK_SET
133 LZREAD(&len);
134 str=xmalloc(len);
135 if (len!=LZRead32(lzfd,str,len))
136 return 0;
137 dprintf_ver(stddeb,"read %s to compare it with %s\n",
138 str,(char*)PTR_SEG_TO_LIN(typeid)
140 if (!lstrcmpi32A(str,(char*)PTR_SEG_TO_LIN(typeid)))
141 skipflag=0;
142 free(str);
143 LZSeek(lzfd,whereleft,SEEK_SET);
146 if (skipflag)
147 continue;
148 LZSeek(lzfd,((int)ni.offset<<shiftcount),SEEK_SET);
149 *off = (int)ni.offset<<shiftcount;
150 len = ni.length<<shiftcount;
151 rdata=(WORD*)xmalloc(len);
152 if (len!=LZRead32(lzfd,rdata,len)) {
153 free(rdata);
154 return 0;
156 dprintf_ver(stddeb,"resource found.\n");
157 *resdata= (BYTE*)rdata;
158 *reslen = len;
159 return 1;
164 /* GetFileResourceSize [VER.2] */
165 DWORD
166 GetFileResourceSize(LPCSTR filename,SEGPTR restype,SEGPTR resid,LPDWORD off) {
167 HFILE lzfd;
168 OFSTRUCT ofs;
169 BYTE *resdata;
170 int reslen;
171 struct ne_header_s nehd;
173 dprintf_ver(stddeb,"GetFileResourceSize(%s,%lx,%lx,%p)\n",
174 filename,(LONG)restype,(LONG)resid,off
176 lzfd=LZOpenFile16(filename,&ofs,OF_READ);
177 if (lzfd==0)
178 return 0;
179 if (!read_ne_header(lzfd,&nehd)) {
180 LZClose(lzfd);
181 return 0;
183 if (!find_ne_resource(lzfd,&nehd,restype,resid,&resdata,&reslen,off)) {
184 LZClose(lzfd);
185 return 0;
187 free(resdata);
188 LZClose(lzfd);
189 return reslen;
192 /* GetFileResource [VER.3] */
193 DWORD
194 GetFileResource(LPCSTR filename,SEGPTR restype,SEGPTR resid,
195 DWORD off,DWORD datalen,LPVOID data
197 HFILE lzfd;
198 OFSTRUCT ofs;
199 BYTE *resdata;
200 int reslen=datalen;
201 struct ne_header_s nehd;
202 dprintf_ver(stddeb,"GetFileResource(%s,%lx,%lx,%ld,%ld,%p)\n",
203 filename,(LONG)restype,(LONG)resid,off,datalen,data
206 lzfd=LZOpenFile16(filename,&ofs,OF_READ);
207 if (lzfd==0)
208 return 0;
209 if (!off) {
210 if (!read_ne_header(lzfd,&nehd)) {
211 LZClose(lzfd);
212 return 0;
214 if (!find_ne_resource(lzfd,&nehd,restype,resid,&resdata,&reslen,&off)) {
215 LZClose(lzfd);
216 return 0;
218 free(resdata);
220 LZSeek(lzfd,off,SEEK_SET);
221 if (reslen>datalen)
222 reslen=datalen;
223 LZRead32(lzfd,data,reslen);
224 LZClose(lzfd);
225 return reslen;
228 /* GetFileVersionInfoSize [VER.6] */
229 DWORD
230 GetFileVersionInfoSize16(LPCSTR filename,LPDWORD handle) {
231 DWORD len,ret;
232 BYTE buf[72];
233 VS_FIXEDFILEINFO *vffi;
235 dprintf_ver(stddeb,"GetFileVersionInfoSize16(%s,%p)\n",filename,handle);
236 len=GetFileResourceSize(filename,VS_FILE_INFO,VS_VERSION_INFO,handle);
237 if (!len)
238 return 0;
239 ret=GetFileResource(
240 filename,VS_FILE_INFO,VS_VERSION_INFO,*handle,sizeof(buf),buf
242 if (!ret)
243 return 0;
245 vffi=(VS_FIXEDFILEINFO*)(buf+0x14);
246 if (vffi->dwSignature != VS_FFI_SIGNATURE)
247 return 0;
248 if (*(WORD*)buf < len)
249 len = *(WORD*)buf;
250 dprintf_ver(stddeb,"->strucver=%ld.%ld,filever=%ld.%ld,productver=%ld.%ld,flagmask=%lx,flags=%lx,OS=",
251 (vffi->dwStrucVersion>>16),vffi->dwStrucVersion&0xFFFF,
252 vffi->dwFileVersionMS,vffi->dwFileVersionLS,
253 vffi->dwProductVersionMS,vffi->dwProductVersionLS,
254 vffi->dwFileFlagsMask,vffi->dwFileFlags
256 switch (vffi->dwFileOS&0xFFFF0000) {
257 case VOS_DOS:dprintf_ver(stddeb,"DOS,");break;
258 case VOS_OS216:dprintf_ver(stddeb,"OS/2-16,");break;
259 case VOS_OS232:dprintf_ver(stddeb,"OS/2-32,");break;
260 case VOS_NT:dprintf_ver(stddeb,"NT,");break;
261 case VOS_UNKNOWN:
262 default:
263 dprintf_ver(stddeb,"UNKNOWN(%ld),",vffi->dwFileOS&0xFFFF0000);break;
265 switch (vffi->dwFileOS & 0xFFFF) {
266 case VOS__BASE:dprintf_ver(stddeb,"BASE");break;
267 case VOS__WINDOWS16:dprintf_ver(stddeb,"WIN16");break;
268 case VOS__WINDOWS32:dprintf_ver(stddeb,"WIN32");break;
269 case VOS__PM16:dprintf_ver(stddeb,"PM16");break;
270 case VOS__PM32:dprintf_ver(stddeb,"PM32");break;
271 default:dprintf_ver(stddeb,"UNKNOWN(%ld)",vffi->dwFileOS&0xFFFF);break;
273 switch (vffi->dwFileType) {
274 default:
275 case VFT_UNKNOWN:
276 dprintf_ver(stddeb,"filetype=Unknown(%ld)",vffi->dwFileType);
277 break;
278 case VFT_APP:dprintf_ver(stddeb,"filetype=APP");break;
279 case VFT_DLL:dprintf_ver(stddeb,"filetype=DLL");break;
280 case VFT_DRV:
281 dprintf_ver(stddeb,"filetype=DRV,");
282 switch(vffi->dwFileSubtype) {
283 default:
284 case VFT2_UNKNOWN:
285 dprintf_ver(stddeb,"UNKNOWN(%ld)",vffi->dwFileSubtype);
286 break;
287 case VFT2_DRV_PRINTER:
288 dprintf_ver(stddeb,"PRINTER");
289 break;
290 case VFT2_DRV_KEYBOARD:
291 dprintf_ver(stddeb,"KEYBOARD");
292 break;
293 case VFT2_DRV_LANGUAGE:
294 dprintf_ver(stddeb,"LANGUAGE");
295 break;
296 case VFT2_DRV_DISPLAY:
297 dprintf_ver(stddeb,"DISPLAY");
298 break;
299 case VFT2_DRV_MOUSE:
300 dprintf_ver(stddeb,"MOUSE");
301 break;
302 case VFT2_DRV_NETWORK:
303 dprintf_ver(stddeb,"NETWORK");
304 break;
305 case VFT2_DRV_SYSTEM:
306 dprintf_ver(stddeb,"SYSTEM");
307 break;
308 case VFT2_DRV_INSTALLABLE:
309 dprintf_ver(stddeb,"INSTALLABLE");
310 break;
311 case VFT2_DRV_SOUND:
312 dprintf_ver(stddeb,"SOUND");
313 break;
314 case VFT2_DRV_COMM:
315 dprintf_ver(stddeb,"COMM");
316 break;
317 case VFT2_DRV_INPUTMETHOD:
318 dprintf_ver(stddeb,"INPUTMETHOD");
319 break;
321 break;
322 case VFT_FONT:
323 dprintf_ver(stddeb,"filetype=FONT.");
324 switch (vffi->dwFileSubtype) {
325 default:
326 dprintf_ver(stddeb,"UNKNOWN(%ld)",vffi->dwFileSubtype);
327 break;
328 case VFT2_FONT_RASTER:dprintf_ver(stddeb,"RASTER");break;
329 case VFT2_FONT_VECTOR:dprintf_ver(stddeb,"VECTOR");break;
330 case VFT2_FONT_TRUETYPE:dprintf_ver(stddeb,"TRUETYPE");break;
332 break;
333 case VFT_VXD:dprintf_ver(stddeb,"filetype=VXD");break;
334 case VFT_STATIC_LIB:dprintf_ver(stddeb,"filetype=STATIC_LIB");break;
336 dprintf_ver(stddeb,"filedata=%lx.%lx\n",vffi->dwFileDateMS,vffi->dwFileDateLS);
337 return len;
340 /* GetFileVersionInfoSize32A [VERSION.1] */
341 DWORD
342 GetFileVersionInfoSize32A(LPCSTR filename,LPDWORD handle) {
343 dprintf_ver(stddeb,"GetFileVersionInfoSize32A(%s,%p)\n",filename,handle);
344 return GetFileVersionInfoSize16(filename,handle);
347 /* GetFileVersionInfoSize32W [VERSION.2] */
348 DWORD GetFileVersionInfoSize32W( LPCWSTR filename, LPDWORD handle )
350 LPSTR xfn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
351 DWORD ret = GetFileVersionInfoSize16( xfn, handle );
352 HeapFree( GetProcessHeap(), 0, xfn );
353 return ret;
356 /* GetFileVersionInfo [VER.7] */
357 DWORD
358 GetFileVersionInfo16(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data) {
359 dprintf_ver(stddeb,"GetFileVersionInfo16(%s,%ld,%ld,%p)\n->",
360 filename,handle,datasize,data
362 return GetFileResource(
363 filename,VS_FILE_INFO,VS_VERSION_INFO,handle,datasize,data
367 /* GetFileVersionInfoA [VERSION.0] */
368 DWORD
369 GetFileVersionInfo32A(LPCSTR filename,DWORD handle,DWORD datasize,LPVOID data) {
370 return GetFileVersionInfo16(filename,handle,datasize,data);
373 /* GetFileVersionInfoW [VERSION.3] */
374 DWORD GetFileVersionInfo32W( LPCWSTR filename, DWORD handle, DWORD datasize,
375 LPVOID data)
377 LPSTR fn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
378 DWORD ret = GetFileVersionInfo16( fn, handle, datasize, data );
379 HeapFree( GetProcessHeap(), 0, fn );
380 return ret;
383 /* VerFindFile [VER.8] */
384 DWORD
385 VerFindFile16(
386 UINT16 flags,LPCSTR filename,LPCSTR windir,LPCSTR appdir,
387 LPSTR curdir,UINT16 *curdirlen,LPSTR destdir,UINT16 *destdirlen
389 dprintf_ver(stddeb,"VerFindFile(%x,%s,%s,%s,%p,%d,%p,%d)\n",
390 flags,filename,windir,appdir,curdir,*curdirlen,destdir,*destdirlen
392 strcpy(curdir,"Z:\\ROOT\\.WINE\\");/*FIXME*/
393 *curdirlen=strlen(curdir);
394 strcpy(destdir,"Z:\\ROOT\\.WINE\\");/*FIXME*/
395 *destdirlen=strlen(destdir);
396 return 0;
399 /* VerFindFileA [VERSION.5] */
400 DWORD
401 VerFindFile32A(
402 UINT32 flags,LPCSTR filename,LPCSTR windir,LPCSTR appdir,
403 LPSTR curdir,UINT32 *pcurdirlen,LPSTR destdir,UINT32 *pdestdirlen )
405 UINT16 curdirlen, destdirlen;
406 DWORD ret = VerFindFile16(flags,filename,windir,appdir,
407 curdir,&curdirlen,destdir,&destdirlen);
408 *pcurdirlen = curdirlen;
409 *pdestdirlen = destdirlen;
410 return ret;
413 /* VerFindFileW [VERSION.6] */
414 DWORD
415 VerFindFile32W(
416 UINT32 flags,LPCWSTR filename,LPCWSTR windir,LPCWSTR appdir,
417 LPWSTR curdir,UINT32 *pcurdirlen,LPWSTR destdir,UINT32 *pdestdirlen )
419 UINT16 curdirlen, destdirlen;
420 LPSTR wfn,wwd,wad,wdd,wcd;
421 DWORD ret;
423 wfn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
424 wwd = HEAP_strdupWtoA( GetProcessHeap(), 0, windir );
425 wad = HEAP_strdupWtoA( GetProcessHeap(), 0, appdir );
426 wcd = HeapAlloc( GetProcessHeap(), 0, *pcurdirlen );
427 wdd = HeapAlloc( GetProcessHeap(), 0, *pdestdirlen );
428 ret = VerFindFile16(flags,wfn,wwd,wad,wcd,&curdirlen,wdd,&destdirlen);
429 lstrcpynAtoW(curdir,wcd,*pcurdirlen);
430 lstrcpynAtoW(destdir,wdd,*pdestdirlen);
431 *pcurdirlen = strlen(wcd);
432 *pdestdirlen = strlen(wdd);
433 HeapFree( GetProcessHeap(), 0, wfn );
434 HeapFree( GetProcessHeap(), 0, wwd );
435 HeapFree( GetProcessHeap(), 0, wad );
436 HeapFree( GetProcessHeap(), 0, wcd );
437 HeapFree( GetProcessHeap(), 0, wdd );
438 return ret;
441 /* VerInstallFile [VER.9] */
442 DWORD
443 VerInstallFile16(
444 UINT16 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
445 LPCSTR destdir,LPSTR tmpfile,UINT16 *tmpfilelen
447 dprintf_ver(stddeb,"VerInstallFile(%x,%s,%s,%s,%s,%p,%d)\n",
448 flags,srcfilename,destfilename,srcdir,destdir,tmpfile,*tmpfilelen
451 /* FIXME: Implementation still missing .... */
453 return VIF_SRCOLD;
456 /* VerFindFileA [VERSION.5] */
457 DWORD
458 VerInstallFile32A(
459 UINT32 flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
460 LPCSTR destdir,LPSTR tmpfile,UINT32 *tmpfilelen )
462 UINT16 filelen;
463 DWORD ret= VerInstallFile16(flags,srcfilename,destfilename,srcdir,
464 destdir,tmpfile,&filelen);
465 *tmpfilelen = filelen;
466 return ret;
469 /* VerFindFileW [VERSION.6] */
470 DWORD
471 VerInstallFile32W(
472 UINT32 flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
473 LPCWSTR destdir,LPWSTR tmpfile,UINT32 *tmpfilelen )
475 LPSTR wsrcf,wsrcd,wdestf,wdestd,wtmpf;
476 DWORD ret;
478 wsrcf = HEAP_strdupWtoA( GetProcessHeap(), 0, srcfilename );
479 wsrcd = HEAP_strdupWtoA( GetProcessHeap(), 0, srcdir );
480 wdestf = HEAP_strdupWtoA( GetProcessHeap(), 0, destfilename );
481 wdestd = HEAP_strdupWtoA( GetProcessHeap(), 0, destdir );
482 wtmpf = HEAP_strdupWtoA( GetProcessHeap(), 0, tmpfile );
483 ret = VerInstallFile32A(flags,wsrcf,wdestf,wsrcd,wdestd,wtmpf,tmpfilelen);
484 HeapFree( GetProcessHeap(), 0, wsrcf );
485 HeapFree( GetProcessHeap(), 0, wsrcd );
486 HeapFree( GetProcessHeap(), 0, wdestf );
487 HeapFree( GetProcessHeap(), 0, wdestd );
488 HeapFree( GetProcessHeap(), 0, wtmpf );
489 return ret;
492 /* FIXME: This table should, of course, be language dependend */
493 static const struct map_id2str {
494 UINT langid;
495 const char *langname;
496 } languages[]={
497 {0x0401,"Arabisch"},
498 {0x0402,"Bulgarisch"},
499 {0x0403,"Katalanisch"},
500 {0x0404,"Traditionales Chinesisch"},
501 {0x0405,"Tschecisch"},
502 {0x0406,"Dänisch"},
503 {0x0407,"Deutsch"},
504 {0x0408,"Griechisch"},
505 {0x0409,"Amerikanisches Englisch"},
506 {0x040A,"Kastilisches Spanisch"},
507 {0x040B,"Finnisch"},
508 {0x040C,"Französisch"},
509 {0x040D,"Hebräisch"},
510 {0x040E,"Ungarisch"},
511 {0x040F,"Isländisch"},
512 {0x0410,"Italienisch"},
513 {0x0411,"Japanisch"},
514 {0x0412,"Koreanisch"},
515 {0x0413,"Niederländisch"},
516 {0x0414,"Norwegisch-Bokmal"},
517 {0x0415,"Polnisch"},
518 {0x0416,"Brasilianisches Portugiesisch"},
519 {0x0417,"Rätoromanisch"},
520 {0x0418,"Rumänisch"},
521 {0x0419,"Russisch"},
522 {0x041A,"Kroatoserbisch (lateinisch)"},
523 {0x041B,"Slowenisch"},
524 {0x041C,"Albanisch"},
525 {0x041D,"Schwedisch"},
526 {0x041E,"Thai"},
527 {0x041F,"Türkisch"},
528 {0x0420,"Urdu"},
529 {0x0421,"Bahasa"},
530 {0x0804,"Vereinfachtes Chinesisch"},
531 {0x0807,"Schweizerdeutsch"},
532 {0x0809,"Britisches Englisch"},
533 {0x080A,"Mexikanisches Spanisch"},
534 {0x080C,"Belgisches Französisch"},
535 {0x0810,"Schweizerisches Italienisch"},
536 {0x0813,"Belgisches Niederländisch"},
537 {0x0814,"Norgwegisch-Nynorsk"},
538 {0x0816,"Portugiesisch"},
539 {0x081A,"Serbokratisch (kyrillisch)"},
540 {0x0C1C,"Kanadisches Französisch"},
541 {0x100C,"Schweizerisches Französisch"},
542 {0x0000,"Unbekannt"},
545 /* VerLanguageName [VER.10] */
546 DWORD
547 VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen) {
548 int i;
549 char *buf;
551 dprintf_ver(stddeb,"VerLanguageName(%d,%p,%d)\n",langid,langname,langnamelen);
552 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
553 * from the registry.
555 buf=(char*)malloc(strlen("\\System\\CurrentControlSet\\control\\Nls\\Locale\\")+9);
556 sprintf(buf,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",langid);
557 if (ERROR_SUCCESS==RegQueryValue16(HKEY_LOCAL_MACHINE,buf,langname,(LPDWORD)&langnamelen)) {
558 langname[langnamelen-1]='\0';
559 return langnamelen;
561 /* if that fails, use the interal table */
562 for (i=0;languages[i].langid!=0;i++)
563 if (langid==languages[i].langid)
564 break;
565 strncpy(langname,languages[i].langname,langnamelen);
566 langname[langnamelen-1]='\0';
567 return strlen(languages[i].langname);
570 /* VerLanguageNameA [VERSION.9] */
571 DWORD
572 VerLanguageName32A(UINT32 langid,LPSTR langname,UINT32 langnamelen) {
573 return VerLanguageName16(langid,langname,langnamelen);
576 /* VerLanguageNameW [VERSION.10] */
577 DWORD
578 VerLanguageName32W(UINT32 langid,LPWSTR langname,UINT32 langnamelen) {
579 int i;
580 char buffer[80];
581 LPWSTR keyname;
583 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
584 * from the registry.
586 sprintf(buffer,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",langid);
587 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
588 if (ERROR_SUCCESS==RegQueryValue32W(HKEY_LOCAL_MACHINE,keyname,langname,(LPDWORD)&langnamelen)) {
589 HeapFree( GetProcessHeap(), 0, keyname );
590 return langnamelen;
592 HeapFree( GetProcessHeap(), 0, keyname );
593 /* if that fails, use the interal table */
594 for (i=0;languages[i].langid!=0;i++)
595 if (langid==languages[i].langid)
596 break;
597 lstrcpyAtoW( langname, languages[i].langname );
598 return strlen(languages[i].langname); /* same as strlenW(langname); */
601 /* FIXME: UNICODE? */
602 struct db {
603 WORD nextoff;
604 WORD datalen;
605 /* in memory structure... */
606 char name[1]; /* padded to dword alignment */
607 /* ....
608 char data[datalen]; padded to dword alignemnt
609 BYTE subdirdata[]; until nextoff
613 static BYTE*
614 _find_data(BYTE *block,LPCSTR str) {
615 char *nextslash;
616 int substrlen;
617 struct db *db;
619 while (*str && *str=='\\')
620 str++;
621 if (NULL!=(nextslash=strchr(str,'\\')))
622 substrlen=nextslash-str;
623 else
624 substrlen=strlen(str);
625 if (nextslash!=NULL) {
626 while (*nextslash && *nextslash=='\\')
627 nextslash++;
628 if (!*nextslash)
629 nextslash=NULL;
633 while (1) {
634 db=(struct db*)block;
635 dprintf_ver(stddeb,"db=%p,db->nextoff=%d,db->datalen=%d,db->name=%s,db->data=%s\n",
636 db,db->nextoff,db->datalen,db->name,(char*)((char*)db+4+((strlen(db->name)+4)&~3))
638 if (!db->nextoff)
639 return NULL;
641 dprintf_ver(stddeb,"comparing with %s\n",db->name);
642 if (!strncmp(db->name,str,substrlen)) {
643 if (nextslash)
644 return _find_data(
645 block+4+((strlen(db->name)+4)&~3)+((db->datalen+3)&~3)
646 ,nextslash
648 else
649 return block;
651 block=block+((db->nextoff+3)&~3);
655 /* VerQueryValue [VER.11] */
656 /* take care, 'buffer' is NOT a SEGPTR, it just points to one */
657 DWORD
658 VerQueryValue16(SEGPTR segblock,LPCSTR subblock,SEGPTR *buffer,UINT16 *buflen)
660 BYTE *block=PTR_SEG_TO_LIN(segblock),*b;
661 struct db *db;
662 char *s;
664 dprintf_ver(stddeb,"VerQueryValue16(%p,%s,%p,%d)\n",
665 block,subblock,buffer,*buflen
667 s=(char*)xmalloc(strlen("VS_VERSION_INFO\\")+strlen(subblock)+1);
668 strcpy(s,"VS_VERSION_INFO\\");strcat(s,subblock);
669 b=_find_data(block,s);
670 if (b==NULL) {
671 *buflen=0;
672 return 0;
674 db=(struct db*)b;
675 *buflen = db->datalen;
676 /* let b point to data area */
677 b = b+4+((strlen(db->name)+4)&~3);
678 /* now look up what the resp. SEGPTR would be ... */
679 *buffer = (b-block)+segblock;
680 dprintf_ver(stddeb," -> %s=%s\n",subblock,b);
681 return 1;
684 DWORD
685 VerQueryValue32A(LPVOID vblock,LPCSTR subblock,LPVOID *vbuffer,UINT32 *buflen)
687 BYTE *b,*block=(LPBYTE)vblock,**buffer=(LPBYTE*)vbuffer;
688 struct db *db;
689 char *s;
691 dprintf_ver(stddeb,"VerQueryValue32A(%p,%s,%p,%d)\n",
692 block,subblock,buffer,*buflen
694 s=(char*)xmalloc(strlen("VS_VERSION_INFO\\")+strlen(subblock)+1);
695 strcpy(s,"VS_VERSION_INFO\\");strcat(s,subblock);
696 b=_find_data(block,s);
697 if (b==NULL) {
698 *buflen=0;
699 return 0;
701 db=(struct db*)b;
702 *buflen = db->datalen;
703 /* let b point to data area */
704 b = b+4+((strlen(db->name)+4)&~3);
705 *buffer = b;
706 dprintf_ver(stddeb," -> %s=%s\n",subblock,b);
707 return 1;
710 DWORD
711 VerQueryValue32W(LPVOID vblock,LPCWSTR subblock,LPVOID *vbuffer,UINT32 *buflen)
713 /* FIXME: hmm, we not only need to convert subblock, but also
714 * the content...or?
715 * And what about UNICODE version info?
716 * And the NAMES of the values?
718 BYTE *b,**buffer=(LPBYTE*)vbuffer,*block=(LPBYTE)vblock;
719 struct db *db;
720 char *s,*sb;
722 sb = HEAP_strdupWtoA( GetProcessHeap(), 0, subblock );
723 s=(char*)xmalloc(strlen("VS_VERSION_INFO\\")+strlen(sb)+1);
724 strcpy(s,"VS_VERSION_INFO\\");strcat(s,sb);
725 b=_find_data(block,s);
726 if (b==NULL) {
727 *buflen=0;
728 HeapFree( GetProcessHeap(), 0, sb );
729 return 0;
731 db=(struct db*)b;
732 *buflen = db->datalen;
733 /* let b point to data area */
734 b = b+4+((strlen(db->name)+4)&~3);
735 *buffer = b;
736 dprintf_ver(stddeb," -> %s=%s\n",sb,b);
737 HeapFree( GetProcessHeap(), 0, sb );
738 return 1;
740 /* 20 GETFILEVERSIONINFORAW */