ReactOS  0.4.12-dev-708-g95ed44e
infsupp.c
Go to the documentation of this file.
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/lib/infsupp.c
23  * PURPOSE: Interfacing with Setup* API .INF Files support functions
24  * PROGRAMMERS: HervĂ© Poussineau
25  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
26  */
27 
28 /* INCLUDES ******************************************************************/
29 
30 #include "usetup.h"
31 
32 #define NDEBUG
33 #include <debug.h>
34 
35 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
36 
37 /* Functions from the INFLIB library */
38 
39 extern VOID InfCloseFile(HINF InfHandle);
40 // #define SetupCloseInfFile InfCloseFile
41 VOID
42 WINAPI
44  IN HINF InfHandle)
45 {
46  if (InfHandle == INVALID_HANDLE_VALUE)
47  return;
48  InfCloseFile(InfHandle);
49 }
50 
51 // #define SetupFindFirstLineW InfpFindFirstLineW
52 BOOL
53 WINAPI
55  IN HINF InfHandle,
56  IN PCWSTR Section,
57  IN PCWSTR Key,
59 {
60  PINFCONTEXT pContext;
61  BOOL ret;
62 
63  if (InfHandle == INVALID_HANDLE_VALUE)
64  return FALSE;
65 
66  ret = InfFindFirstLine(InfHandle, Section, Key, &pContext);
67  if (!ret)
68  return FALSE;
69 
70  memcpy(Context, pContext, sizeof(INFCONTEXT));
71  InfFreeContext(pContext);
72  return TRUE;
73 }
74 
75 extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn,
76  PINFCONTEXT ContextOut);
77 // #define SetupFindNextLine InfFindNextLine
78 BOOL
79 WINAPI
81  IN PINFCONTEXT ContextIn,
82  OUT PINFCONTEXT ContextOut)
83 {
84  return !!InfFindNextLine(ContextIn, ContextOut);
85 }
86 
88 // #define SetupGetFieldCount InfGetFieldCount
89 ULONG
90 WINAPI
93 {
95 }
96 
97 /*
98  * This function corresponds to an undocumented but exported SetupAPI function
99  * that exists since WinNT4 and is still present in Win10.
100  * The returned string pointer is a read-only pointer to a string in the
101  * maintained INF cache, and is always in UNICODE (on NT systems).
102  */
105  PWCHAR *Data);
106 PCWSTR
107 WINAPI
111 {
112  PWCHAR Data = NULL;
114  return NULL;
115  return Data;
116 }
117 
120  PUCHAR ReturnBuffer,
123 // #define SetupGetBinaryField InfGetBinaryField
124 BOOL
125 WINAPI
129  OUT PUCHAR ReturnBuffer,
132 {
133  return !!InfGetBinaryField(Context,
134  FieldIndex,
135  ReturnBuffer,
137  RequiredSize);
138 }
139 
142  INT *IntegerValue);
143 // #define SetupGetIntField InfGetIntField
144 BOOL
145 WINAPI
149  OUT INT *IntegerValue) // PINT
150 {
151  return !!InfGetIntField(Context, FieldIndex, IntegerValue);
152 }
153 
156  PWSTR ReturnBuffer,
159 // #define SetupGetMultiSzFieldW InfGetMultiSzField
160 BOOL
161 WINAPI
165  OUT PWSTR ReturnBuffer,
168 {
169  return !!InfGetMultiSzField(Context,
170  FieldIndex,
171  ReturnBuffer,
173  RequiredSize);
174 }
175 
178  PWSTR ReturnBuffer,
181 // #define SetupGetStringFieldW InfGetStringField
182 BOOL
183 WINAPI
187  OUT PWSTR ReturnBuffer,
190 {
191  return !!InfGetStringField(Context,
192  FieldIndex,
193  ReturnBuffer,
195  RequiredSize);
196 }
197 
198 /* SetupOpenInfFileW with support for a user-provided LCID */
199 // #define SetupOpenInfFileExW InfpOpenInfFileW
200 HINF
201 WINAPI
204  IN PCWSTR InfClass,
205  IN DWORD InfStyle,
206  IN LCID LocaleId,
207  OUT PUINT ErrorLine)
208 {
209  HINF hInf = NULL;
210  UNICODE_STRING FileNameU;
211  ULONG ErrorLineUL;
213 
214  RtlInitUnicodeString(&FileNameU, FileName);
215  Status = InfOpenFile(&hInf,
216  &FileNameU,
217  LANGIDFROMLCID(LocaleId),
218  &ErrorLineUL);
219  *ErrorLine = (UINT)ErrorLineUL;
220  if (!NT_SUCCESS(Status))
221  return INVALID_HANDLE_VALUE;
222 
223  return hInf;
224 }
225 
226 
227 /* GLOBALS *******************************************************************/
228 
239 
240 
241 /* HELPER FUNCTIONS **********************************************************/
242 
243 HINF WINAPI
245  IN PSTR FileBuffer,
246  IN ULONG FileSize,
247  IN PCSTR InfClass,
248  IN DWORD InfStyle,
249  IN LCID LocaleId,
250  OUT PUINT ErrorLine)
251 {
252  HINF hInf = NULL;
253  ULONG ErrorLineUL;
255 
256  Status = InfOpenBufferedFile(&hInf,
257  FileBuffer,
258  FileSize,
259  LANGIDFROMLCID(LocaleId),
260  &ErrorLineUL);
261  *ErrorLine = (UINT)ErrorLineUL;
262  if (!NT_SUCCESS(Status))
263  return INVALID_HANDLE_VALUE;
264 
265  return hInf;
266 }
267 
268 /* EOF */
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
PCWSTR(WINAPI * pSpInfGetField)(IN PINFCONTEXT Context, IN ULONG FieldIndex)
Definition: infsupp.h:134
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
BOOL(WINAPI * pSpInfGetMultiSzField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:112
#define TRUE
Definition: types.h:120
BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn, PINFCONTEXT ContextOut)
Definition: inffile.c:1125
HINF(WINAPI * pSpInfOpenInfFile)(IN PCWSTR FileName, IN PCWSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.h:143
uint16_t * PWSTR
Definition: typedefs.h:54
unsigned char * PUCHAR
Definition: retypes.h:3
pSpInfCloseInfFile SpInfCloseInfFile
Definition: infsupp.c:86
NTSTATUS InfOpenBufferedFile(PHINF InfHandle, PVOID Buffer, ULONG BufferSize, LANGID LanguageId, PULONG ErrorLine)
Definition: infrosgen.c:51
pSpInfFindNextLine SpInfFindNextLine
Definition: infsupp.c:88
LONG NTSTATUS
Definition: precomp.h:26
ULONG(WINAPI * pSpInfGetFieldCount)(IN PINFCONTEXT Context)
Definition: infsupp.h:85
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1891
DWORD LCID
Definition: nls.h:13
uint16_t * PWCHAR
Definition: typedefs.h:54
int32_t INT
Definition: typedefs.h:56
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
BOOLEAN InfGetDataField(PINFCONTEXT Context, ULONG FieldIndex, PWCHAR *Data)
Definition: infrosget.c:127
BOOL(WINAPI * pSpInfFindFirstLine)(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.h:67
pSpInfFindFirstLine SpInfFindFirstLine
Definition: infsupp.c:87
pSpInfGetBinaryField SpInfGetBinaryField
Definition: infsupp.c:90
BOOL(WINAPI * pSpInfFindNextLine)(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.h:77
long LONG
Definition: pedump.c:60
BOOL WINAPI SetupGetBinaryField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:126
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID InfFreeContext(PINFCONTEXT Context)
Definition: infrosget.c:135
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, INT *IntegerValue)
Definition: inffile.c:1335
pSpInfGetFieldCount SpInfGetFieldCount
Definition: infsupp.c:89
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
BOOLEAN InfGetBinaryField(PINFCONTEXT Context, ULONG FieldIndex, PUCHAR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: inffile.c:1278
LONG InfGetFieldCount(PINFCONTEXT Context)
Definition: inffile.c:1268
unsigned int BOOL
Definition: ntddk_ex.h:94
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_In_ DWORD FieldIndex
Definition: setupapi.h:1889
pSpInfGetStringField SpInfGetStringField
Definition: infsupp.c:93
unsigned long DWORD
Definition: ntddk_ex.h:95
pSpInfGetField SpInfGetField
Definition: infsupp.c:94
int ret
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:91
PCWSTR WINAPI pSetupGetField(IN PINFCONTEXT Context, IN ULONG FieldIndex)
Definition: infsupp.c:108
VOID InfCloseFile(HINF InfHandle)
Definition: inffile.c:1046
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define LANGIDFROMLCID(l)
Definition: nls.h:18
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
pSpInfGetIntField SpInfGetIntField
Definition: infsupp.c:91
HINF WINAPI INF_OpenBufferedFileA(IN PSTR FileBuffer, IN ULONG FileSize, IN PCSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.c:244
#define WINAPI
Definition: msvc.h:20
BOOL(WINAPI * pSpInfGetBinaryField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:92
Status
Definition: gdiplustypes.h:24
pSpInfGetMultiSzField SpInfGetMultiSzField
Definition: infsupp.c:92
HINF WINAPI SetupOpenInfFileExW(IN PCWSTR FileName, IN PCWSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.c:35
BOOL WINAPI SetupGetMultiSzFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:162
BOOLEAN InfFindFirstLine(HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context)
Definition: inffile.c:1068
BOOLEAN InfOpenFile(PHINF InfHandle, PCSTR FileName, PULONG ErrorLine)
Definition: inffile.c:936
pSpInfOpenInfFile SpInfOpenInfFile
Definition: infsupp.c:95
signed char * PSTR
Definition: retypes.h:7
unsigned int * PULONG
Definition: retypes.h:1
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:80
VOID(WINAPI * pSpInfCloseInfFile)(IN HINF InfHandle)
Definition: infsupp.h:60
BOOL WINAPI SetupGetIntField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.c:146
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
const char * PCSTR
Definition: typedefs.h:51
#define UINT
Definition: msvc.h:27
unsigned int * PUINT
Definition: ndis.h:50
BOOL(WINAPI * pSpInfGetStringField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:123
BOOLEAN InfGetStringField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infrosget.c:106
BOOL(WINAPI * pSpInfGetIntField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.h:103
BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, ULONG ReturnBufferSize, PULONG RequiredSize)
Definition: infrosget.c:94
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184