2 * SetupX .inf file parsing functions
6 * - this should be reimplemented at some point to have its own
7 * file parsing instead of using profile functions,
8 * as some SETUPX exports probably demand that
9 * (IpSaveRestorePosition, IpFindNextMatchLine, ...).
13 #include "debugtools.h"
16 #include "wine/winbase16.h"
18 #include "setupapi_private.h"
20 DEFAULT_DEBUG_CHANNEL(setupapi);
22 WORD InfNumEntries = 0;
23 INF_FILE *InfList = NULL;
24 HINF16 IP_curr_handle = 0;
26 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
28 HFILE hFile = _lopen(lpInfFileName, OF_READ);
33 /* this could be improved by checking for already freed handles */
34 if (IP_curr_handle == 0xffff)
35 return ERR_IP_OUT_OF_HANDLES;
37 if (hFile != HFILE_ERROR)
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;
47 TRACE("ret handle %d.\n", *lphInf);
51 return ERR_IP_INVALID_INFFILE;
54 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
58 for (n=0; n < InfNumEntries; n++)
59 if (InfList[n].hInf == hInf)
68 LPCSTR IP_GetFileName(HINF16 hInf)
71 if (IP_FindInf(hInf, &n))
73 return InfList[n].lpInfFileName;
78 RETERR16 IP_CloseInf(HINF16 hInf)
82 RETERR16 res = ERR_IP_INVALID_HINF;
84 if (IP_FindInf(hInf, &n))
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];
91 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
97 /***********************************************************************
101 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
103 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
104 return IP_OpenInf(lpInfFileName, lphInf);
107 /***********************************************************************
110 RETERR16 WINAPI IpClose16(HINF16 hInf)
112 return IP_CloseInf(hInf);
115 /***********************************************************************
116 * IpGetProfileString (SETUPX.210)
118 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
120 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
121 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));