Ignore:
Timestamp:
Jul 23, 1999, 9:30:49 AM (26 years ago)
Author:
sandervl
Message:

EB's VerQueryValueA/W implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/version/version.cpp

    r95 r369  
    1 /* $Id: version.cpp,v 1.3 1999-06-10 16:29:00 phaller Exp $ */
     1/* $Id: version.cpp,v 1.4 1999-07-23 07:30:49 sandervl Exp $ */
    22
    33/*
     
    2424
    2525
    26 /*
    27 #include "winver.h"
    28 #include "windef.h"
    29 */
    30 
    31 
    3226/******************************************************************************/
    3327/******************************************************************************/
     
    9993/******************************************************************************/
    10094/******************************************************************************/
    101 BOOL WIN32API VERSION_VerQueryValueA(const LPVOID pBlock,
    102                                      LPTSTR       lpSubBlock,
    103                                      LPVOID       lplpBuffer,
    104                                      PUINT        puLen)
    105 {
    106   dprintf(("VERSION: VerQueryValueA(%08xh,%08xh,%08xh,%08xh) not implemented\n",
    107            pBlock,
    108            lpSubBlock,
    109            lplpBuffer,
    110            puLen));
    111 
    112    return TRUE;
    113 }
    114 /******************************************************************************/
    115 /******************************************************************************/
    116 /*KSO Sun 24.05.1998*/
    117 BOOL WIN32API VERSION_VerQueryValueW(const LPVOID pBlock,
    118                                      LPWSTR       lpSubBlock,
    119                                      LPVOID       lplpBuffer,
    120                                      PUINT        puLen)
    121 {
    122    dprintf(("VERSION: VerQueryValueW(%08xh,%08xh,%08xh,%08xh) not implemented\n",
    123             pBlock,
    124             lpSubBlock,
    125             lplpBuffer,
    126             puLen));
    127 
    128    return TRUE;
    129 }
    130 /******************************************************************************/
    131 /******************************************************************************/
    132 
     95INT WIN32API lstrncmpiW( LPCWSTR str1, LPCWSTR str2, INT n )
     96{
     97    INT res;
     98
     99    if (!n) return 0;
     100    while ((--n > 0) && *str1)
     101    {
     102        if ((res = towupper(*str1) - towupper(*str2)) != 0) return res;
     103        str1++;
     104        str2++;
     105    }
     106    return towupper(*str1) - towupper(*str2);
     107}
     108/***********************************************************************
     109 *           VersionInfo16_FindChild             [internal]
     110 */
     111VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16 *info,
     112                                            LPCSTR szKey, UINT cbKey )
     113{
     114    VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
     115
     116    while ( (DWORD)child < (DWORD)info + info->wLength )
     117    {
     118        if ( !strnicmp( child->szKey, szKey, cbKey ) )
     119            return child;
     120
     121        if (!(child->wLength)) return NULL;
     122        child = VersionInfo16_Next( child );
     123    }
     124
     125    return NULL;
     126}
     127/***********************************************************************
     128 *           VersionInfo32_FindChild             [internal]
     129 */
     130VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info,
     131                                            LPCWSTR szKey, UINT cbKey )
     132{
     133    VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
     134
     135    while ( (DWORD)child < (DWORD)info + info->wLength )
     136    {
     137        if ( !lstrncmpiW( child->szKey, szKey, cbKey ) )
     138            return child;
     139
     140        child = VersionInfo32_Next( child );
     141    }
     142
     143    return NULL;
     144}
     145/******************************************************************************/
     146/******************************************************************************
     147 *           VerQueryValue32W              [VERSION.13]
     148 */
     149BOOL WIN32API VERSION_VerQueryValueW( LPVOID pBlock, LPCWSTR lpSubBlock,
     150                                      LPVOID *lplpBuffer, UINT *puLen )
     151{
     152    VS_VERSION_INFO_STRUCT32 *info = (VS_VERSION_INFO_STRUCT32 *)pBlock;
     153    if ( VersionInfoIs16( info ) )
     154    {
     155        dprintf(("VERSION: called on NE resource!\n"));
     156        return FALSE;
     157    }
     158
     159    dprintf(("VERSION: (%p,%s,%p,%p)\n",
     160             pBlock, lpSubBlock, lplpBuffer, puLen ));
     161
     162    while ( *lpSubBlock )
     163    {
     164        /* Find next path component */
     165        LPCWSTR lpNextSlash;
     166        for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
     167            if ( *lpNextSlash == '\\' )
     168                break;
     169
     170        /* Skip empty components */
     171        if ( lpNextSlash == lpSubBlock )
     172        {
     173            lpSubBlock++;
     174            continue;
     175        }
     176
     177        /* We have a non-empty component: search info for key */
     178        info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
     179        if ( !info ) return FALSE;
     180
     181        /* Skip path component */
     182        lpSubBlock = lpNextSlash;
     183    }
     184
     185    /* Return value */
     186    *lplpBuffer = VersionInfo32_Value( info );
     187    *puLen = info->wValueLength;
     188
     189    return TRUE;
     190}
     191/******************************************************************************/
     192/******************************************************************************/
     193/***********************************************************************
     194 *           VerQueryValue32A              [VERSION.12]
     195 */
     196BOOL WIN32API VERSION_VerQueryValueA( LPVOID pBlock, LPCSTR lpSubBlock,
     197                                      LPVOID *lplpBuffer, UINT *puLen )
     198{
     199    VS_VERSION_INFO_STRUCT16 *info = (VS_VERSION_INFO_STRUCT16 *)pBlock;
     200    if ( !VersionInfoIs16( info ) )
     201    {
     202        // this is a quick hack, not much tested
     203        WCHAR *ustring = (WCHAR *)malloc(strlen((char *)lpSubBlock)*2+1);
     204        LPVOID ubuffer;
     205        char *abuffer;
     206        UINT len = *puLen * 2;
     207        BOOL rc;
     208
     209        dprintf(("VERSION: called on PE unicode resource!\n" ));
     210
     211        AsciiToUnicode((char *)lpSubBlock, ustring);
     212        rc = VERSION_VerQueryValueW( pBlock, (LPCWSTR)ustring, &ubuffer, &len);
     213        if(lpSubBlock[0] == '\\' && lpSubBlock[1] == 0)
     214          *lplpBuffer = ubuffer;
     215        else
     216        {
     217          *lplpBuffer = malloc(len+1); // no free, memory leak
     218          UnicodeToAsciiN((WCHAR *)ubuffer, (char *)*lplpBuffer, len);
     219        }
     220        *puLen = len;
     221        free(ustring);
     222        return rc;
     223    }
     224
     225    dprintf(("VERSION: (%p,%s,%p,%p)\n",
     226             pBlock, lpSubBlock, lplpBuffer, puLen ));
     227
     228    while ( *lpSubBlock )
     229    {
     230        /* Find next path component */
     231        LPCSTR lpNextSlash;
     232        for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
     233            if ( *lpNextSlash == '\\' )
     234                break;
     235
     236        /* Skip empty components */
     237        if ( lpNextSlash == lpSubBlock )
     238        {
     239            lpSubBlock++;
     240            continue;
     241        }
     242
     243        /* We have a non-empty component: search info for key */
     244        info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
     245        if ( !info ) return FALSE;
     246
     247        /* Skip path component */
     248        lpSubBlock = lpNextSlash;
     249    }
     250
     251    /* Return value */
     252    *lplpBuffer = VersionInfo16_Value( info );
     253    *puLen = info->wValueLength;
     254
     255    return TRUE;
     256}
     257/******************************************************************************/
    133258
    134259
Note: See TracChangeset for help on using the changeset viewer.