1 | /* $Id: install.c,v 1.2 2000-01-08 14:27:33 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Implementation of VERSION.DLL - File Installer routines (Wine 991212)
|
---|
4 | *
|
---|
5 | * Copyright 1996,1997 Marcus Meissner
|
---|
6 | * Copyright 1997 David Cuthbert
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include <stdlib.h>
|
---|
10 | #include <string.h>
|
---|
11 |
|
---|
12 | #include "windef.h"
|
---|
13 | #include "winver.h"
|
---|
14 | #include "wine/winestring.h"
|
---|
15 | #include "winerror.h"
|
---|
16 | #include "heap.h"
|
---|
17 | #include "lzexpand.h"
|
---|
18 | #include "xmalloc.h"
|
---|
19 | #include "debugtools.h"
|
---|
20 | #include <misc.h>
|
---|
21 |
|
---|
22 | DEFAULT_DEBUG_CHANNEL(ver)
|
---|
23 |
|
---|
24 |
|
---|
25 | /******************************************************************************
|
---|
26 | *
|
---|
27 | * void ver_dstring(
|
---|
28 | * char const * prologue,
|
---|
29 | * char const * teststring,
|
---|
30 | * char const * epilogue )
|
---|
31 | *
|
---|
32 | * This function will print via dprintf[_]ver to stddeb the prologue string,
|
---|
33 | * followed by the address of teststring and the string it contains if
|
---|
34 | * teststring is non-null or "(null)" otherwise, and then the epilogue
|
---|
35 | * string followed by a new line.
|
---|
36 | *
|
---|
37 | * Revision history
|
---|
38 | * 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
---|
39 | * Original implementation as dprintf[_]ver_string
|
---|
40 | * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
---|
41 | * Fixed problem that caused bug with tools/make_debug -- renaming
|
---|
42 | * this function should fix the problem.
|
---|
43 | * 15-Feb-1998 Dimitrie Paun (dimi@cs.toronto.edu)
|
---|
44 | * Modified it to make it print the message using only one
|
---|
45 | * dprintf[_]ver call.
|
---|
46 | *
|
---|
47 | *****************************************************************************/
|
---|
48 |
|
---|
49 | static void ver_dstring(
|
---|
50 | char const * prologue,
|
---|
51 | char const * teststring,
|
---|
52 | char const * epilogue )
|
---|
53 | {
|
---|
54 | TRACE("%s %p (\"%s\") %s\n", prologue,
|
---|
55 | (void const *) teststring,
|
---|
56 | teststring ? teststring : "(null)",
|
---|
57 | epilogue);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /******************************************************************************
|
---|
61 | *
|
---|
62 | * int testFileExistence(
|
---|
63 | * char const * path,
|
---|
64 | * char const * file )
|
---|
65 | *
|
---|
66 | * Tests whether a given path/file combination exists. If the file does
|
---|
67 | * not exist, the return value is zero. If it does exist, the return
|
---|
68 | * value is non-zero.
|
---|
69 | *
|
---|
70 | * Revision history
|
---|
71 | * 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
---|
72 | * Original implementation
|
---|
73 | *
|
---|
74 | *****************************************************************************/
|
---|
75 |
|
---|
76 | static int testFileExistence(
|
---|
77 | char const * path,
|
---|
78 | char const * file )
|
---|
79 | {
|
---|
80 | char filename[1024];
|
---|
81 | int filenamelen;
|
---|
82 | OFSTRUCT fileinfo;
|
---|
83 | int retval;
|
---|
84 |
|
---|
85 | fileinfo.cBytes = sizeof(OFSTRUCT);
|
---|
86 |
|
---|
87 | strcpy(filename, path);
|
---|
88 | filenamelen = strlen(filename);
|
---|
89 |
|
---|
90 | /* Add a trailing \ if necessary */
|
---|
91 | if(filenamelen) {
|
---|
92 | if(filename[filenamelen - 1] != '\\')
|
---|
93 | strcat(filename, "\\");
|
---|
94 | }
|
---|
95 | else /* specify the current directory */
|
---|
96 | strcpy(filename, ".\\");
|
---|
97 |
|
---|
98 | /* Create the full pathname */
|
---|
99 | strcat(filename, file);
|
---|
100 |
|
---|
101 | if(OpenFile(filename, &fileinfo, OF_EXIST) == HFILE_ERROR)
|
---|
102 | retval = 0;
|
---|
103 | else
|
---|
104 | retval = 1;
|
---|
105 |
|
---|
106 | return retval;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /******************************************************************************
|
---|
110 | *
|
---|
111 | * int testFileExclusiveExistence(
|
---|
112 | * char const * path,
|
---|
113 | * char const * file )
|
---|
114 | *
|
---|
115 | * Tests whether a given path/file combination exists and ensures that no
|
---|
116 | * other programs have handles to the given file. If the file does not
|
---|
117 | * exist or is open, the return value is zero. If it does exist, the
|
---|
118 | * return value is non-zero.
|
---|
119 | *
|
---|
120 | * Revision history
|
---|
121 | * 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
---|
122 | * Original implementation
|
---|
123 | *
|
---|
124 | *****************************************************************************/
|
---|
125 |
|
---|
126 | static int testFileExclusiveExistence(
|
---|
127 | char const * path,
|
---|
128 | char const * file )
|
---|
129 | {
|
---|
130 | char filename[1024];
|
---|
131 | int filenamelen;
|
---|
132 | OFSTRUCT fileinfo;
|
---|
133 | int retval;
|
---|
134 |
|
---|
135 | fileinfo.cBytes = sizeof(OFSTRUCT);
|
---|
136 |
|
---|
137 | strcpy(filename, path);
|
---|
138 | filenamelen = strlen(filename);
|
---|
139 |
|
---|
140 | /* Add a trailing \ if necessary */
|
---|
141 | if(filenamelen) {
|
---|
142 | if(filename[filenamelen - 1] != '\\')
|
---|
143 | strcat(filename, "\\");
|
---|
144 | }
|
---|
145 | else /* specify the current directory */
|
---|
146 | strcpy(filename, ".\\");
|
---|
147 |
|
---|
148 | /* Create the full pathname */
|
---|
149 | strcat(filename, file);
|
---|
150 |
|
---|
151 | if(OpenFile(filename, &fileinfo, OF_EXIST | OF_SHARE_EXCLUSIVE) ==
|
---|
152 | HFILE_ERROR)
|
---|
153 | retval = 0;
|
---|
154 | else
|
---|
155 | retval = 1;
|
---|
156 |
|
---|
157 | return retval;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /*****************************************************************************
|
---|
161 | *
|
---|
162 | * VerFindFile() [VER.8]
|
---|
163 | * Determines where to install a file based on whether it locates another
|
---|
164 | * version of the file in the system. The values VerFindFile returns are
|
---|
165 | * used in a subsequent call to the VerInstallFile function.
|
---|
166 | *
|
---|
167 | * Revision history:
|
---|
168 | * 30-May-1997 Dave Cuthbert (dacut@ece.cmu.edu)
|
---|
169 | * Reimplementation of VerFindFile from original stub.
|
---|
170 | *
|
---|
171 | ****************************************************************************/
|
---|
172 |
|
---|
173 | /* VerFindFile32A [VERSION.5] */
|
---|
174 | DWORD WINAPI VerFindFileA(
|
---|
175 | UINT flags,
|
---|
176 | LPCSTR lpszFilename,
|
---|
177 | LPCSTR lpszWinDir,
|
---|
178 | LPCSTR lpszAppDir,
|
---|
179 | LPSTR lpszCurDir,
|
---|
180 | UINT *lpuCurDirLen,
|
---|
181 | LPSTR lpszDestDir,
|
---|
182 | UINT *lpuDestDirLen )
|
---|
183 | {
|
---|
184 | DWORD retval;
|
---|
185 | char curDir[256];
|
---|
186 | char destDir[256];
|
---|
187 | unsigned int curDirSizeReq;
|
---|
188 | unsigned int destDirSizeReq;
|
---|
189 |
|
---|
190 | retval = 0;
|
---|
191 |
|
---|
192 | /* Print out debugging information */
|
---|
193 | TRACE("called with parameters:\n"
|
---|
194 | "\tflags = %x", flags);
|
---|
195 | if(flags & VFFF_ISSHAREDFILE)
|
---|
196 | TRACE(" (VFFF_ISSHAREDFILE)\n");
|
---|
197 | else
|
---|
198 | TRACE("\n");
|
---|
199 |
|
---|
200 | ver_dstring("\tlpszFilename = ", lpszFilename, "");
|
---|
201 | ver_dstring("\tlpszWinDir = ", lpszWinDir, "");
|
---|
202 | ver_dstring("\tlpszAppDir = ", lpszAppDir, "");
|
---|
203 |
|
---|
204 | TRACE("\tlpszCurDir = %p\n", lpszCurDir);
|
---|
205 | if(lpuCurDirLen)
|
---|
206 | TRACE("\tlpuCurDirLen = %p (%u)\n",
|
---|
207 | lpuCurDirLen, *lpuCurDirLen);
|
---|
208 | else
|
---|
209 | TRACE("\tlpuCurDirLen = (null)\n");
|
---|
210 |
|
---|
211 | TRACE("\tlpszDestDir = %p\n", lpszDestDir);
|
---|
212 | if(lpuDestDirLen)
|
---|
213 | TRACE("\tlpuDestDirLen = %p (%u)\n",
|
---|
214 | lpuDestDirLen, *lpuDestDirLen);
|
---|
215 |
|
---|
216 | /* Figure out where the file should go; shared files default to the
|
---|
217 | system directory */
|
---|
218 |
|
---|
219 | strcpy(curDir, "");
|
---|
220 | strcpy(destDir, "");
|
---|
221 |
|
---|
222 | if(flags & VFFF_ISSHAREDFILE) {
|
---|
223 | GetSystemDirectoryA(destDir, 256);
|
---|
224 |
|
---|
225 | /* Were we given a filename? If so, try to find the file. */
|
---|
226 | if(lpszFilename) {
|
---|
227 | if(testFileExistence(destDir, lpszFilename)) {
|
---|
228 | strcpy(curDir, destDir);
|
---|
229 |
|
---|
230 | if(!testFileExclusiveExistence(destDir, lpszFilename))
|
---|
231 | retval |= VFF_FILEINUSE;
|
---|
232 | }
|
---|
233 | else if(lpszAppDir && testFileExistence(lpszAppDir,
|
---|
234 | lpszFilename)) {
|
---|
235 | strcpy(curDir, lpszAppDir);
|
---|
236 | retval |= VFF_CURNEDEST;
|
---|
237 |
|
---|
238 | if(!testFileExclusiveExistence(lpszAppDir, lpszFilename))
|
---|
239 | retval |= VFF_FILEINUSE;
|
---|
240 | }
|
---|
241 | }
|
---|
242 | }
|
---|
243 | else if(!(flags & VFFF_ISSHAREDFILE)) { /* not a shared file */
|
---|
244 | if(lpszAppDir) {
|
---|
245 | char systemDir[256];
|
---|
246 | GetSystemDirectoryA(systemDir, 256);
|
---|
247 |
|
---|
248 | strcpy(destDir, lpszAppDir);
|
---|
249 |
|
---|
250 | if(lpszFilename) {
|
---|
251 | if(testFileExistence(lpszAppDir, lpszFilename)) {
|
---|
252 | strcpy(curDir, lpszAppDir);
|
---|
253 |
|
---|
254 | if(!testFileExclusiveExistence(lpszAppDir, lpszFilename))
|
---|
255 | retval |= VFF_FILEINUSE;
|
---|
256 | }
|
---|
257 | else if(testFileExistence(systemDir, lpszFilename)) {
|
---|
258 | strcpy(curDir, systemDir);
|
---|
259 | retval |= VFF_CURNEDEST;
|
---|
260 |
|
---|
261 | if(!testFileExclusiveExistence(systemDir, lpszFilename))
|
---|
262 | retval |= VFF_FILEINUSE;
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | curDirSizeReq = strlen(curDir) + 1;
|
---|
269 | destDirSizeReq = strlen(destDir) + 1;
|
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 | /* Make sure that the pointers to the size of the buffers are
|
---|
274 | valid; if not, do NOTHING with that buffer. If that pointer
|
---|
275 | is valid, then make sure that the buffer pointer is valid, too! */
|
---|
276 |
|
---|
277 | if(lpuDestDirLen && lpszDestDir) {
|
---|
278 | if(*lpuDestDirLen < destDirSizeReq) {
|
---|
279 | retval |= VFF_BUFFTOOSMALL;
|
---|
280 | if (*lpuDestDirLen) {
|
---|
281 | lstrcpynA(lpszDestDir, destDir, *lpuDestDirLen);
|
---|
282 | }
|
---|
283 | }
|
---|
284 | else
|
---|
285 | strcpy(lpszDestDir, destDir);
|
---|
286 |
|
---|
287 | *lpuDestDirLen = destDirSizeReq;
|
---|
288 | }
|
---|
289 |
|
---|
290 | if(lpuCurDirLen && lpszCurDir) {
|
---|
291 | if(*lpuCurDirLen < curDirSizeReq) {
|
---|
292 | retval |= VFF_BUFFTOOSMALL;
|
---|
293 | if (*lpuCurDirLen) {
|
---|
294 | lstrcpynA(lpszCurDir, curDir, *lpuCurDirLen);
|
---|
295 | }
|
---|
296 | }
|
---|
297 | else
|
---|
298 | strcpy(lpszCurDir, curDir);
|
---|
299 |
|
---|
300 | *lpuCurDirLen = curDirSizeReq;
|
---|
301 | }
|
---|
302 |
|
---|
303 | TRACE("ret = %lu (%s%s%s)\n", retval,
|
---|
304 | (retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
|
---|
305 | (retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
|
---|
306 | (retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "");
|
---|
307 |
|
---|
308 | ver_dstring("\t(Exit) lpszCurDir = ", lpszCurDir, "");
|
---|
309 | if(lpuCurDirLen)
|
---|
310 | TRACE("\t(Exit) lpuCurDirLen = %p (%u)\n",
|
---|
311 | lpuCurDirLen, *lpuCurDirLen);
|
---|
312 | else
|
---|
313 | TRACE("\t(Exit) lpuCurDirLen = (null)\n");
|
---|
314 |
|
---|
315 | ver_dstring("\t(Exit) lpszDestDir = ", lpszDestDir, "");
|
---|
316 | if(lpuDestDirLen)
|
---|
317 | TRACE("\t(Exit) lpuDestDirLen = %p (%u)\n",
|
---|
318 | lpuDestDirLen, *lpuDestDirLen);
|
---|
319 |
|
---|
320 | return retval;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /* VerFindFile32W [VERSION.6] */
|
---|
324 | DWORD WINAPI VerFindFileW(
|
---|
325 | UINT flags,LPCWSTR filename,LPCWSTR windir,LPCWSTR appdir,
|
---|
326 | LPWSTR curdir,UINT *pcurdirlen,LPWSTR destdir,UINT *pdestdirlen )
|
---|
327 | {
|
---|
328 | UINT curdirlen, destdirlen;
|
---|
329 | LPSTR wfn,wwd,wad,wdd,wcd;
|
---|
330 | DWORD ret;
|
---|
331 |
|
---|
332 | wfn = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
|
---|
333 | wwd = HEAP_strdupWtoA( GetProcessHeap(), 0, windir );
|
---|
334 | wad = HEAP_strdupWtoA( GetProcessHeap(), 0, appdir );
|
---|
335 | wcd = HeapAlloc( GetProcessHeap(), 0, *pcurdirlen );
|
---|
336 | wdd = HeapAlloc( GetProcessHeap(), 0, *pdestdirlen );
|
---|
337 | ret = VerFindFileA(flags,wfn,wwd,wad,wcd,&curdirlen,wdd,&destdirlen);
|
---|
338 | lstrcpynAtoW(curdir,wcd,*pcurdirlen);
|
---|
339 | lstrcpynAtoW(destdir,wdd,*pdestdirlen);
|
---|
340 | *pcurdirlen = strlen(wcd);
|
---|
341 | *pdestdirlen = strlen(wdd);
|
---|
342 | HeapFree( GetProcessHeap(), 0, wfn );
|
---|
343 | HeapFree( GetProcessHeap(), 0, wwd );
|
---|
344 | HeapFree( GetProcessHeap(), 0, wad );
|
---|
345 | HeapFree( GetProcessHeap(), 0, wcd );
|
---|
346 | HeapFree( GetProcessHeap(), 0, wdd );
|
---|
347 | return ret;
|
---|
348 | }
|
---|
349 |
|
---|
350 | static LPBYTE
|
---|
351 | _fetch_versioninfo(LPSTR fn,VS_FIXEDFILEINFO **vffi) {
|
---|
352 | DWORD alloclen;
|
---|
353 | LPBYTE buf;
|
---|
354 | DWORD ret;
|
---|
355 |
|
---|
356 | alloclen = 1000;
|
---|
357 | buf= xmalloc(alloclen);
|
---|
358 | while (1) {
|
---|
359 | ret = GetFileVersionInfoA(fn,0,alloclen,buf);
|
---|
360 | if (!ret) {
|
---|
361 | free(buf);
|
---|
362 | return 0;
|
---|
363 | }
|
---|
364 | if (alloclen<*(WORD*)buf) {
|
---|
365 | free(buf);
|
---|
366 | alloclen = *(WORD*)buf;
|
---|
367 | buf = xmalloc(alloclen);
|
---|
368 | } else {
|
---|
369 | *vffi = (VS_FIXEDFILEINFO*)(buf+0x14);
|
---|
370 | if ((*vffi)->dwSignature == 0x004f0049) /* hack to detect unicode */
|
---|
371 | *vffi = (VS_FIXEDFILEINFO*)(buf+0x28);
|
---|
372 | if ((*vffi)->dwSignature != VS_FFI_SIGNATURE)
|
---|
373 | WARN("Bad VS_FIXEDFILEINFO signature 0x%08lx\n",(*vffi)->dwSignature);
|
---|
374 | return buf;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | }
|
---|
378 |
|
---|
379 | static DWORD
|
---|
380 | _error2vif(DWORD error) {
|
---|
381 | switch (error) {
|
---|
382 | case ERROR_ACCESS_DENIED:
|
---|
383 | return VIF_ACCESSVIOLATION;
|
---|
384 | case ERROR_SHARING_VIOLATION:
|
---|
385 | return VIF_SHARINGVIOLATION;
|
---|
386 | default:
|
---|
387 | return 0;
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | /******************************************************************************
|
---|
393 | * VerInstallFile32A [VERSION.7]
|
---|
394 | */
|
---|
395 | DWORD WINAPI VerInstallFileA(
|
---|
396 | UINT flags,LPCSTR srcfilename,LPCSTR destfilename,LPCSTR srcdir,
|
---|
397 | LPCSTR destdir,LPCSTR curdir,LPSTR tmpfile,UINT *tmpfilelen )
|
---|
398 | {
|
---|
399 | LPCSTR pdest;
|
---|
400 | char destfn[260],tmpfn[260],srcfn[260];
|
---|
401 | HFILE hfsrc,hfdst;
|
---|
402 | DWORD attr,ret,xret,tmplast;
|
---|
403 | LPBYTE buf1,buf2;
|
---|
404 | OFSTRUCT ofs;
|
---|
405 |
|
---|
406 | TRACE("(%x,%s,%s,%s,%s,%s,%p,%d)\n",
|
---|
407 | flags,srcfilename,destfilename,srcdir,destdir,curdir,tmpfile,*tmpfilelen
|
---|
408 | );
|
---|
409 | xret = 0;
|
---|
410 | sprintf(srcfn,"%s\\%s",srcdir,srcfilename);
|
---|
411 | if (!destdir || !*destdir) pdest = srcdir;
|
---|
412 | else pdest = destdir;
|
---|
413 | sprintf(destfn,"%s\\%s",pdest,destfilename);
|
---|
414 | hfsrc=LZOpenFileA(srcfn,&ofs,OF_READ);
|
---|
415 | if (hfsrc==HFILE_ERROR)
|
---|
416 | return VIF_CANNOTREADSRC;
|
---|
417 | sprintf(tmpfn,"%s\\%s",pdest,destfilename);
|
---|
418 | tmplast=strlen(pdest)+1;
|
---|
419 | attr = GetFileAttributesA(tmpfn);
|
---|
420 | if (attr!=-1) {
|
---|
421 | if (attr & FILE_ATTRIBUTE_READONLY) {
|
---|
422 | LZClose(hfsrc);
|
---|
423 | return VIF_WRITEPROT;
|
---|
424 | }
|
---|
425 | /* FIXME: check if file currently in use and return VIF_FILEINUSE */
|
---|
426 | }
|
---|
427 | attr = -1;
|
---|
428 | if (flags & VIFF_FORCEINSTALL) {
|
---|
429 | if (tmpfile[0]) {
|
---|
430 | sprintf(tmpfn,"%s\\%s",pdest,tmpfile);
|
---|
431 | tmplast = strlen(pdest)+1;
|
---|
432 | attr = GetFileAttributesA(tmpfn);
|
---|
433 | /* if it exists, it has been copied by the call before.
|
---|
434 | * we jump over the copy part...
|
---|
435 | */
|
---|
436 | }
|
---|
437 | }
|
---|
438 | if (attr == -1) {
|
---|
439 | char *s;
|
---|
440 |
|
---|
441 | GetTempFileNameA(pdest,"ver",0,tmpfn); /* should not fail ... */
|
---|
442 | s=strrchr(tmpfn,'\\');
|
---|
443 | if (s)
|
---|
444 | tmplast = s-tmpfn;
|
---|
445 | else
|
---|
446 | tmplast = 0;
|
---|
447 | hfdst = OpenFile(tmpfn,&ofs,OF_CREATE);
|
---|
448 | if (hfdst == HFILE_ERROR) {
|
---|
449 | LZClose(hfsrc);
|
---|
450 | return VIF_CANNOTCREATE; /* | translated dos error */
|
---|
451 | }
|
---|
452 | ret = LZCopy(hfsrc,hfdst);
|
---|
453 | _lclose(hfdst);
|
---|
454 | if (((long) ret) < 0) {
|
---|
455 | /* translate LZ errors into VIF_xxx */
|
---|
456 | switch (ret) {
|
---|
457 | case LZERROR_BADINHANDLE:
|
---|
458 | case LZERROR_READ:
|
---|
459 | case LZERROR_BADVALUE:
|
---|
460 | case LZERROR_UNKNOWNALG:
|
---|
461 | ret = VIF_CANNOTREADSRC;
|
---|
462 | break;
|
---|
463 | case LZERROR_BADOUTHANDLE:
|
---|
464 | case LZERROR_WRITE:
|
---|
465 | ret = VIF_OUTOFMEMORY; /* FIXME: correct? */
|
---|
466 | break;
|
---|
467 | case LZERROR_GLOBALLOC:
|
---|
468 | case LZERROR_GLOBLOCK:
|
---|
469 | ret = VIF_OUTOFSPACE;
|
---|
470 | break;
|
---|
471 | default: /* unknown error, should not happen */
|
---|
472 | ret = 0;
|
---|
473 | break;
|
---|
474 | }
|
---|
475 | if (ret) {
|
---|
476 | LZClose(hfsrc);
|
---|
477 | return ret;
|
---|
478 | }
|
---|
479 | }
|
---|
480 | }
|
---|
481 | xret = 0;
|
---|
482 | if (!(flags & VIFF_FORCEINSTALL)) {
|
---|
483 | VS_FIXEDFILEINFO *destvffi,*tmpvffi;
|
---|
484 | buf1 = _fetch_versioninfo(destfn,&destvffi);
|
---|
485 | if (buf1) {
|
---|
486 | buf2 = _fetch_versioninfo(tmpfn,&tmpvffi);
|
---|
487 | if (buf2) {
|
---|
488 | char *tbuf1,*tbuf2;
|
---|
489 | UINT len1,len2;
|
---|
490 |
|
---|
491 | len1=len2=40;
|
---|
492 |
|
---|
493 | /* compare file versions */
|
---|
494 | if ((destvffi->dwFileVersionMS > tmpvffi->dwFileVersionMS)||
|
---|
495 | ((destvffi->dwFileVersionMS==tmpvffi->dwFileVersionMS)&&
|
---|
496 | (destvffi->dwFileVersionLS > tmpvffi->dwFileVersionLS)
|
---|
497 | )
|
---|
498 | )
|
---|
499 | xret |= VIF_MISMATCH|VIF_SRCOLD;
|
---|
500 | /* compare filetypes and filesubtypes */
|
---|
501 | if ((destvffi->dwFileType!=tmpvffi->dwFileType) ||
|
---|
502 | (destvffi->dwFileSubtype!=tmpvffi->dwFileSubtype)
|
---|
503 | )
|
---|
504 | xret |= VIF_MISMATCH|VIF_DIFFTYPE;
|
---|
505 | if (VerQueryValueA(buf1,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf1,&len1) &&
|
---|
506 | VerQueryValueA(buf2,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf2,&len2)
|
---|
507 | ) {
|
---|
508 | /* irgendwas mit tbuf1 und tbuf2 machen
|
---|
509 | * generiert DIFFLANG|MISMATCH
|
---|
510 | */
|
---|
511 | }
|
---|
512 | free(buf2);
|
---|
513 | } else
|
---|
514 | xret=VIF_MISMATCH|VIF_SRCOLD;
|
---|
515 | free(buf1);
|
---|
516 | }
|
---|
517 | }
|
---|
518 | if (xret) {
|
---|
519 | if (*tmpfilelen<strlen(tmpfn+tmplast)) {
|
---|
520 | xret|=VIF_BUFFTOOSMALL;
|
---|
521 | DeleteFileA(tmpfn);
|
---|
522 | } else {
|
---|
523 | strcpy(tmpfile,tmpfn+tmplast);
|
---|
524 | *tmpfilelen = strlen(tmpfn+tmplast)+1;
|
---|
525 | xret|=VIF_TEMPFILE;
|
---|
526 | }
|
---|
527 | } else {
|
---|
528 | if (-1!=GetFileAttributesA(destfn))
|
---|
529 | if (!DeleteFileA(destfn)) {
|
---|
530 | xret|=_error2vif(GetLastError())|VIF_CANNOTDELETE;
|
---|
531 | DeleteFileA(tmpfn);
|
---|
532 | LZClose(hfsrc);
|
---|
533 | return xret;
|
---|
534 | }
|
---|
535 | if ((!(flags & VIFF_DONTDELETEOLD)) &&
|
---|
536 | curdir &&
|
---|
537 | *curdir &&
|
---|
538 | lstrcmpiA(curdir,pdest)
|
---|
539 | ) {
|
---|
540 | char curfn[260];
|
---|
541 |
|
---|
542 | sprintf(curfn,"%s\\%s",curdir,destfilename);
|
---|
543 | if (-1!=GetFileAttributesA(curfn)) {
|
---|
544 | /* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */
|
---|
545 | if (!DeleteFileA(curfn))
|
---|
546 | xret|=_error2vif(GetLastError())|VIF_CANNOTDELETECUR;
|
---|
547 | }
|
---|
548 | }
|
---|
549 | if (!MoveFileA(tmpfn,destfn)) {
|
---|
550 | xret|=_error2vif(GetLastError())|VIF_CANNOTRENAME;
|
---|
551 | DeleteFileA(tmpfn);
|
---|
552 | }
|
---|
553 | }
|
---|
554 | LZClose(hfsrc);
|
---|
555 | return xret;
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | /* VerInstallFile32W [VERSION.8] */
|
---|
560 | DWORD WINAPI VerInstallFileW(
|
---|
561 | UINT flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
|
---|
562 | LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,UINT *tmpfilelen )
|
---|
563 | {
|
---|
564 | LPSTR wsrcf,wsrcd,wdestf,wdestd,wtmpf,wcurd;
|
---|
565 | DWORD ret;
|
---|
566 |
|
---|
567 | wsrcf = HEAP_strdupWtoA( GetProcessHeap(), 0, srcfilename );
|
---|
568 | wsrcd = HEAP_strdupWtoA( GetProcessHeap(), 0, srcdir );
|
---|
569 | wdestf = HEAP_strdupWtoA( GetProcessHeap(), 0, destfilename );
|
---|
570 | wdestd = HEAP_strdupWtoA( GetProcessHeap(), 0, destdir );
|
---|
571 | wtmpf = HEAP_strdupWtoA( GetProcessHeap(), 0, tmpfile );
|
---|
572 | wcurd = HEAP_strdupWtoA( GetProcessHeap(), 0, curdir );
|
---|
573 | ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,tmpfilelen);
|
---|
574 | if (!ret)
|
---|
575 | lstrcpynAtoW(tmpfile,wtmpf,*tmpfilelen);
|
---|
576 | HeapFree( GetProcessHeap(), 0, wsrcf );
|
---|
577 | HeapFree( GetProcessHeap(), 0, wsrcd );
|
---|
578 | HeapFree( GetProcessHeap(), 0, wdestf );
|
---|
579 | HeapFree( GetProcessHeap(), 0, wdestd );
|
---|
580 | HeapFree( GetProcessHeap(), 0, wtmpf );
|
---|
581 | if (wcurd)
|
---|
582 | HeapFree( GetProcessHeap(), 0, wcurd );
|
---|
583 | return ret;
|
---|
584 | }
|
---|
585 |
|
---|