Ignore:
Timestamp:
Oct 24, 2003, 4:47:25 PM (22 years ago)
Author:
sandervl
Message:

Wine resync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/version/install.c

    r2373 r10296  
    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  *
     1/*
     2 * Implementation of VERSION.DLL - File Installer routines
     3 *
    54 * Copyright 1996,1997 Marcus Meissner
    65 * Copyright 1997 David Cuthbert
     6 *
     7 * This library is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU Lesser General Public
     9 * License as published by the Free Software Foundation; either
     10 * version 2.1 of the License, or (at your option) any later version.
     11 *
     12 * This library is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 * Lesser General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU Lesser General Public
     18 * License along with this library; if not, write to the Free Software
     19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     20 *
     21 * TODO
     22 *   o Check the installation functions.
    723 */
    824
    925#include <stdlib.h>
     26#include <stdarg.h>
     27#include <stdio.h>
    1028#include <string.h>
    1129
    1230#include "windef.h"
     31#include "winbase.h"
    1332#include "winver.h"
    14 #include "wine/winestring.h"
     33#include "winnls.h"
     34#include "wine/unicode.h"
    1535#include "winerror.h"
    16 #include "heap.h"
    1736#include "lzexpand.h"
    18 #include "xmalloc.h"
    19 #include "debugtools.h"
    20 #include <misc.h>
    21 
    22 DEFAULT_DEBUG_CHANNEL(ver)
     37#include "wine/debug.h"
     38
     39WINE_DEFAULT_DEBUG_CHANNEL(ver);
    2340
    2441
    2542/******************************************************************************
    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 )
     43 *   testFileExistenceA
    6544 *
    6645 *   Tests whether a given path/file combination exists.  If the file does
     
    7251 *         Original implementation
    7352 *
    74  *****************************************************************************/
    75 
    76 static int  testFileExistence(
    77    char const * path,
    78    char const * file )
     53 */
     54static int testFileExistenceA( char const * path, char const * file, BOOL excl )
    7955{
    8056    char  filename[1024];
    8157    int  filenamelen;
    8258    OFSTRUCT  fileinfo;
    83     int  retval;
    8459
    8560    fileinfo.cBytes = sizeof(OFSTRUCT);
     
    9974    strcat(filename, file);
    10075
    101     if(OpenFile(filename, &fileinfo, OF_EXIST) == HFILE_ERROR)
    102         retval = 0;
    103     else
    104         retval = 1;
    105 
    106     return  retval;
     76    return (OpenFile(filename, &fileinfo,
     77                     OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
    10778}
    10879
    10980/******************************************************************************
    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 )
     81 *   testFileExistenceW
     82 */
     83static int testFileExistenceW( const WCHAR *path, const WCHAR *file, BOOL excl )
    12984{
    130     char  filename[1024];
    131     int  filenamelen;
    132     OFSTRUCT  fileinfo;
    133     int  retval;
     85    char *filename;
     86    DWORD pathlen, filelen;
     87    int ret;
     88    OFSTRUCT fileinfo;
    13489
    13590    fileinfo.cBytes = sizeof(OFSTRUCT);
    13691
    137     strcpy(filename, path);
    138     filenamelen = strlen(filename);
    139 
     92    pathlen = WideCharToMultiByte( CP_ACP, 0, path, -1, NULL, 0, NULL, NULL );
     93    filelen = WideCharToMultiByte( CP_ACP, 0, file, -1, NULL, 0, NULL, NULL );
     94    filename = HeapAlloc( GetProcessHeap(), 0, pathlen+filelen+2 );
     95
     96    WideCharToMultiByte( CP_ACP, 0, path, -1, filename, pathlen, NULL, NULL );
    14097    /* Add a trailing \ if necessary */
    141     if(filenamelen) {
    142         if(filename[filenamelen - 1] != '\\')
    143             strcat(filename, "\\");
     98    if (pathlen > 1)
     99    {
     100        if (filename[pathlen-2] != '\\') strcpy( &filename[pathlen-1], "\\" );
    144101    }
    145102    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;
     103        strcpy(filename, ".\\");
     104
     105    WideCharToMultiByte( CP_ACP, 0, file, -1, filename+strlen(filename), filelen, NULL, NULL );
     106
     107    ret = (OpenFile(filename, &fileinfo,
     108                    OF_EXIST | (excl ? OF_SHARE_EXCLUSIVE : 0)) != HFILE_ERROR);
     109    HeapFree( GetProcessHeap(), 0, filename );
     110    return ret;
    158111}
    159112
    160113/*****************************************************************************
    161  *
    162  *   VerFindFile() [VER.8]
     114 *   VerFindFileA [VERSION.@]
     115 *
    163116 *   Determines where to install a file based on whether it locates another
    164117 *   version of the file in the system.  The values VerFindFile returns are
     
    168121 *      30-May-1997   Dave Cuthbert (dacut@ece.cmu.edu)
    169122 *         Reimplementation of VerFindFile from original stub.
    170  *
    171  ****************************************************************************/
    172 
    173 /* VerFindFile32A                                               [VERSION.5] */
     123 */
    174124DWORD WINAPI VerFindFileA(
    175125    UINT flags,
     
    182132    UINT *lpuDestDirLen )
    183133{
    184     DWORD  retval;
    185     char  curDir[256];
    186     char  destDir[256];
     134    DWORD  retval = 0;
     135    const char *curDir;
     136    const char *destDir;
    187137    unsigned int  curDirSizeReq;
    188138    unsigned int  destDirSizeReq;
    189 
    190     retval = 0;
     139    char  systemDir[MAX_PATH];
    191140
    192141    /* 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);
     142    TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
     143          flags, debugstr_a(lpszFilename), debugstr_a(lpszWinDir), debugstr_a(lpszAppDir),
     144          lpuCurDirLen, lpuCurDirLen ? *lpuCurDirLen : 0,
     145          lpuDestDirLen, lpuDestDirLen ? *lpuDestDirLen : 0 );
    215146
    216147    /* Figure out where the file should go; shared files default to the
    217148       system directory */
    218149
    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     }
     150    GetSystemDirectoryA(systemDir, sizeof(systemDir));
     151    curDir = "";
     152    destDir = "";
     153
     154    if(flags & VFFF_ISSHAREDFILE)
     155    {
     156        destDir = systemDir;
     157        /* Were we given a filename?  If so, try to find the file. */
     158        if(lpszFilename)
     159        {
     160            if(testFileExistenceA(destDir, lpszFilename, FALSE)) curDir = destDir;
     161            else if(lpszAppDir && testFileExistenceA(lpszAppDir, lpszFilename, FALSE))
     162            {
     163                curDir = lpszAppDir;
     164                retval |= VFF_CURNEDEST;
     165            }
     166        }
     167    }
     168    else /* not a shared file */
     169    {
     170        if(lpszAppDir)
     171        {
     172            destDir = lpszAppDir;
     173            if(lpszFilename)
     174            {
     175                if(testFileExistenceA(destDir, lpszFilename, FALSE)) curDir = destDir;
     176                else if(testFileExistenceA(systemDir, lpszFilename, FALSE))
     177                {
     178                    curDir = systemDir;
     179                    retval |= VFF_CURNEDEST;
     180                }
     181            }
     182        }
     183    }
     184
     185    if (lpszFilename && !testFileExistenceA(curDir, lpszFilename, TRUE))
     186        retval |= VFF_FILEINUSE;
    267187
    268188    curDirSizeReq = strlen(curDir) + 1;
    269189    destDirSizeReq = strlen(destDir) + 1;
    270 
    271 
    272190
    273191    /* Make sure that the pointers to the size of the buffers are
     
    275193       is valid, then make sure that the buffer pointer is valid, too! */
    276194
    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);
     195    if(lpuDestDirLen && lpszDestDir)
     196    {
     197        if (*lpuDestDirLen < destDirSizeReq) retval |= VFF_BUFFTOOSMALL;
     198        lstrcpynA(lpszDestDir, destDir, *lpuDestDirLen);
     199        *lpuDestDirLen = destDirSizeReq;
     200    }
     201    if(lpuCurDirLen && lpszCurDir)
     202    {
     203        if(*lpuCurDirLen < curDirSizeReq) retval |= VFF_BUFFTOOSMALL;
     204        lstrcpynA(lpszCurDir, curDir, *lpuCurDirLen);
     205        *lpuCurDirLen = curDirSizeReq;
     206    }
     207
     208    TRACE("ret = %lu (%s%s%s) curdir=%s destdir=%s\n", retval,
     209          (retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
     210          (retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
     211          (retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
     212          debugstr_a(lpszCurDir), debugstr_a(lpszDestDir));
    319213
    320214    return retval;
    321215}
    322216
    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 )
     217/*****************************************************************************
     218 * VerFindFileW                                         [VERSION.@]
     219 */
     220DWORD WINAPI VerFindFileW( UINT flags,LPCWSTR lpszFilename,LPCWSTR lpszWinDir,
     221                           LPCWSTR lpszAppDir, LPWSTR lpszCurDir,UINT *lpuCurDirLen,
     222                           LPWSTR lpszDestDir,UINT *lpuDestDirLen )
    327223{
    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;
     224    static const WCHAR emptyW;
     225    DWORD retval = 0;
     226    const WCHAR *curDir;
     227    const WCHAR *destDir;
     228    unsigned int curDirSizeReq;
     229    unsigned int destDirSizeReq;
     230    WCHAR systemDir[MAX_PATH];
     231
     232    /* Print out debugging information */
     233    TRACE("flags = %x filename=%s windir=%s appdir=%s curdirlen=%p(%u) destdirlen=%p(%u)\n",
     234          flags, debugstr_w(lpszFilename), debugstr_w(lpszWinDir), debugstr_w(lpszAppDir),
     235          lpuCurDirLen, lpuCurDirLen ? *lpuCurDirLen : 0,
     236          lpuDestDirLen, lpuDestDirLen ? *lpuDestDirLen : 0 );
     237
     238    /* Figure out where the file should go; shared files default to the
     239       system directory */
     240
     241    GetSystemDirectoryW(systemDir, sizeof(systemDir)/sizeof(WCHAR));
     242    curDir = &emptyW;
     243    destDir = &emptyW;
     244
     245    if(flags & VFFF_ISSHAREDFILE)
     246    {
     247        destDir = systemDir;
     248        /* Were we given a filename?  If so, try to find the file. */
     249        if(lpszFilename)
     250        {
     251            if(testFileExistenceW(destDir, lpszFilename, FALSE)) curDir = destDir;
     252            else if(lpszAppDir && testFileExistenceW(lpszAppDir, lpszFilename, FALSE))
     253            {
     254                curDir = lpszAppDir;
     255                retval |= VFF_CURNEDEST;
     256            }
     257        }
     258    }
     259    else /* not a shared file */
     260    {
     261        if(lpszAppDir)
     262        {
     263            destDir = lpszAppDir;
     264            if(lpszFilename)
     265            {
     266                if(testFileExistenceW(destDir, lpszFilename, FALSE)) curDir = destDir;
     267                else if(testFileExistenceW(systemDir, lpszFilename, FALSE))
     268                {
     269                    curDir = systemDir;
     270                    retval |= VFF_CURNEDEST;
     271                }
     272            }
     273        }
     274    }
     275
     276    if (lpszFilename && !testFileExistenceW(curDir, lpszFilename, TRUE))
     277        retval |= VFF_FILEINUSE;
     278
     279    curDirSizeReq = strlenW(curDir) + 1;
     280    destDirSizeReq = strlenW(destDir) + 1;
     281
     282    /* Make sure that the pointers to the size of the buffers are
     283       valid; if not, do NOTHING with that buffer.  If that pointer
     284       is valid, then make sure that the buffer pointer is valid, too! */
     285
     286    if(lpuDestDirLen && lpszDestDir)
     287    {
     288        if (*lpuDestDirLen < destDirSizeReq) retval |= VFF_BUFFTOOSMALL;
     289        lstrcpynW(lpszDestDir, destDir, *lpuDestDirLen);
     290        *lpuDestDirLen = destDirSizeReq;
     291    }
     292    if(lpuCurDirLen && lpszCurDir)
     293    {
     294        if(*lpuCurDirLen < curDirSizeReq) retval |= VFF_BUFFTOOSMALL;
     295        lstrcpynW(lpszCurDir, curDir, *lpuCurDirLen);
     296        *lpuCurDirLen = curDirSizeReq;
     297    }
     298
     299    TRACE("ret = %lu (%s%s%s) curdir=%s destdir=%s\n", retval,
     300          (retval & VFF_CURNEDEST) ? "VFF_CURNEDEST " : "",
     301          (retval & VFF_FILEINUSE) ? "VFF_FILEINUSE " : "",
     302          (retval & VFF_BUFFTOOSMALL) ? "VFF_BUFFTOOSMALL " : "",
     303          debugstr_w(lpszCurDir), debugstr_w(lpszDestDir));
     304    return retval;
    348305}
    349306
     
    355312
    356313    alloclen = 1000;
    357     buf= xmalloc(alloclen);
     314    buf=HeapAlloc(GetProcessHeap(), 0, alloclen);
     315    if(buf == NULL) {
     316        WARN("Memory exausted while fetching version info!\n");
     317        return NULL;
     318    }
    358319    while (1) {
    359320        ret = GetFileVersionInfoA(fn,0,alloclen,buf);
    360321        if (!ret) {
    361             free(buf);
    362             return 0;
     322            HeapFree(GetProcessHeap(), 0, buf);
     323            return NULL;
    363324        }
    364325        if (alloclen<*(WORD*)buf) {
    365             free(buf);
    366326            alloclen = *(WORD*)buf;
    367             buf = xmalloc(alloclen);
     327            HeapFree(GetProcessHeap(), 0, buf);
     328            buf = HeapAlloc(GetProcessHeap(), 0, alloclen);
     329            if(buf == NULL) {
     330               WARN("Memory exausted while fetching version info!\n");
     331               return NULL;
     332            }
    368333        } else {
    369334            *vffi = (VS_FIXEDFILEINFO*)(buf+0x14);
     
    391356
    392357/******************************************************************************
    393  * VerInstallFile32A [VERSION.7]
     358 * VerInstallFileA [VERSION.@]
    394359 */
    395360DWORD WINAPI VerInstallFileA(
     
    413378    sprintf(destfn,"%s\\%s",pdest,destfilename);
    414379    hfsrc=LZOpenFileA(srcfn,&ofs,OF_READ);
    415     if (hfsrc==HFILE_ERROR)
     380    if (hfsrc < 0)
    416381        return VIF_CANNOTREADSRC;
    417382    sprintf(tmpfn,"%s\\%s",pdest,destfilename);
    418383    tmplast=strlen(pdest)+1;
    419384    attr = GetFileAttributesA(tmpfn);
    420     if (attr!=-1) {
     385    if (attr != INVALID_FILE_ATTRIBUTES) {
    421386        if (attr & FILE_ATTRIBUTE_READONLY) {
    422387            LZClose(hfsrc);
     
    425390        /* FIXME: check if file currently in use and return VIF_FILEINUSE */
    426391    }
    427     attr = -1;
     392    attr = INVALID_FILE_ATTRIBUTES;
    428393    if (flags & VIFF_FORCEINSTALL) {
    429394        if (tmpfile[0]) {
     
    432397            attr = GetFileAttributesA(tmpfn);
    433398            /* if it exists, it has been copied by the call before.
    434              * we jump over the copy part... 
     399             * we jump over the copy part...
    435400             */
    436401        }
    437402    }
    438     if (attr == -1) {
     403    if (attr == INVALID_FILE_ATTRIBUTES) {
    439404        char    *s;
    440405
     
    463428            case LZERROR_BADOUTHANDLE:
    464429            case LZERROR_WRITE:
    465                 ret = VIF_OUTOFMEMORY; /* FIXME: correct? */
     430                ret = VIF_OUTOFSPACE;
    466431                break;
    467432            case LZERROR_GLOBALLOC:
    468433            case LZERROR_GLOBLOCK:
    469                 ret = VIF_OUTOFSPACE;
     434                ret = VIF_OUTOFMEMORY;
    470435                break;
    471436            default: /* unknown error, should not happen */
     
    506471                    VerQueryValueA(buf2,"\\VarFileInfo\\Translation",(LPVOID*)&tbuf2,&len2)
    507472                ) {
    508                     /* irgendwas mit tbuf1 und tbuf2 machen 
     473                    /* irgendwas mit tbuf1 und tbuf2 machen
    509474                     * generiert DIFFLANG|MISMATCH
    510475                     */
    511476                }
    512                 free(buf2);
     477                HeapFree(GetProcessHeap(), 0, buf2);
    513478            } else
    514479                xret=VIF_MISMATCH|VIF_SRCOLD;
    515             free(buf1);
     480            HeapFree(GetProcessHeap(), 0, buf1);
    516481        }
    517482    }
     
    533498                return xret;
    534499            }
    535         if ((!(flags & VIFF_DONTDELETEOLD))     && 
    536             curdir                              && 
     500        if ((!(flags & VIFF_DONTDELETEOLD))     &&
     501            curdir                              &&
    537502            *curdir                             &&
    538503            lstrcmpiA(curdir,pdest)
     
    541506
    542507            sprintf(curfn,"%s\\%s",curdir,destfilename);
    543             if (-1!=GetFileAttributesA(curfn)) {
     508            if (INVALID_FILE_ATTRIBUTES != GetFileAttributesA(curfn)) {
    544509                /* FIXME: check if in use ... if it is, VIF_CANNOTDELETECUR */
    545510                if (!DeleteFileA(curfn))
     
    557522
    558523
    559 /* VerInstallFile32W                            [VERSION.8] */
     524/******************************************************************************
     525 * VerInstallFileW                              [VERSION.@]
     526 */
    560527DWORD WINAPI VerInstallFileW(
    561528        UINT flags,LPCWSTR srcfilename,LPCWSTR destfilename,LPCWSTR srcdir,
    562529        LPCWSTR destdir,LPCWSTR curdir,LPWSTR tmpfile,UINT *tmpfilelen )
    563530{
    564     LPSTR wsrcf,wsrcd,wdestf,wdestd,wtmpf,wcurd;
     531    LPSTR wsrcf = NULL, wsrcd = NULL, wdestf = NULL, wdestd = NULL, wtmpf = NULL, wcurd = NULL;
    565532    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);
     533    UINT len;
     534
     535    if (srcfilename)
     536    {
     537        len = WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, NULL, 0, NULL, NULL );
     538        if ((wsrcf = HeapAlloc( GetProcessHeap(), 0, len )))
     539            WideCharToMultiByte( CP_ACP, 0, srcfilename, -1, wsrcf, len, NULL, NULL );
     540    }
     541    if (srcdir)
     542    {
     543        len = WideCharToMultiByte( CP_ACP, 0, srcdir, -1, NULL, 0, NULL, NULL );
     544        if ((wsrcd = HeapAlloc( GetProcessHeap(), 0, len )))
     545            WideCharToMultiByte( CP_ACP, 0, srcdir, -1, wsrcd, len, NULL, NULL );
     546    }
     547    if (destfilename)
     548    {
     549        len = WideCharToMultiByte( CP_ACP, 0, destfilename, -1, NULL, 0, NULL, NULL );
     550        if ((wdestf = HeapAlloc( GetProcessHeap(), 0, len )))
     551            WideCharToMultiByte( CP_ACP, 0, destfilename, -1, wdestf, len, NULL, NULL );
     552    }
     553    if (destdir)
     554    {
     555        len = WideCharToMultiByte( CP_ACP, 0, destdir, -1, NULL, 0, NULL, NULL );
     556        if ((wdestd = HeapAlloc( GetProcessHeap(), 0, len )))
     557            WideCharToMultiByte( CP_ACP, 0, destdir, -1, wdestd, len, NULL, NULL );
     558    }
     559    if (curdir)
     560    {
     561        len = WideCharToMultiByte( CP_ACP, 0, curdir, -1, NULL, 0, NULL, NULL );
     562        if ((wcurd = HeapAlloc( GetProcessHeap(), 0, len )))
     563            WideCharToMultiByte( CP_ACP, 0, curdir, -1, wcurd, len, NULL, NULL );
     564    }
     565    len = *tmpfilelen * sizeof(WCHAR);
     566    wtmpf = HeapAlloc( GetProcessHeap(), 0, len );
     567    ret = VerInstallFileA(flags,wsrcf,wdestf,wsrcd,wdestd,wcurd,wtmpf,&len);
    574568    if (!ret)
    575         lstrcpynAtoW(tmpfile,wtmpf,*tmpfilelen);
     569        *tmpfilelen = MultiByteToWideChar( CP_ACP, 0, wtmpf, -1, tmpfile, *tmpfilelen );
     570    else if (ret & VIF_BUFFTOOSMALL)
     571        *tmpfilelen = len;  /* FIXME: not correct */
     572
    576573    HeapFree( GetProcessHeap(), 0, wsrcf );
    577574    HeapFree( GetProcessHeap(), 0, wsrcd );
     
    579576    HeapFree( GetProcessHeap(), 0, wdestd );
    580577    HeapFree( GetProcessHeap(), 0, wtmpf );
    581     if (wcurd)
    582         HeapFree( GetProcessHeap(), 0, wcurd );
     578    HeapFree( GetProcessHeap(), 0, wcurd );
    583579    return ret;
    584580}
    585 
Note: See TracChangeset for help on using the changeset viewer.