Ignore:
Timestamp:
May 15, 2002, 2:39:57 PM (23 years ago)
Author:
sandervl
Message:

wine resync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/setupapi/infparse.c

    r6712 r8421  
    11/*
    22 * SetupX .inf file parsing functions
     3 *
     4 * Copyright 2000 Andreas Mohr for Codeweavers
     5 *
     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.
     10 *
     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.
     15 *
     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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    319 *
    420 * FIXME:
     
    1026 */
    1127
    12 #include "debugtools.h"
     28#include <string.h>
    1329#include "windef.h"
    1430#include "winbase.h"
    15 #include "heap.h"
     31#include "ntddk.h"
    1632#include "wine/winbase16.h"
     33#include "setupapi.h"
    1734#include "setupx16.h"
    18 #include "setupx_private.h"
    19 
    20 DEFAULT_DEBUG_CHANNEL(setupx);
     35#include "setupapi_private.h"
     36#include "wine/debug.h"
     37
     38WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
     39
     40#define MAX_HANDLES 16384
     41#define FIRST_HANDLE 32
     42
     43static HINF handles[MAX_HANDLES];
     44
     45
     46static RETERR16 alloc_hinf16( HINF hinf, HINF16 *hinf16 )
     47{
     48    int i;
     49    for (i = 0; i < MAX_HANDLES; i++)
     50    {
     51        if (!handles[i])
     52        {
     53            handles[i] = hinf;
     54            *hinf16 = i + FIRST_HANDLE;
     55            return OK;
     56        }
     57    }
     58    return ERR_IP_OUT_OF_HANDLES;
     59}
     60
     61static HINF get_hinf( HINF16 hinf16 )
     62{
     63    int idx = hinf16 - FIRST_HANDLE;
     64    if (idx < 0 || idx >= MAX_HANDLES) return 0;
     65    return handles[idx];
     66}
     67
     68
     69static HINF free_hinf16( HINF16 hinf16 )
     70{
     71    HINF ret;
     72    int idx = hinf16 - FIRST_HANDLE;
     73
     74    if (idx < 0 || idx >= MAX_HANDLES) return 0;
     75    ret = handles[idx];
     76    handles[idx] = 0;
     77    return ret;
     78}
     79
     80/* convert last error code to a RETERR16 value */
     81static RETERR16 get_last_error(void)
     82{
     83    switch(GetLastError())
     84    {
     85    case ERROR_EXPECTED_SECTION_NAME:
     86    case ERROR_BAD_SECTION_NAME_LINE:
     87    case ERROR_SECTION_NAME_TOO_LONG: return ERR_IP_INVALID_SECT_NAME;
     88    case ERROR_SECTION_NOT_FOUND: return ERR_IP_SECT_NOT_FOUND;
     89    case ERROR_LINE_NOT_FOUND: return ERR_IP_LINE_NOT_FOUND;
     90    default: return IP_ERROR;  /* FIXME */
     91    }
     92}
     93
     94
     95/***********************************************************************
     96 *              IpOpen (SETUPX.2)
     97 *
     98 */
     99RETERR16 WINAPI IpOpen16( LPCSTR filename, HINF16 *hinf16 )
     100{
     101    HINF hinf = SetupOpenInfFileA( filename, NULL, INF_STYLE_WIN4, NULL );
     102    if (hinf == (HINF)INVALID_HANDLE_VALUE) return get_last_error();
     103    return alloc_hinf16( hinf, hinf16 );
     104}
     105
     106
     107/***********************************************************************
     108 *              IpClose (SETUPX.4)
     109 */
     110RETERR16 WINAPI IpClose16( HINF16 hinf16 )
     111{
     112    HINF hinf = free_hinf16( hinf16 );
     113    if (!hinf) return ERR_IP_INVALID_HINF;
     114    SetupCloseInfFile( hinf );
     115    return OK;
     116}
     117
     118
     119/***********************************************************************
     120 *              IpGetProfileString (SETUPX.210)
     121 */
     122RETERR16 WINAPI IpGetProfileString16( HINF16 hinf16, LPCSTR section, LPCSTR entry,
     123                                      LPSTR buffer, WORD buflen )
     124{
     125    DWORD required_size;
     126    HINF hinf = get_hinf( hinf16 );
     127
     128    if (!hinf) return ERR_IP_INVALID_HINF;
     129    if (!SetupGetLineTextA( NULL, hinf, section, entry, buffer, buflen, &required_size ))
     130        return get_last_error();
     131    TRACE("%p: section %s entry %s ret %s\n",
     132          hinf, debugstr_a(section), debugstr_a(entry), debugstr_a(buffer) );
     133    return OK;
     134}
     135
     136
     137/***********************************************************************
     138 *              GenFormStrWithoutPlaceHolders (SETUPX.103)
     139 *
     140 * ought to be pretty much implemented, I guess...
     141 */
     142void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR dst, LPCSTR src, HINF16 hinf16 )
     143{
     144    UNICODE_STRING srcW;
     145    HINF hinf = get_hinf( hinf16 );
     146
     147    if (!hinf) return;
     148
     149    if (!RtlCreateUnicodeStringFromAsciiz( &srcW, src )) return;
     150    PARSER_string_substA( hinf, srcW.Buffer, dst, MAX_INF_STRING_LENGTH );
     151    RtlFreeUnicodeString( &srcW );
     152    TRACE( "%s -> %s\n", debugstr_a(src), debugstr_a(dst) );
     153}
     154
     155/***********************************************************************
     156 *              GenInstall (SETUPX.101)
     157 *
     158 * generic installer function for .INF file sections
     159 *
     160 * This is not perfect - patch whenever you can !
     161 *
     162 * wFlags == GENINSTALL_DO_xxx
     163 * e.g. NetMeeting:
     164 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
     165 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
     166 */
     167RETERR16 WINAPI GenInstall16( HINF16 hinf16, LPCSTR section, WORD genflags )
     168{
     169    UINT flags = 0;
     170    HINF hinf = get_hinf( hinf16 );
     171    RETERR16 ret = OK;
     172    void *context;
     173
     174    if (!hinf) return ERR_IP_INVALID_HINF;
     175
     176    if (genflags & GENINSTALL_DO_FILES) flags |= SPINST_FILES;
     177    if (genflags & GENINSTALL_DO_INI) flags |= SPINST_INIFILES;
     178    if (genflags & GENINSTALL_DO_REG) flags |= SPINST_REGISTRY;
     179    if (genflags & GENINSTALL_DO_INI2REG) flags |= SPINST_INI2REG;
     180    if (genflags & GENINSTALL_DO_LOGCONFIG) flags |= SPINST_LOGCONFIG;
     181    if (genflags & (GENINSTALL_DO_REGSRCPATH|GENINSTALL_DO_CFGAUTO|GENINSTALL_DO_PERUSER))
     182        FIXME( "unsupported flags %x\n", genflags );
     183
     184    context = SetupInitDefaultQueueCallback( 0 );
     185    if (!SetupInstallFromInfSectionA( 0, hinf, section, flags, 0, NULL, 0,
     186                                      SetupDefaultQueueCallbackA, context, 0, 0 ))
     187        ret = get_last_error();
     188
     189    SetupTermDefaultQueueCallback( context );
     190    return ret;
     191}
     192
    21193
    22194WORD InfNumEntries = 0;
     
    24196HINF16 IP_curr_handle = 0;
    25197
    26 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
    27 {
    28     HFILE hFile = _lopen(lpInfFileName, OF_READ);
    29 
    30     if (!lphInf)
    31         return IP_ERROR;
    32 
    33     /* this could be improved by checking for already freed handles */
    34     if (IP_curr_handle == 0xffff)
    35         return ERR_IP_OUT_OF_HANDLES;
    36 
    37     if (hFile != HFILE_ERROR)
    38     {
    39         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
    40         InfList[InfNumEntries].hInf = IP_curr_handle++;
    41         InfList[InfNumEntries].hInfFile = hFile;
    42         InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
    43                                                           strlen(lpInfFileName)+1);
    44         strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
    45         *lphInf = InfList[InfNumEntries].hInf;
    46         InfNumEntries++;
    47         TRACE("ret handle %d.\n", *lphInf);
    48         return OK;
    49     }
    50     *lphInf = 0xffff;
    51     return ERR_IP_INVALID_INFFILE;
    52 }
    53198
    54199BOOL IP_FindInf(HINF16 hInf, WORD *ret)
     
    76221}
    77222
    78 RETERR16 IP_CloseInf(HINF16 hInf)
    79 {
    80     int i;
    81     WORD n;
    82     RETERR16 res = ERR_IP_INVALID_HINF;
    83 
    84     if (IP_FindInf(hInf, &n))
    85     {
    86         _lclose(InfList[n].hInfFile);
    87         HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
    88         for (i=n; i < InfNumEntries-1; i++)
    89             InfList[i] = InfList[i+1];
    90         InfNumEntries--;
    91         InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
    92         res = OK;
    93     }
    94     return res;
    95 }
    96 
    97 /***********************************************************************
    98  *              IpOpen16
    99  *
    100  */
    101 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
    102 {
    103     TRACE("('%s', %p)\n", lpInfFileName, lphInf);
    104     return IP_OpenInf(lpInfFileName, lphInf);
    105 }
    106 
    107 /***********************************************************************
    108  *              IpClose16
    109  */
    110 RETERR16 WINAPI IpClose16(HINF16 hInf)
    111 {
    112     return IP_CloseInf(hInf);
    113 }
    114 
    115 /***********************************************************************
    116  *              IpGetProfileString16
    117  */
    118 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
    119 {
    120     TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
    121     GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
    122     return 0;
    123 }
     223
Note: See TracChangeset for help on using the changeset viewer.