version: Moved GetFileResourceSize16/GetFileResource16 to ver16.c.
[wine/hacks.git] / dlls / version / ver16.c
blobf399cd2bad8d9e7a7fbd2c7fe5944db160c4f867
1 /*
2 * Implementation of VER.DLL
4 * Copyright 1999 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "wine/winbase16.h"
25 #include "winver.h"
26 #include "lzexpand.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ver);
32 extern DWORD find_resource( HFILE lzfd, LPCSTR type, LPCSTR id, DWORD *reslen, DWORD *offset );
34 /*************************************************************************
35 * GetFileResourceSize [VER.2]
37 DWORD WINAPI GetFileResourceSize16( LPCSTR lpszFileName, LPCSTR lpszResType,
38 LPCSTR lpszResId, LPDWORD lpdwFileOffset )
40 HFILE lzfd;
41 OFSTRUCT ofs;
42 DWORD reslen = 0;
44 TRACE("(%s,type=%p,id=%p,off=%p)\n",
45 debugstr_a(lpszFileName), lpszResType, lpszResId, lpszResId );
47 lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
48 if (lzfd >= 0)
50 if (!find_resource( lzfd, lpszResType, lpszResId, &reslen, lpdwFileOffset )) reslen = 0;
51 LZClose( lzfd );
53 return reslen;
57 /*************************************************************************
58 * GetFileResource [VER.3]
60 DWORD WINAPI GetFileResource16( LPCSTR lpszFileName, LPCSTR lpszResType,
61 LPCSTR lpszResId, DWORD dwFileOffset,
62 DWORD dwResLen, LPVOID lpvData )
64 HFILE lzfd;
65 OFSTRUCT ofs;
66 DWORD reslen = dwResLen;
68 TRACE("(%s,type=%p,id=%p,off=%d,len=%d,data=%p)\n",
69 debugstr_a(lpszFileName), lpszResType, lpszResId,
70 dwFileOffset, dwResLen, lpvData );
72 lzfd = LZOpenFileA( (LPSTR)lpszFileName, &ofs, OF_READ );
73 if ( lzfd < 0 ) return 0;
75 if ( !dwFileOffset )
77 if (!find_resource( lzfd, lpszResType, lpszResId, &reslen, &dwFileOffset ))
79 LZClose( lzfd );
80 return 0;
84 LZSeek( lzfd, dwFileOffset, 0 /* SEEK_SET */ );
85 reslen = LZRead( lzfd, lpvData, min( reslen, dwResLen ) );
86 LZClose( lzfd );
88 return reslen;
91 /*************************************************************************
92 * GetFileVersionInfoSize [VER.6]
94 DWORD WINAPI GetFileVersionInfoSize16( LPCSTR lpszFileName, LPDWORD lpdwHandle )
96 TRACE("(%s, %p)\n", debugstr_a(lpszFileName), lpdwHandle );
97 return GetFileVersionInfoSizeA( lpszFileName, lpdwHandle );
100 /*************************************************************************
101 * GetFileVersionInfo [VER.7]
103 DWORD WINAPI GetFileVersionInfo16( LPCSTR lpszFileName, DWORD handle,
104 DWORD cbBuf, LPVOID lpvData )
106 TRACE("(%s, %08x, %d, %p)\n",
107 debugstr_a(lpszFileName), handle, cbBuf, lpvData );
109 return GetFileVersionInfoA( lpszFileName, handle, cbBuf, lpvData );
112 /*************************************************************************
113 * VerFindFile [VER.8]
115 DWORD WINAPI VerFindFile16( UINT16 flags, LPSTR lpszFilename,
116 LPSTR lpszWinDir, LPSTR lpszAppDir,
117 LPSTR lpszCurDir, UINT16 *lpuCurDirLen,
118 LPSTR lpszDestDir, UINT16 *lpuDestDirLen )
120 UINT curDirLen, destDirLen;
121 DWORD retv = VerFindFileA( flags, lpszFilename, lpszWinDir, lpszAppDir,
122 lpszCurDir, &curDirLen, lpszDestDir, &destDirLen );
124 *lpuCurDirLen = (UINT16)curDirLen;
125 *lpuDestDirLen = (UINT16)destDirLen;
126 return retv;
129 /*************************************************************************
130 * VerInstallFile [VER.9]
132 DWORD WINAPI VerInstallFile16( UINT16 flags,
133 LPSTR lpszSrcFilename, LPSTR lpszDestFilename,
134 LPSTR lpszSrcDir, LPSTR lpszDestDir, LPSTR lpszCurDir,
135 LPSTR lpszTmpFile, UINT16 *lpwTmpFileLen )
137 UINT filelen;
138 DWORD retv = VerInstallFileA( flags, lpszSrcFilename, lpszDestFilename,
139 lpszSrcDir, lpszDestDir, lpszCurDir,
140 lpszTmpFile, &filelen);
142 *lpwTmpFileLen = (UINT16)filelen;
143 return retv;
146 /*************************************************************************
147 * VerLanguageName [VER.10]
149 DWORD WINAPI VerLanguageName16( UINT16 uLang, LPSTR lpszLang, UINT16 cbLang )
151 return VerLanguageNameA( uLang, lpszLang, cbLang );
154 /*************************************************************************
155 * VerQueryValue [VER.11]
157 DWORD WINAPI VerQueryValue16( SEGPTR spvBlock, LPSTR lpszSubBlock,
158 SEGPTR *lpspBuffer, UINT16 *lpcb )
160 LPVOID lpvBlock = MapSL( spvBlock );
161 LPVOID buffer = lpvBlock;
162 UINT buflen;
163 DWORD retv;
165 TRACE("(%p, %s, %p, %p)\n",
166 lpvBlock, debugstr_a(lpszSubBlock), lpspBuffer, lpcb );
168 retv = VerQueryValueA( lpvBlock, lpszSubBlock, &buffer, &buflen );
169 if ( !retv ) return FALSE;
171 if ( OFFSETOF( spvBlock ) + ((char *) buffer - (char *) lpvBlock) >= 0x10000 )
173 FIXME("offset %08X too large relative to %04X:%04X\n",
174 (char *) buffer - (char *) lpvBlock, SELECTOROF( spvBlock ), OFFSETOF( spvBlock ) );
175 return FALSE;
178 if (lpcb) *lpcb = buflen;
179 *lpspBuffer = (SEGPTR) ((char *) spvBlock + ((char *) buffer - (char *) lpvBlock));
181 return retv;