Author: hbelusca
Date: Wed Aug 9 20:12:00 2017
New Revision: 75515
URL:
http://svn.reactos.org/svn/reactos?rev=75515&view=rev
Log:
[USETUP][SETUPLIB]: Move some INF-related code from usetup to the setuplib.
- Move the generic INF_GetDataField() and INF_GetData() helpers to setuplib, and rework
them a bit so that they explicitly call setupapi functions (or implementations thereof
when being used in usetup);
- Rework the headers in accordance;
- and Fix compilation in lib/registry.c .
Added:
branches/setup_improvements/base/setup/lib/infsupp.c (with props)
Modified:
branches/setup_improvements/base/setup/lib/infsupp.h
branches/setup_improvements/base/setup/lib/registry.c
branches/setup_improvements/base/setup/usetup/inffile.c
branches/setup_improvements/base/setup/usetup/inffile.h
branches/setup_improvements/base/setup/usetup/usetup.h
Added: branches/setup_improvements/base/setup/lib/infsupp.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/infsupp.c (added)
+++ branches/setup_improvements/base/setup/lib/infsupp.c [iso-8859-1] Wed Aug 9 20:12:00
2017
@@ -0,0 +1,119 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS Setup Library
+ * FILE: base/setup/lib/infsupp.c
+ * PURPOSE: Interfacing with Setup* API .inf files support functions
+ * PROGRAMMERS: Hervé Poussineau
+ * Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "precomp.h"
+#include "infsupp.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* HELPER FUNCTIONS **********************************************************/
+
+BOOLEAN
+INF_GetDataField(
+ IN PINFCONTEXT Context,
+ IN ULONG FieldIndex,
+ OUT PWCHAR *Data)
+{
+#if 0
+
+ BOOL Success;
+ PWCHAR InfData;
+ DWORD dwSize;
+
+ *Data = NULL;
+
+ Success = SetupGetStringFieldW(Context,
+ FieldIndex,
+ NULL,
+ 0,
+ &dwSize);
+ if (!Success)
+ return FALSE;
+
+ InfData = RtlAllocateHeap(ProcessHeap, 0, dwSize * sizeof(WCHAR));
+ if (!InfData)
+ return FALSE;
+
+ Success = SetupGetStringFieldW(Context,
+ FieldIndex,
+ InfData,
+ dwSize,
+ NULL);
+ if (!Success)
+ {
+ RtlFreeHeap(ProcessHeap, 0, InfData);
+ return FALSE;
+ }
+
+ *Data = InfData;
+ return TRUE;
+
+#else
+
+ *Data = (PWCHAR)pSetupGetField(Context, FieldIndex);
+ return !!*Data;
+
+#endif
+}
+
+BOOLEAN
+INF_GetData(
+ IN PINFCONTEXT Context,
+ OUT PWCHAR *Key,
+ OUT PWCHAR *Data)
+{
+ BOOL Success;
+ PWCHAR InfData[2] = {NULL, NULL};
+
+ if (Key)
+ *Key = NULL;
+
+ if (Data)
+ *Data = NULL;
+
+ /*
+ * Verify that the INF file has only one value field, in addition to its key name.
+ * Note that SetupGetFieldCount() does not count the key name as a field.
+ */
+ if (SetupGetFieldCount(Context) != 1)
+ {
+ DPRINT1("SetupGetFieldCount != 1\n");
+ return FALSE;
+ }
+
+ if (Key)
+ {
+ Success = INF_GetDataField(Context, 0, &InfData[0]);
+ if (!Success)
+ return FALSE;
+ }
+
+ if (Data)
+ {
+ Success = INF_GetDataField(Context, 1, &InfData[1]);
+ if (!Success)
+ {
+ INF_FreeData(InfData[0]);
+ return FALSE;
+ }
+ }
+
+ if (Key)
+ *Key = InfData[0];
+
+ if (Data)
+ *Data = InfData[1];
+
+ return TRUE;
+}
+
+/* EOF */
Propchange: branches/setup_improvements/base/setup/lib/infsupp.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: branches/setup_improvements/base/setup/lib/infsupp.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/infsupp.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/infsupp.h [iso-8859-1] Wed Aug 9 20:12:00
2017
@@ -8,39 +8,123 @@
#pragma once
-// #ifndef __REACTOS__
+#ifdef __REACTOS__
+#define _SETUPAPI_
+#endif
-#define _SETUPAPI_
+// FIXME: Temporary measure until all the users of this header
+// (usetup...) use or define SetupAPI-conforming APIs.
+#if 0
+
#include <setupapi.h>
+
+#else
+
+typedef PVOID HINF;
+typedef struct _INFCONTEXT
+{
+ HINF Inf;
+ HINF CurrentInf;
+ UINT Section;
+ UINT Line;
+} INFCONTEXT, *PINFCONTEXT;
+
+// #define SetupCloseInfFile InfCloseFile
+VOID
+WINAPI
+SetupCloseInfFile(HINF InfHandle);
+
+// #define SetupFindFirstLineW InfpFindFirstLineW
+BOOL
+WINAPI
+SetupFindFirstLineW(
+ IN HINF InfHandle,
+ IN PCWSTR Section,
+ IN PCWSTR Key,
+ IN OUT PINFCONTEXT Context);
+
+// #define SetupFindNextLine InfFindNextLine
+BOOL
+WINAPI
+SetupFindNextLine(PINFCONTEXT ContextIn,
+ PINFCONTEXT ContextOut);
+
+// #define SetupGetFieldCount InfGetFieldCount
+LONG
+WINAPI
+SetupGetFieldCount(PINFCONTEXT Context);
+
+// #define SetupGetBinaryField InfGetBinaryField
+BOOL
+WINAPI
+SetupGetBinaryField(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ PUCHAR ReturnBuffer,
+ ULONG ReturnBufferSize,
+ PULONG RequiredSize);
+
+// #define SetupGetIntField InfGetIntField
+BOOLEAN
+WINAPI
+SetupGetIntField(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ INT *IntegerValue);
+
+// #define SetupGetMultiSzFieldW InfGetMultiSzField
+BOOL
+WINAPI
+SetupGetMultiSzFieldW(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ PWSTR ReturnBuffer,
+ ULONG ReturnBufferSize,
+ PULONG RequiredSize);
+
+// #define SetupGetStringFieldW InfGetStringField
+BOOL
+WINAPI
+SetupGetStringFieldW(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ PWSTR ReturnBuffer,
+ ULONG ReturnBufferSize,
+ PULONG RequiredSize);
+
+#endif
/* Lower the MAX_INF_STRING_LENGTH value in order to avoid too much stack usage */
#undef MAX_INF_STRING_LENGTH
#define MAX_INF_STRING_LENGTH 1024 // Still larger than in infcommon.h
-// #else /* __REACTOS__ */
-
-// /* Functions from the INFLIB library */
-// #include <infcommon.h>
-
-#define INF_STYLE_WIN4 0x00000002
+#ifndef INF_STYLE_WIN4
+#define INF_STYLE_WIN4 0x00000002
+#endif
#if 0
-/* FIXME: this structure is the one used in inflib, not in setupapi
- * Delete it once we don't use inflib anymore */
+typedef PVOID HINF;
typedef struct _INFCONTEXT
{
- PVOID Inf;
- PVOID CurrentInf;
- PVOID Section;
- PVOID Line;
-} INFCONTEXT;
-#else
-C_ASSERT(sizeof(INFCONTEXT) == 2 * sizeof(PVOID) + 2 * sizeof(UINT));
+ HINF Inf;
+ HINF CurrentInf;
+ UINT Section;
+ UINT Line;
+} INFCONTEXT, *PINFCONTEXT;
#endif
-// #endif
+C_ASSERT(sizeof(INFCONTEXT) == 2 * sizeof(HINF) + 2 * sizeof(UINT));
-/* SetupOpenInfFileW with support for a user-provided LCID */
+
+/*
+ * This function corresponds to an undocumented but exported SetupAPI function
+ * that exists since WinNT4 and is still present in Win10.
+ * The returned string pointer is a read-only pointer to a string in the
+ * maintained INF cache, and is always in UNICODE (on NT systems).
+ */
+PCWSTR
+WINAPI
+pSetupGetField(PINFCONTEXT Context,
+ ULONG FieldIndex);
+
+/* A version of SetupOpenInfFileW with support for a user-provided LCID */
+// #define SetupOpenInfFileExW InfpOpenInfFileW
HINF
WINAPI
SetupOpenInfFileExW(
@@ -50,4 +134,30 @@
IN LCID LocaleId,
OUT PUINT ErrorLine);
+
+/* HELPER FUNCTIONS **********************************************************/
+
+FORCEINLINE VOID
+INF_FreeData(IN PWCHAR InfData)
+{
+#if 0
+ if (InfData)
+ RtlFreeHeap(ProcessHeap, 0, InfData);
+#else
+ UNREFERENCED_PARAMETER(InfData);
+#endif
+}
+
+BOOLEAN
+INF_GetDataField(
+ IN PINFCONTEXT Context,
+ IN ULONG FieldIndex,
+ OUT PWCHAR *Data);
+
+BOOLEAN
+INF_GetData(
+ IN PINFCONTEXT Context,
+ OUT PWCHAR *Key,
+ OUT PWCHAR *Data);
+
/* EOF */
Modified: branches/setup_improvements/base/setup/lib/registry.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/registry.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/registry.c [iso-8859-1] Wed Aug 9 20:12:00
2017
@@ -39,7 +39,7 @@
// #ifdef __REACTOS__
-#if 0
+#if 1 // FIXME: Disable if setupapi.h is included in the code...
#define FLG_ADDREG_BINVALUETYPE 0x00000001
#define FLG_ADDREG_NOCLOBBER 0x00000002
#define FLG_ADDREG_DELVAL 0x00000004
Modified: branches/setup_improvements/base/setup/usetup/inffile.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/u…
==============================================================================
--- branches/setup_improvements/base/setup/usetup/inffile.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/usetup/inffile.c [iso-8859-1] Wed Aug 9
20:12:00 2017
@@ -87,17 +87,24 @@
return InfGetFieldCount(Context);
}
-extern BOOLEAN InfGetIntField(PINFCONTEXT Context,
- ULONG FieldIndex,
- INT *IntegerValue);
-// #define SetupGetIntField InfGetIntField
-BOOLEAN
-WINAPI
-SetupGetIntField(PINFCONTEXT Context,
- ULONG FieldIndex,
- INT *IntegerValue)
-{
- return InfGetIntField(Context, FieldIndex, IntegerValue);
+/*
+ * This function corresponds to an undocumented but exported setupapi API
+ * that exists since WinNT4 and is still present in Win10.
+ * The returned string pointer is a read-only pointer to a string in the
+ * maintained INF cache, and is always in UNICODE (on NT systems).
+ */
+extern BOOLEAN InfGetDataField(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ PWCHAR *Data);
+PCWSTR
+WINAPI
+pSetupGetField(PINFCONTEXT Context,
+ ULONG FieldIndex)
+{
+ PWCHAR Data = NULL;
+ if (!InfGetDataField(Context, FieldIndex, &Data))
+ return NULL;
+ return Data;
}
extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context,
@@ -119,6 +126,19 @@
ReturnBuffer,
ReturnBufferSize,
RequiredSize);
+}
+
+extern BOOLEAN InfGetIntField(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ INT *IntegerValue);
+// #define SetupGetIntField InfGetIntField
+BOOLEAN
+WINAPI
+SetupGetIntField(PINFCONTEXT Context,
+ ULONG FieldIndex,
+ INT *IntegerValue)
+{
+ return InfGetIntField(Context, FieldIndex, IntegerValue);
}
extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context,
@@ -197,102 +217,6 @@
/* HELPER FUNCTIONS **********************************************************/
-BOOLEAN
-INF_GetData(
- IN PINFCONTEXT Context,
- OUT PWCHAR *Key,
- OUT PWCHAR *Data)
-{
-#ifdef __REACTOS__
- return InfGetData(Context, Key, Data);
-#else
- static PWCHAR pLastCallData[4] = { NULL, NULL, NULL, NULL };
- static DWORD currentIndex = 0;
- DWORD dwSize, i;
- BOOL ret;
-
- currentIndex ^= 2;
-
- if (Key)
- *Key = NULL;
-
- if (Data)
- *Data = NULL;
-
- if (SetupGetFieldCount(Context) != 1)
- return FALSE;
-
- for (i = 0; i <= 1; i++)
- {
- ret = SetupGetStringFieldW(Context,
- i,
- NULL,
- 0,
- &dwSize);
- if (!ret)
- return FALSE;
-
- HeapFree(GetProcessHeap(), 0, pLastCallData[i + currentIndex]);
- pLastCallData[i + currentIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize *
sizeof(WCHAR));
- ret = SetupGetStringFieldW(Context,
- i,
- pLastCallData[i + currentIndex],
- dwSize,
- NULL);
- if (!ret)
- return FALSE;
- }
-
- if (Key)
- *Key = pLastCallData[0 + currentIndex];
-
- if (Data)
- *Data = pLastCallData[1 + currentIndex];
-
- return TRUE;
-#endif /* !__REACTOS__ */
-}
-
-BOOLEAN
-INF_GetDataField(
- IN PINFCONTEXT Context,
- IN ULONG FieldIndex,
- OUT PWCHAR *Data)
-{
-#ifdef __REACTOS__
- return InfGetDataField(Context, FieldIndex, Data);
-#else
- static PWCHAR pLastCallsData[] = { NULL, NULL, NULL };
- static DWORD NextIndex = 0;
- DWORD dwSize;
- BOOL ret;
-
- *Data = NULL;
-
- ret = SetupGetStringFieldW(Context,
- FieldIndex,
- NULL,
- 0,
- &dwSize);
- if (!ret)
- return FALSE;
-
- HeapFree(GetProcessHeap(), 0, pLastCallsData[NextIndex]);
- pLastCallsData[NextIndex] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
- ret = SetupGetStringFieldW(Context,
- FieldIndex,
- pLastCallsData[NextIndex],
- dwSize,
- NULL);
- if (!ret)
- return FALSE;
-
- *Data = pLastCallsData[NextIndex];
- NextIndex = (NextIndex + 1) % (sizeof(pLastCallsData) / sizeof(pLastCallsData[0]));
- return TRUE;
-#endif /* !__REACTOS__ */
-}
-
HINF WINAPI
INF_OpenBufferedFileA(
IN PSTR FileBuffer,
Modified: branches/setup_improvements/base/setup/usetup/inffile.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/u…
==============================================================================
--- branches/setup_improvements/base/setup/usetup/inffile.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/usetup/inffile.h [iso-8859-1] Wed Aug 9
20:12:00 2017
@@ -27,116 +27,26 @@
#pragma once
-#ifndef __REACTOS__
+#ifdef __REACTOS__
-#include <setupapi.h>
-
-#else /* __REACTOS__ */
+// HACK around the fact INFLIB unconditionally defines MAX_INF_STRING_LENGTH.
+#undef MAX_INF_STRING_LENGTH
/* Functions from the INFLIB library */
-#include <infcommon.h>
+// #include <infcommon.h>
+#include <infros.h>
-#define INF_STYLE_WIN4 0x00000002
-
-/* FIXME: this structure is the one used in inflib, not in setupapi
- * Delete it once we don't use inflib anymore */
-typedef struct _INFCONTEXT
-{
- HINF Inf;
- HINF CurrentInf;
- UINT Section;
- UINT Line;
-} INFCONTEXT;
-C_ASSERT(sizeof(INFCONTEXT) == 2 * sizeof(PVOID) + 2 * sizeof(UINT));
+#undef MAX_INF_STRING_LENGTH
+#define MAX_INF_STRING_LENGTH 1024
extern VOID InfSetHeap(PVOID Heap);
-// #define SetupCloseInfFile InfCloseFile
-VOID
-WINAPI
-SetupCloseInfFile(HINF InfHandle);
+#endif /* __REACTOS__ */
-// #define SetupFindFirstLineW InfpFindFirstLineW
-BOOL
-WINAPI
-SetupFindFirstLineW(
- IN HINF InfHandle,
- IN PCWSTR Section,
- IN PCWSTR Key,
- IN OUT PINFCONTEXT Context);
-
-// #define SetupFindNextLine InfFindNextLine
-BOOL
-WINAPI
-SetupFindNextLine(PINFCONTEXT ContextIn,
- PINFCONTEXT ContextOut);
-
-// #define SetupGetFieldCount InfGetFieldCount
-LONG
-WINAPI
-SetupGetFieldCount(PINFCONTEXT Context);
-
-// #define SetupGetIntField InfGetIntField
-BOOLEAN
-WINAPI
-SetupGetIntField(PINFCONTEXT Context,
- ULONG FieldIndex,
- INT *IntegerValue);
-
-// #define SetupGetBinaryField InfGetBinaryField
-BOOL
-WINAPI
-SetupGetBinaryField(PINFCONTEXT Context,
- ULONG FieldIndex,
- PUCHAR ReturnBuffer,
- ULONG ReturnBufferSize,
- PULONG RequiredSize);
-
-// #define SetupGetMultiSzFieldW InfGetMultiSzField
-BOOL
-WINAPI
-SetupGetMultiSzFieldW(PINFCONTEXT Context,
- ULONG FieldIndex,
- PWSTR ReturnBuffer,
- ULONG ReturnBufferSize,
- PULONG RequiredSize);
-
-// #define SetupGetStringFieldW InfGetStringField
-BOOL
-WINAPI
-SetupGetStringFieldW(PINFCONTEXT Context,
- ULONG FieldIndex,
- PWSTR ReturnBuffer,
- ULONG ReturnBufferSize,
- PULONG RequiredSize);
-
-/* SetupOpenInfFileW with support for a user-provided LCID */
-// #define SetupOpenInfFileExW InfpOpenInfFileW
-HINF
-WINAPI
-SetupOpenInfFileExW(
- IN PCWSTR FileName,
- IN PCWSTR InfClass,
- IN DWORD InfStyle,
- IN LCID LocaleId,
- OUT PUINT ErrorLine);
-
-#endif /* __REACTOS__ */
+#include <../lib/infsupp.h>
/* HELPER FUNCTIONS **********************************************************/
-
-BOOLEAN
-INF_GetData(
- IN PINFCONTEXT Context,
- OUT PWCHAR *Key,
- OUT PWCHAR *Data);
-
-BOOLEAN
-INF_GetDataField(
- IN PINFCONTEXT Context,
- IN ULONG FieldIndex,
- OUT PWCHAR *Data);
HINF WINAPI
INF_OpenBufferedFileA(
Modified: branches/setup_improvements/base/setup/usetup/usetup.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/u…
==============================================================================
--- branches/setup_improvements/base/setup/usetup/usetup.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/usetup/usetup.h [iso-8859-1] Wed Aug 9
20:12:00 2017
@@ -52,6 +52,7 @@
#include <ndk/rtlfuncs.h>
#include <ndk/setypes.h>
+
/* Setup library headers */
#include <reactos/rosioctl.h>
#include <../lib/setuplib.h>
@@ -62,7 +63,6 @@
#include "inffile.h"
#include "progress.h"
#ifdef __REACTOS__
-#include "infros.h"
#include "filequeue.h"
#endif
#include "fslist.h"
@@ -72,6 +72,7 @@
#include "genlist.h"
#include "host.h"
#include "mui.h"
+
extern HANDLE ProcessHeap;
extern BOOLEAN IsUnattendedSetup;