[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 BOOL WINAPI
43 InfpFindFirstLineW(
44 IN HINF InfHandle,
45 IN PCWSTR Section,
46 IN PCWSTR Key,
47 IN OUT PINFCONTEXT Context)
48 {
49 PINFCONTEXT pContext;
50 BOOL ret;
51
52 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
53 if (!ret)
54 return FALSE;
55
56 memcpy(Context, pContext, sizeof(INFCONTEXT));
57 InfFreeContext(pContext);
58 return TRUE;
59 }
60
61 HINF WINAPI
62 InfpOpenInfFileW(
63 IN PCWSTR FileName,
64 IN PCWSTR InfClass,
65 IN DWORD InfStyle,
66 IN LCID LocaleId,
67 OUT PUINT ErrorLine)
68 {
69 HINF hInf = NULL;
70 UNICODE_STRING FileNameU;
71 ULONG ErrorLineUL;
72 NTSTATUS Status;
73
74 RtlInitUnicodeString(&FileNameU, FileName);
75 Status = InfOpenFile(
76 &hInf,
77 &FileNameU,
78 LocaleId,
79 &ErrorLineUL);
80 *ErrorLine = (UINT)ErrorLineUL;
81 if (!NT_SUCCESS(Status))
82 return INVALID_HANDLE_VALUE;
83
84 return hInf;
85 }
86
87 #endif /* __REACTOS__ */
88
89 BOOLEAN
90 INF_GetData(
91 IN PINFCONTEXT Context,
92 OUT PWCHAR *Key,
93 OUT PWCHAR *Data)
94 {
95 #ifdef __REACTOS__
96 return InfGetData(Context, Key, Data);
97 #else
98 static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
99 static DWORD currentIndex = 0;
100 DWORD dwSize, i;
101 BOOL ret;
102
103 currentIndex ^= 2;
104
105 if (Key) *Key = NULL;
106 if (Data) *Data = NULL;
107
108 if (SetupGetFieldCount(Context) != 1)
109 return FALSE;
110
111 for (i = 0; i <= 1; i++)
112 {
113 ret = SetupGetStringFieldW(
114 Context,
115 i,
116 NULL,
117 0,
118 &dwSize);
119 if (!ret)
120 return FALSE;
121 HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
122 pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
123 ret = SetupGetStringFieldW(
124 Context,
125 i,
126 pLastCallData[i + currentIndex],
127 dwSize,
128 NULL);
129 if (!ret)
130 return FALSE;
131 }
132
133 if (Key)
134 *Key = pLastCallData[0 + currentIndex];
135 if (Data)
136 *Data = pLastCallData[1 + currentIndex];
137 return TRUE;
138 #endif /* !__REACTOS__ */
139 }
140
141 BOOLEAN
142 INF_GetDataField(
143 IN PINFCONTEXT Context,
144 IN ULONG FieldIndex,
145 OUT PWCHAR *Data)
146 {
147 #ifdef __REACTOS__
148 return InfGetDataField(Context, FieldIndex, Data);
149 #else
150 static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
151 static DWORD NextIndex = 0;
152 DWORD dwSize;
153 BOOL ret;
154
155 *Data = NULL;
156
157 ret = SetupGetStringFieldW(
158 Context,
159 FieldIndex,
160 NULL,
161 0,
162 &dwSize);
163 if (!ret)
164 return FALSE;
165 HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
166 pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
167 ret = SetupGetStringFieldW(
168 Context,
169 FieldIndex,
170 pLastCallsData[NextIndex],
171 dwSize,
172 NULL);
173 if (!ret)
174 return FALSE;
175
176 *Data = pLastCallsData[NextIndex];
177 NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
178 return TRUE;
179 #endif /* !__REACTOS__ */
180 }
181
182 HINF WINAPI
183 INF_OpenBufferedFileA(
184 IN PSTR FileBuffer,
185 IN ULONG FileSize,
186 IN PCSTR InfClass,
187 IN DWORD InfStyle,
188 IN LCID LocaleId,
189 OUT PUINT ErrorLine)
190 {
191 #ifdef __REACTOS__
192 HINF hInf = NULL;
193 ULONG ErrorLineUL;
194 NTSTATUS Status;
195
196 Status = InfOpenBufferedFile(
197 &hInf,
198 FileBuffer,
199 FileSize,
200 LocaleId,
201 &ErrorLineUL);
202 *ErrorLine = (UINT)ErrorLineUL;
203 if (!NT_SUCCESS(Status))
204 return INVALID_HANDLE_VALUE;
205
206 return hInf;
207 #else
208 return INVALID_HANDLE_VALUE;
209 #endif /* !__REACTOS__ */
210 }
211
212 /* EOF */