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