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"
17 #include "wine/winbase16.h"
19 #include "setupapi_private.h"
21 DEFAULT_DEBUG_CHANNEL(setupapi);
23 WORD InfNumEntries = 0;
24 INF_FILE *InfList = NULL;
25 HINF16 IP_curr_handle = 0;
27 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
29 HFILE hFile = _lopen(lpInfFileName, OF_READ);
34 /* this could be improved by checking for already freed handles */
35 if (IP_curr_handle == 0xffff)
36 return ERR_IP_OUT_OF_HANDLES;
38 if (hFile != HFILE_ERROR)
40 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
41 InfList[InfNumEntries].hInf = IP_curr_handle++;
42 InfList[InfNumEntries].hInfFile = hFile;
43 InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
44 strlen(lpInfFileName)+1);
45 strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
46 *lphInf = InfList[InfNumEntries].hInf;
48 TRACE("ret handle %d.\n", *lphInf);
52 return ERR_IP_INVALID_INFFILE;
55 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
59 for (n=0; n < InfNumEntries; n++)
60 if (InfList[n].hInf == hInf)
69 LPCSTR IP_GetFileName(HINF16 hInf)
72 if (IP_FindInf(hInf, &n))
74 return InfList[n].lpInfFileName;
79 RETERR16 IP_CloseInf(HINF16 hInf)
83 RETERR16 res = ERR_IP_INVALID_HINF;
85 if (IP_FindInf(hInf, &n))
87 _lclose(InfList[n].hInfFile);
88 HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
89 for (i=n; i < InfNumEntries-1; i++)
90 InfList[i] = InfList[i+1];
92 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
98 /***********************************************************************
102 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
104 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
105 return IP_OpenInf(lpInfFileName, lphInf);
108 /***********************************************************************
111 RETERR16 WINAPI IpClose16(HINF16 hInf)
113 return IP_CloseInf(hInf);
116 /***********************************************************************
117 * IpGetProfileString16
119 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
121 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
122 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));