3 * Copyright (C) 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/lib/infsupp.c
23 * PURPOSE: Interfacing with Setup* API .INF Files support functions
24 * PROGRAMMERS: Hervé Poussineau
25 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
28 /* INCLUDES ******************************************************************/
35 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
37 /* Functions from the INFLIB library */
39 extern VOID
InfCloseFile(HINF InfHandle
);
40 // #define SetupCloseInfFile InfCloseFile
46 if (InfHandle
== INVALID_HANDLE_VALUE
)
48 InfCloseFile(InfHandle
);
51 // #define SetupFindFirstLineW InfpFindFirstLineW
58 IN OUT PINFCONTEXT Context
)
63 if (InfHandle
== INVALID_HANDLE_VALUE
)
66 ret
= InfFindFirstLine(InfHandle
, Section
, Key
, &pContext
);
70 memcpy(Context
, pContext
, sizeof(INFCONTEXT
));
71 InfFreeContext(pContext
);
75 extern BOOLEAN
InfFindNextLine(PINFCONTEXT ContextIn
,
76 PINFCONTEXT ContextOut
);
77 // #define SetupFindNextLine InfFindNextLine
81 IN PINFCONTEXT ContextIn
,
82 OUT PINFCONTEXT ContextOut
)
84 return !!InfFindNextLine(ContextIn
, ContextOut
);
87 extern LONG
InfGetFieldCount(PINFCONTEXT Context
);
88 // #define SetupGetFieldCount InfGetFieldCount
92 IN PINFCONTEXT Context
)
94 return (ULONG
)InfGetFieldCount(Context
);
98 * This function corresponds to an undocumented but exported SetupAPI function
99 * that exists since WinNT4 and is still present in Win10.
100 * The returned string pointer is a read-only pointer to a string in the
101 * maintained INF cache, and is always in UNICODE (on NT systems).
103 extern BOOLEAN
InfGetDataField(PINFCONTEXT Context
,
109 IN PINFCONTEXT Context
,
113 if (!InfGetDataField(Context
, FieldIndex
, &Data
))
118 extern BOOLEAN
InfGetBinaryField(PINFCONTEXT Context
,
121 ULONG ReturnBufferSize
,
122 PULONG RequiredSize
);
123 // #define SetupGetBinaryField InfGetBinaryField
127 IN PINFCONTEXT Context
,
129 OUT PUCHAR ReturnBuffer
,
130 IN ULONG ReturnBufferSize
,
131 OUT PULONG RequiredSize
)
133 return !!InfGetBinaryField(Context
,
140 extern BOOLEAN
InfGetIntField(PINFCONTEXT Context
,
143 // #define SetupGetIntField InfGetIntField
147 IN PINFCONTEXT Context
,
149 OUT INT
*IntegerValue
) // PINT
151 return !!InfGetIntField(Context
, FieldIndex
, IntegerValue
);
154 extern BOOLEAN
InfGetMultiSzField(PINFCONTEXT Context
,
157 ULONG ReturnBufferSize
,
158 PULONG RequiredSize
);
159 // #define SetupGetMultiSzFieldW InfGetMultiSzField
162 SetupGetMultiSzFieldW(
163 IN PINFCONTEXT Context
,
165 OUT PWSTR ReturnBuffer
,
166 IN ULONG ReturnBufferSize
,
167 OUT PULONG RequiredSize
)
169 return !!InfGetMultiSzField(Context
,
176 extern BOOLEAN
InfGetStringField(PINFCONTEXT Context
,
179 ULONG ReturnBufferSize
,
180 PULONG RequiredSize
);
181 // #define SetupGetStringFieldW InfGetStringField
184 SetupGetStringFieldW(
185 IN PINFCONTEXT Context
,
187 OUT PWSTR ReturnBuffer
,
188 IN ULONG ReturnBufferSize
,
189 OUT PULONG RequiredSize
)
191 return !!InfGetStringField(Context
,
198 /* SetupOpenInfFileW with support for a user-provided LCID */
199 // #define SetupOpenInfFileExW InfpOpenInfFileW
210 UNICODE_STRING FileNameU
;
214 RtlInitUnicodeString(&FileNameU
, FileName
);
215 Status
= InfOpenFile(&hInf
,
217 LANGIDFROMLCID(LocaleId
),
219 *ErrorLine
= (UINT
)ErrorLineUL
;
220 if (!NT_SUCCESS(Status
))
221 return INVALID_HANDLE_VALUE
;
227 /* GLOBALS *******************************************************************/
229 pSpInfCloseInfFile SpInfCloseInfFile
= SetupCloseInfFile
;
230 pSpInfFindFirstLine SpInfFindFirstLine
= SetupFindFirstLineW
;
231 pSpInfFindNextLine SpInfFindNextLine
= SetupFindNextLine
;
232 pSpInfGetFieldCount SpInfGetFieldCount
= SetupGetFieldCount
;
233 pSpInfGetBinaryField SpInfGetBinaryField
= SetupGetBinaryField
;
234 pSpInfGetIntField SpInfGetIntField
= SetupGetIntField
;
235 pSpInfGetMultiSzField SpInfGetMultiSzField
= SetupGetMultiSzFieldW
;
236 pSpInfGetStringField SpInfGetStringField
= SetupGetStringFieldW
;
237 pSpInfGetField SpInfGetField
= pSetupGetField
;
238 pSpInfOpenInfFile SpInfOpenInfFile
= SetupOpenInfFileExW
;
241 /* HELPER FUNCTIONS **********************************************************/
244 INF_OpenBufferedFileA(
256 Status
= InfOpenBufferedFile(&hInf
,
259 LANGIDFROMLCID(LocaleId
),
261 *ErrorLine
= (UINT
)ErrorLineUL
;
262 if (!NT_SUCCESS(Status
))
263 return INVALID_HANDLE_VALUE
;