merge trunk head (37902)
[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 InfpGetMultiSzFieldW(
70 IN PINFCONTEXT Context,
71 IN ULONG FieldIndex,
72 IN OUT PWSTR ReturnBuffer,
73 IN ULONG ReturnBufferSize,
74 OUT PULONG RequiredSize)
75 {
76 return InfGetMultiSzField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize);
77 }
78
79 BOOL WINAPI
80 InfpGetStringFieldW(
81 IN PINFCONTEXT Context,
82 IN ULONG FieldIndex,
83 IN OUT PWSTR ReturnBuffer,
84 IN ULONG ReturnBufferSize,
85 OUT PULONG RequiredSize)
86 {
87 return InfGetStringField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize);
88 }
89
90 HINF WINAPI
91 InfpOpenInfFileW(
92 IN PCWSTR FileName,
93 IN PCWSTR InfClass,
94 IN DWORD InfStyle,
95 OUT PUINT ErrorLine)
96 {
97 HINF hInf = NULL;
98 UNICODE_STRING FileNameU;
99 ULONG ErrorLineUL;
100 NTSTATUS Status;
101
102 RtlInitUnicodeString(&FileNameU, FileName);
103 Status = InfOpenFile(
104 &hInf,
105 &FileNameU,
106 &ErrorLineUL);
107 *ErrorLine = (UINT)ErrorLineUL;
108 if (!NT_SUCCESS(Status))
109 return INVALID_HANDLE_VALUE;
110
111 return hInf;
112 }
113
114 #endif /* __REACTOS__ */
115
116 BOOLEAN
117 INF_GetData(
118 IN PINFCONTEXT Context,
119 OUT PWCHAR *Key,
120 OUT PWCHAR *Data)
121 {
122 #ifdef __REACTOS__
123 return InfGetData(Context, Key, Data);
124 #else
125 static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
126 static DWORD currentIndex = 0;
127 DWORD dwSize, i;
128 BOOL ret;
129
130 currentIndex ^= 2;
131
132 if (Key) *Key = NULL;
133 if (Data) *Data = NULL;
134
135 if (SetupGetFieldCount(Context) != 1)
136 return FALSE;
137
138 for (i = 0; i <= 1; i++)
139 {
140 ret = SetupGetStringFieldW(
141 Context,
142 i,
143 NULL,
144 0,
145 &dwSize);
146 if (!ret)
147 return FALSE;
148 HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
149 pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
150 ret = SetupGetStringFieldW(
151 Context,
152 i,
153 pLastCallData[i + currentIndex],
154 dwSize,
155 NULL);
156 if (!ret)
157 return FALSE;
158 }
159
160 if (Key)
161 *Key = pLastCallData[0 + currentIndex];
162 if (Data)
163 *Data = pLastCallData[1 + currentIndex];
164 return TRUE;
165 #endif /* !__REACTOS__ */
166 }
167
168 BOOLEAN
169 INF_GetDataField(
170 IN PINFCONTEXT Context,
171 IN ULONG FieldIndex,
172 OUT PWCHAR *Data)
173 {
174 #ifdef __REACTOS__
175 return InfGetDataField(Context, FieldIndex, Data);
176 #else
177 static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
178 static DWORD NextIndex = 0;
179 DWORD dwSize;
180 BOOL ret;
181
182 *Data = NULL;
183
184 ret = SetupGetStringFieldW(
185 Context,
186 FieldIndex,
187 NULL,
188 0,
189 &dwSize);
190 if (!ret)
191 return FALSE;
192 HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
193 pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
194 ret = SetupGetStringFieldW(
195 Context,
196 FieldIndex,
197 pLastCallsData[NextIndex],
198 dwSize,
199 NULL);
200 if (!ret)
201 return FALSE;
202
203 *Data = pLastCallsData[NextIndex];
204 NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
205 return TRUE;
206 #endif /* !__REACTOS__ */
207 }
208
209 HINF WINAPI
210 INF_OpenBufferedFileA(
211 IN PSTR FileBuffer,
212 IN ULONG FileSize,
213 IN PCSTR InfClass,
214 IN DWORD InfStyle,
215 OUT PUINT ErrorLine)
216 {
217 #ifdef __REACTOS__
218 HINF hInf = NULL;
219 ULONG ErrorLineUL;
220 NTSTATUS Status;
221
222 Status = InfOpenBufferedFile(
223 &hInf,
224 FileBuffer,
225 FileSize,
226 &ErrorLineUL);
227 *ErrorLine = (UINT)ErrorLineUL;
228 if (!NT_SUCCESS(Status))
229 return INVALID_HANDLE_VALUE;
230
231 return hInf;
232 #else
233 return INVALID_HANDLE_VALUE;
234 #endif /* !__REACTOS__ */
235 }
236
237 VOID INF_SetHeap(
238 IN PVOID Heap)
239 {
240 #ifdef __REACTOS__
241 InfSetHeap(Heap);
242 #endif
243 }
244
245 /* EOF */