Fix incompatible pointer type warnings
[reactos.git] / reactos / 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 OUT PUINT ErrorLine)
136 {
137 HINF hInf = NULL;
138 UNICODE_STRING FileNameU;
139 ULONG ErrorLineUL;
140 NTSTATUS Status;
141
142 RtlInitUnicodeString(&FileNameU, FileName);
143 Status = InfOpenFile(
144 &hInf,
145 &FileNameU,
146 &ErrorLineUL);
147 *ErrorLine = (UINT)ErrorLineUL;
148 if (!NT_SUCCESS(Status))
149 return INVALID_HANDLE_VALUE;
150
151 return hInf;
152 }
153
154 #endif /* __REACTOS__ */
155
156 BOOLEAN
157 INF_GetData(
158 IN PINFCONTEXT Context,
159 OUT PWCHAR *Key,
160 OUT PWCHAR *Data)
161 {
162 #ifdef __REACTOS__
163 return InfGetData(Context, Key, Data);
164 #else
165 static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
166 static DWORD currentIndex = 0;
167 DWORD dwSize, i;
168 BOOL ret;
169
170 currentIndex ^= 2;
171
172 if (Key) *Key = NULL;
173 if (Data) *Data = NULL;
174
175 if (SetupGetFieldCount(Context) != 1)
176 return FALSE;
177
178 for (i = 0; i <= 1; i++)
179 {
180 ret = SetupGetStringFieldW(
181 Context,
182 i,
183 NULL,
184 0,
185 &dwSize);
186 if (!ret)
187 return FALSE;
188 HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
189 pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
190 ret = SetupGetStringFieldW(
191 Context,
192 i,
193 pLastCallData[i + currentIndex],
194 dwSize,
195 NULL);
196 if (!ret)
197 return FALSE;
198 }
199
200 if (Key)
201 *Key = pLastCallData[0 + currentIndex];
202 if (Data)
203 *Data = pLastCallData[1 + currentIndex];
204 return TRUE;
205 #endif /* !__REACTOS__ */
206 }
207
208 BOOLEAN
209 INF_GetDataField(
210 IN PINFCONTEXT Context,
211 IN ULONG FieldIndex,
212 OUT PWCHAR *Data)
213 {
214 #ifdef __REACTOS__
215 return InfGetDataField(Context, FieldIndex, Data);
216 #else
217 static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
218 static DWORD NextIndex = 0;
219 DWORD dwSize;
220 BOOL ret;
221
222 *Data = NULL;
223
224 ret = SetupGetStringFieldW(
225 Context,
226 FieldIndex,
227 NULL,
228 0,
229 &dwSize);
230 if (!ret)
231 return FALSE;
232 HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
233 pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
234 ret = SetupGetStringFieldW(
235 Context,
236 FieldIndex,
237 pLastCallsData[NextIndex],
238 dwSize,
239 NULL);
240 if (!ret)
241 return FALSE;
242
243 *Data = pLastCallsData[NextIndex];
244 NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
245 return TRUE;
246 #endif /* !__REACTOS__ */
247 }
248
249 HINF WINAPI
250 INF_OpenBufferedFileA(
251 IN PSTR FileBuffer,
252 IN ULONG FileSize,
253 IN PCSTR InfClass,
254 IN DWORD InfStyle,
255 OUT PUINT ErrorLine)
256 {
257 #ifdef __REACTOS__
258 HINF hInf = NULL;
259 ULONG ErrorLineUL;
260 NTSTATUS Status;
261
262 Status = InfOpenBufferedFile(
263 &hInf,
264 FileBuffer,
265 FileSize,
266 &ErrorLineUL);
267 *ErrorLine = (UINT)ErrorLineUL;
268 if (!NT_SUCCESS(Status))
269 return INVALID_HANDLE_VALUE;
270
271 return hInf;
272 #else
273 return INVALID_HANDLE_VALUE;
274 #endif /* !__REACTOS__ */
275 }
276
277 VOID INF_SetHeap(
278 IN PVOID Heap)
279 {
280 #ifdef __REACTOS__
281 InfSetHeap(Heap);
282 #endif
283 }
284
285 /* EOF */