47edb34a5816ef4bdc3f2691a375e6902ba73029
[reactos.git] / base / setup / usetup / inffile.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/inffile.c
23 * PURPOSE: .inf files support functions
24 * PROGRAMMERS: Hervé Poussineau
25 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
26 */
27
28 /* INCLUDES ******************************************************************/
29
30 #include "usetup.h"
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
36
37 /* Functions from the INFLIB library */
38
39 extern VOID InfCloseFile(HINF InfHandle);
40 // #define SetupCloseInfFile InfCloseFile
41 VOID
42 WINAPI
43 SetupCloseInfFile(HINF InfHandle)
44 {
45 InfCloseFile(InfHandle);
46 }
47
48 // #define SetupFindFirstLineW InfpFindFirstLineW
49 BOOL
50 WINAPI
51 SetupFindFirstLineW(
52 IN HINF InfHandle,
53 IN PCWSTR Section,
54 IN PCWSTR Key,
55 IN OUT PINFCONTEXT Context)
56 {
57 PINFCONTEXT pContext;
58 BOOL ret;
59
60 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
61 if (!ret)
62 return FALSE;
63
64 memcpy(Context, pContext, sizeof(INFCONTEXT));
65 InfFreeContext(pContext);
66 return TRUE;
67 }
68
69 extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn,
70 PINFCONTEXT ContextOut);
71 // #define SetupFindNextLine InfFindNextLine
72 BOOL
73 WINAPI
74 SetupFindNextLine(PINFCONTEXT ContextIn,
75 PINFCONTEXT ContextOut)
76 {
77 return !!InfFindNextLine(ContextIn, ContextOut);
78 }
79
80 extern LONG InfGetFieldCount(PINFCONTEXT Context);
81 // #define SetupGetFieldCount InfGetFieldCount
82 LONG
83 WINAPI
84 SetupGetFieldCount(PINFCONTEXT Context)
85 {
86 return InfGetFieldCount(Context);
87 }
88
89 /*
90 * This function corresponds to an undocumented but exported setupapi API
91 * that exists since WinNT4 and is still present in Win10.
92 * The returned string pointer is a read-only pointer to a string in the
93 * maintained INF cache, and is always in UNICODE (on NT systems).
94 */
95 extern BOOLEAN InfGetDataField(PINFCONTEXT Context,
96 ULONG FieldIndex,
97 PWCHAR *Data);
98 PCWSTR
99 WINAPI
100 pSetupGetField(PINFCONTEXT Context,
101 ULONG FieldIndex)
102 {
103 PWCHAR Data = NULL;
104 if (!InfGetDataField(Context, FieldIndex, &Data))
105 return NULL;
106 return Data;
107 }
108
109 extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context,
110 ULONG FieldIndex,
111 PUCHAR ReturnBuffer,
112 ULONG ReturnBufferSize,
113 PULONG RequiredSize);
114 // #define SetupGetBinaryField InfGetBinaryField
115 BOOL
116 WINAPI
117 SetupGetBinaryField(PINFCONTEXT Context,
118 ULONG FieldIndex,
119 PUCHAR ReturnBuffer,
120 ULONG ReturnBufferSize,
121 PULONG RequiredSize)
122 {
123 return !!InfGetBinaryField(Context,
124 FieldIndex,
125 ReturnBuffer,
126 ReturnBufferSize,
127 RequiredSize);
128 }
129
130 extern BOOLEAN InfGetIntField(PINFCONTEXT Context,
131 ULONG FieldIndex,
132 INT *IntegerValue);
133 // #define SetupGetIntField InfGetIntField
134 BOOL
135 WINAPI
136 SetupGetIntField(PINFCONTEXT Context,
137 ULONG FieldIndex,
138 INT *IntegerValue) // PINT
139 {
140 return !!InfGetIntField(Context, FieldIndex, IntegerValue);
141 }
142
143 extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context,
144 ULONG FieldIndex,
145 PWSTR ReturnBuffer,
146 ULONG ReturnBufferSize,
147 PULONG RequiredSize);
148 // #define SetupGetMultiSzFieldW InfGetMultiSzField
149 BOOL
150 WINAPI
151 SetupGetMultiSzFieldW(PINFCONTEXT Context,
152 ULONG FieldIndex,
153 PWSTR ReturnBuffer,
154 ULONG ReturnBufferSize,
155 PULONG RequiredSize)
156 {
157 return !!InfGetMultiSzField(Context,
158 FieldIndex,
159 ReturnBuffer,
160 ReturnBufferSize,
161 RequiredSize);
162 }
163
164 extern BOOLEAN InfGetStringField(PINFCONTEXT Context,
165 ULONG FieldIndex,
166 PWSTR ReturnBuffer,
167 ULONG ReturnBufferSize,
168 PULONG RequiredSize);
169 // #define SetupGetStringFieldW InfGetStringField
170 BOOL
171 WINAPI
172 SetupGetStringFieldW(PINFCONTEXT Context,
173 ULONG FieldIndex,
174 PWSTR ReturnBuffer,
175 ULONG ReturnBufferSize,
176 PULONG RequiredSize)
177 {
178 return !!InfGetStringField(Context,
179 FieldIndex,
180 ReturnBuffer,
181 ReturnBufferSize,
182 RequiredSize);
183 }
184
185
186 /* SetupOpenInfFileW with support for a user-provided LCID */
187 // #define SetupOpenInfFileExW InfpOpenInfFileW
188 HINF
189 WINAPI
190 SetupOpenInfFileExW(
191 IN PCWSTR FileName,
192 IN PCWSTR InfClass,
193 IN DWORD InfStyle,
194 IN LCID LocaleId,
195 OUT PUINT ErrorLine)
196 {
197 HINF hInf = NULL;
198 UNICODE_STRING FileNameU;
199 ULONG ErrorLineUL;
200 NTSTATUS Status;
201
202 RtlInitUnicodeString(&FileNameU, FileName);
203 Status = InfOpenFile(&hInf,
204 &FileNameU,
205 LANGIDFROMLCID(LocaleId),
206 &ErrorLineUL);
207 *ErrorLine = (UINT)ErrorLineUL;
208 if (!NT_SUCCESS(Status))
209 return INVALID_HANDLE_VALUE;
210
211 return hInf;
212 }
213
214
215 /* HELPER FUNCTIONS **********************************************************/
216
217 HINF WINAPI
218 INF_OpenBufferedFileA(
219 IN PSTR FileBuffer,
220 IN ULONG FileSize,
221 IN PCSTR InfClass,
222 IN DWORD InfStyle,
223 IN LCID LocaleId,
224 OUT PUINT ErrorLine)
225 {
226 HINF hInf = NULL;
227 ULONG ErrorLineUL;
228 NTSTATUS Status;
229
230 Status = InfOpenBufferedFile(&hInf,
231 FileBuffer,
232 FileSize,
233 LANGIDFROMLCID(LocaleId),
234 &ErrorLineUL);
235 *ErrorLine = (UINT)ErrorLineUL;
236 if (!NT_SUCCESS(Status))
237 return INVALID_HANDLE_VALUE;
238
239 return hInf;
240 }
241
242 /* EOF */