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