[USETUP] Get rid of the interface directory because we support text-mode only
[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: base/setup/usetup/inffile.c
23 * PURPOSE: .inf files support functions
24 * PROGRAMMER: Hervé Poussineau
25 */
26
27 /* INCLUDES ******************************************************************/
28
29 #include "usetup.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* FUNCTIONS *****************************************************************/
35
36 #ifdef __REACTOS__
37
38 BOOL
39 WINAPI
40 InfpFindFirstLineW(
41 IN HINF InfHandle,
42 IN PCWSTR Section,
43 IN PCWSTR Key,
44 IN OUT PINFCONTEXT Context)
45 {
46 PINFCONTEXT pContext;
47 BOOL ret;
48
49 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
50 if (!ret)
51 return FALSE;
52
53 memcpy(Context, pContext, sizeof(INFCONTEXT));
54 InfFreeContext(pContext);
55 return TRUE;
56 }
57
58
59 HINF
60 WINAPI
61 InfpOpenInfFileW(
62 IN PCWSTR FileName,
63 IN PCWSTR InfClass,
64 IN DWORD InfStyle,
65 IN LCID LocaleId,
66 OUT PUINT ErrorLine)
67 {
68 HINF hInf = NULL;
69 UNICODE_STRING FileNameU;
70 ULONG ErrorLineUL;
71 NTSTATUS Status;
72
73 RtlInitUnicodeString(&FileNameU, FileName);
74 Status = InfOpenFile(&hInf,
75 &FileNameU,
76 LANGIDFROMLCID(LocaleId),
77 &ErrorLineUL);
78 *ErrorLine = (UINT)ErrorLineUL;
79 if (!NT_SUCCESS(Status))
80 return INVALID_HANDLE_VALUE;
81
82 return hInf;
83 }
84 #endif /* __REACTOS__ */
85
86
87 BOOLEAN
88 INF_GetData(
89 IN PINFCONTEXT Context,
90 OUT PWCHAR *Key,
91 OUT PWCHAR *Data)
92 {
93 #ifdef __REACTOS__
94 return InfGetData(Context, Key, Data);
95 #else
96 static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
97 static DWORD currentIndex = 0;
98 DWORD dwSize, i;
99 BOOL ret;
100
101 currentIndex ^= 2;
102
103 if (Key)
104 *Key = NULL;
105
106 if (Data)
107 *Data = NULL;
108
109 if (SetupGetFieldCount(Context) != 1)
110 return FALSE;
111
112 for (i = 0; i <= 1; i++)
113 {
114 ret = SetupGetStringFieldW(Context,
115 i,
116 NULL,
117 0,
118 &dwSize);
119 if (!ret)
120 return FALSE;
121
122 HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
123 pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
124 ret = SetupGetStringFieldW(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
136 if (Data)
137 *Data = pLastCallData[1 + currentIndex];
138
139 return TRUE;
140 #endif /* !__REACTOS__ */
141 }
142
143
144 BOOLEAN
145 INF_GetDataField(
146 IN PINFCONTEXT Context,
147 IN ULONG FieldIndex,
148 OUT PWCHAR *Data)
149 {
150 #ifdef __REACTOS__
151 return InfGetDataField(Context, FieldIndex, Data);
152 #else
153 static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
154 static DWORD NextIndex = 0;
155 DWORD dwSize;
156 BOOL ret;
157
158 *Data = NULL;
159
160 ret = SetupGetStringFieldW(Context,
161 FieldIndex,
162 NULL,
163 0,
164 &dwSize);
165 if (!ret)
166 return FALSE;
167
168 HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
169 pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
170 ret = SetupGetStringFieldW(Context,
171 FieldIndex,
172 pLastCallsData[NextIndex],
173 dwSize,
174 NULL);
175 if (!ret)
176 return FALSE;
177
178 *Data = pLastCallsData[NextIndex];
179 NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
180 return TRUE;
181 #endif /* !__REACTOS__ */
182 }
183
184
185 HINF WINAPI
186 INF_OpenBufferedFileA(
187 IN PSTR FileBuffer,
188 IN ULONG FileSize,
189 IN PCSTR InfClass,
190 IN DWORD InfStyle,
191 IN LCID LocaleId,
192 OUT PUINT ErrorLine)
193 {
194 #ifdef __REACTOS__
195 HINF hInf = NULL;
196 ULONG ErrorLineUL;
197 NTSTATUS Status;
198
199 Status = InfOpenBufferedFile(&hInf,
200 FileBuffer,
201 FileSize,
202 LANGIDFROMLCID(LocaleId),
203 &ErrorLineUL);
204 *ErrorLine = (UINT)ErrorLineUL;
205 if (!NT_SUCCESS(Status))
206 return INVALID_HANDLE_VALUE;
207
208 return hInf;
209 #else
210 return INVALID_HANDLE_VALUE;
211 #endif /* !__REACTOS__ */
212 }
213
214 /* EOF */