ReactOS  0.4.14-dev-115-g4576127
infsupp.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS GUI first stage setup application
4  * FILE: base/setup/lib/infsupp.c
5  * PURPOSE: Interfacing with Setup* API .INF Files support functions
6  * PROGRAMMERS: HervĂ© Poussineau
7  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include "reactos.h"
13 #include <winnls.h>
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
19 
20 /*
21  * This function corresponds to an undocumented but exported SetupAPI function
22  * that exists since WinNT4 and is still present in Win10.
23  * The returned string pointer is a read-only pointer to a string in the
24  * maintained INF cache, and is always in UNICODE (on NT systems).
25  */
26 PCWSTR
27 WINAPI
31 
32 /* SetupOpenInfFileW with support for a user-provided LCID */
33 HINF
34 WINAPI
37  IN PCWSTR InfClass,
38  IN DWORD InfStyle,
39  IN LCID LocaleId,
40  OUT PUINT ErrorLine)
41 {
42  HINF InfHandle;
43  LCID OldLocaleId;
44  WCHAR Win32FileName[MAX_PATH];
45 
46  /*
47  * SetupOpenInfFileExW is called within setuplib with NT paths, however
48  * the Win32 SetupOpenInfFileW API only takes Win32 paths. We therefore
49  * map the NT path to Win32 path and then call the Win32 API.
50  */
52  Win32FileName,
53  _countof(Win32FileName),
54  FileName))
55  {
56  return INVALID_HANDLE_VALUE;
57  }
58 
59  /*
60  * Because SetupAPI's SetupOpenInfFileW() function does not allow the user
61  * to specify a given LCID to use to load localized string substitutions,
62  * we temporarily change the current thread locale before calling
63  * SetupOpenInfFileW(). When we have finished we restore the original
64  * thread locale.
65  */
66  OldLocaleId = GetThreadLocale();
67  if (OldLocaleId != LocaleId)
68  SetThreadLocale(LocaleId);
69 
70  /* Load the INF file */
71  InfHandle = SetupOpenInfFileW(Win32FileName,
72  InfClass,
73  InfStyle,
74  ErrorLine);
75 
76  /* Restore the original thread locale */
77  if (OldLocaleId != LocaleId)
78  SetThreadLocale(OldLocaleId);
79 
80  return InfHandle;
81 }
82 
83 
84 /* GLOBALS *******************************************************************/
85 
96 
97 
98 /* HELPER FUNCTIONS **********************************************************/
99 
100 #if 0
101 
102 HINF WINAPI
104  IN PSTR FileBuffer,
105  IN ULONG FileSize,
106  IN PCSTR InfClass,
107  IN DWORD InfStyle,
108  IN LCID LocaleId,
109  OUT PUINT ErrorLine)
110 {
111 #ifdef __REACTOS__
112  HINF hInf = NULL;
113  ULONG ErrorLineUL;
115 
116  Status = InfOpenBufferedFile(&hInf,
117  FileBuffer,
118  FileSize,
119  LANGIDFROMLCID(LocaleId),
120  &ErrorLineUL);
121  *ErrorLine = (UINT)ErrorLineUL;
122  if (!NT_SUCCESS(Status))
123  return INVALID_HANDLE_VALUE;
124 
125  return hInf;
126 #else
127  return INVALID_HANDLE_VALUE;
128 #endif /* !__REACTOS__ */
129 }
130 
131 #endif
132 
133 /* 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
HINF(WINAPI * pSpInfOpenInfFile)(IN PCWSTR FileName, IN PCWSTR InfClass, IN DWORD InfStyle, IN LCID LocaleId, OUT PUINT ErrorLine)
Definition: infsupp.h:143
#define _countof(array)
Definition: fontsub.cpp:30
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
DWORD LCID
Definition: nls.h:13
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
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
BOOL WINAPI SetThreadLocale(LCID lcid)
Definition: lang.c:1468
pSpInfGetBinaryField SpInfGetBinaryField
Definition: infsupp.c:90
BOOL(WINAPI * pSpInfFindNextLine)(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.h:77
BOOL WINAPI SetupGetBinaryField(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PUCHAR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:126
smooth NULL
Definition: ftsmooth.c:416
BOOL ConvertNtPathToWin32Path(IN OUT PNT_WIN32_PATH_MAPPING_LIST MappingList, OUT PWSTR pwszPath, IN DWORD cchPathMax, IN PCWSTR pwszNTPath)
Definition: reactos.c:1498
pSpInfGetFieldCount SpInfGetFieldCount
Definition: infsupp.c:89
NT_WIN32_PATH_MAPPING_LIST MappingList
Definition: reactos.h:126
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ DWORD FieldIndex
Definition: setupapi.h:1890
pSpInfGetStringField SpInfGetStringField
Definition: infsupp.c:93
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
pSpInfGetField SpInfGetField
Definition: infsupp.c:94
SETUPDATA SetupData
Definition: reactos.c:41
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:91
PCWSTR WINAPI pSetupGetField(IN PINFCONTEXT Context, IN ULONG FieldIndex)
Definition: infsupp.c:108
#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
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
pSpInfOpenInfFile SpInfOpenInfFile
Definition: infsupp.c:95
signed char * PSTR
Definition: retypes.h:7
unsigned int UINT
Definition: ndis.h:50
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
const char * PCSTR
Definition: typedefs.h:51
unsigned int * PUINT
Definition: ndis.h:50
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1449
BOOL(WINAPI * pSpInfGetStringField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.h:123
BOOL(WINAPI * pSpInfGetIntField)(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT INT *IntegerValue)
Definition: infsupp.h:103
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184