Sync with trunk (r48144)
[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: subsys/system/usetup/inffile.c
23 * PURPOSE: .inf files support functions
24 * PROGRAMMER: Hervé Poussineau
25 */
26
27 /* INCLUDES ******************************************************************/
28
29 #include "usetup.h"
30
31 #ifdef __REACTOS__
32 #include <infros.h>
33 #endif
34
35 #define NDEBUG
36 #include <debug.h>
37
38 /* FUNCTIONS *****************************************************************/
39
40 #ifdef __REACTOS__
41
42 VOID WINAPI
43 InfpCloseInfFile(
44 IN HINF InfHandle)
45 {
46 InfCloseFile(InfHandle);
47 }
48
49 BOOL WINAPI
50 InfpFindFirstLineW(
51 IN HINF InfHandle,
52 IN PCWSTR Section,
53 IN PCWSTR Key,
54 IN OUT PINFCONTEXT Context)
55 {
56 PINFCONTEXT pContext;
57 BOOL ret;
58
59 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
60 if (!ret)
61 return FALSE;
62
63 memcpy(Context, pContext, sizeof(INFCONTEXT));
64 InfFreeContext(pContext);
65 return TRUE;
66 }
67
68 BOOL WINAPI
69 InfpFindNextLine(
70 IN PINFCONTEXT ContextIn,
71 OUT PINFCONTEXT ContextOut)
72 {
73 return InfFindNextLine(ContextIn, ContextOut);
74 }
75
76 BOOL WINAPI
77 InfpGetBinaryField(
78 IN PINFCONTEXT Context,
79 IN ULONG FieldIndex,
80 IN OUT BYTE* ReturnBuffer,
81 IN ULONG ReturnBufferSize,
82 OUT PULONG RequiredSize)
83 {
84 return InfGetBinaryField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize);
85 }
86
87 DWORD WINAPI
88 InfpGetFieldCount(
89 IN PINFCONTEXT Context)
90 {
91 return (DWORD)InfGetFieldCount(Context);
92 }
93
94 BOOL WINAPI
95 InfpGetIntField(
96 IN PINFCONTEXT Context,
97 IN DWORD FieldIndex,
98 OUT PINT IntegerValue)
99 {
100 LONG IntegerValueL;
101 BOOL ret;
102
103 ret = InfGetIntField(Context, FieldIndex, &IntegerValueL);
104 *IntegerValue = (INT)IntegerValueL;
105 return ret;
106 }
107
108 BOOL WINAPI
109 InfpGetMultiSzFieldW(
110 IN PINFCONTEXT Context,
111 IN ULONG FieldIndex,
112 IN OUT PWSTR ReturnBuffer,
113 IN ULONG ReturnBufferSize,
114 OUT PULONG RequiredSize)
115 {
116 return InfGetMultiSzField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize);
117 }
118
119 BOOL WINAPI
120 InfpGetStringFieldW(
121 IN PINFCONTEXT Context,
122 IN ULONG FieldIndex,
123 IN OUT PWSTR ReturnBuffer,
124 IN ULONG ReturnBufferSize,
125 OUT PULONG RequiredSize)
126 {
127 return InfGetStringField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize);
128 }
129
130 HINF WINAPI
131 InfpOpenInfFileW(
132 IN PCWSTR FileName,
133 IN PCWSTR InfClass,
134 IN DWORD InfStyle,
135 IN LCID LocaleId,
136 OUT PUINT ErrorLine)
137 {
138 HINF hInf = NULL;
139 UNICODE_STRING FileNameU;
140 ULONG ErrorLineUL;
141 NTSTATUS Status;
142
143 RtlInitUnicodeString(&FileNameU, FileName);
144 Status = InfOpenFile(
145 &hInf,
146 &FileNameU,
147 LocaleId,
148 &ErrorLineUL);
149 *ErrorLine = (UINT)ErrorLineUL;
150 if (!NT_SUCCESS(Status))
151 return INVALID_HANDLE_VALUE;
152
153 return hInf;
154 }
155
156 #endif /* __REACTOS__ */
157
158 BOOLEAN
159 INF_GetData(
160 IN PINFCONTEXT Context,
161 OUT PWCHAR *Key,
162 OUT PWCHAR *Data)
163 {
164 #ifdef __REACTOS__
165 return InfGetData(Context, Key, Data);
166 #else
167 static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
168 static DWORD currentIndex = 0;
169 DWORD dwSize, i;
170 BOOL ret;
171
172 currentIndex ^= 2;
173
174 if (Key) *Key = NULL;
175 if (Data) *Data = NULL;
176
177 if (SetupGetFieldCount(Context) != 1)
178 return FALSE;
179
180 for (i = 0; i <= 1; i++)
181 {
182 ret = SetupGetStringFieldW(
183 Context,
184 i,
185 NULL,
186 0,
187 &dwSize);
188 if (!ret)
189 return FALSE;
190 HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
191 pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
192 ret = SetupGetStringFieldW(
193 Context,
194 i,
195 pLastCallData[i + currentIndex],
196 dwSize,
197 NULL);
198 if (!ret)
199 return FALSE;
200 }
201
202 if (Key)
203 *Key = pLastCallData[0 + currentIndex];
204 if (Data)
205 *Data = pLastCallData[1 + currentIndex];
206 return TRUE;
207 #endif /* !__REACTOS__ */
208 }
209
210 BOOLEAN
211 INF_GetDataField(
212 IN PINFCONTEXT Context,
213 IN ULONG FieldIndex,
214 OUT PWCHAR *Data)
215 {
216 #ifdef __REACTOS__
217 return InfGetDataField(Context, FieldIndex, Data);
218 #else
219 static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
220 static DWORD NextIndex = 0;
221 DWORD dwSize;
222 BOOL ret;
223
224 *Data = NULL;
225
226 ret = SetupGetStringFieldW(
227 Context,
228 FieldIndex,
229 NULL,
230 0,
231 &dwSize);
232 if (!ret)
233 return FALSE;
234 HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
235 pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
236 ret = SetupGetStringFieldW(
237 Context,
238 FieldIndex,
239 pLastCallsData[NextIndex],
240 dwSize,
241 NULL);
242 if (!ret)
243 return FALSE;
244
245 *Data = pLastCallsData[NextIndex];
246 NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
247 return TRUE;
248 #endif /* !__REACTOS__ */
249 }
250
251 HINF WINAPI
252 INF_OpenBufferedFileA(
253 IN PSTR FileBuffer,
254 IN ULONG FileSize,
255 IN PCSTR InfClass,
256 IN DWORD InfStyle,
257 IN LCID LocaleId,
258 OUT PUINT ErrorLine)
259 {
260 #ifdef __REACTOS__
261 HINF hInf = NULL;
262 ULONG ErrorLineUL;
263 NTSTATUS Status;
264
265 Status = InfOpenBufferedFile(
266 &hInf,
267 FileBuffer,
268 FileSize,
269 LocaleId,
270 &ErrorLineUL);
271 *ErrorLine = (UINT)ErrorLineUL;
272 if (!NT_SUCCESS(Status))
273 return INVALID_HANDLE_VALUE;
274
275 return hInf;
276 #else
277 return INVALID_HANDLE_VALUE;
278 #endif /* !__REACTOS__ */
279 }
280
281 VOID INF_SetHeap(
282 IN PVOID Heap)
283 {
284 #ifdef __REACTOS__
285 InfSetHeap(Heap);
286 #endif
287 }
288
289 /* EOF */