1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Setup Library
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 "precomp.h"
13 #include "infsupp.h"
14
15 #define NDEBUG
16 #include <debug.h>
17
18 /* GLOBALS *******************************************************************/
19
20 /*
21 * These externs should be defined by the user of this library.
22 * They are kept there for reference and ease of usage.
23 */
24 SPINF_EXPORTS SpInfExports = {NULL};
25
26 /* HELPER FUNCTIONS **********************************************************/
27
28 BOOLEAN
INF_GetDataField(IN PINFCONTEXT Context,IN ULONG FieldIndex,OUT PCWSTR * Data)29 INF_GetDataField(
30 IN PINFCONTEXT Context,
31 IN ULONG FieldIndex,
32 OUT PCWSTR* Data)
33 {
34 #if 0
35
36 BOOL Success;
37 PWCHAR InfData;
38 DWORD dwSize;
39
40 *Data = NULL;
41
42 Success = SpInfGetStringField(Context,
43 FieldIndex,
44 NULL,
45 0,
46 &dwSize);
47 if (!Success)
48 return FALSE;
49
50 InfData = RtlAllocateHeap(ProcessHeap, 0, dwSize * sizeof(WCHAR));
51 if (!InfData)
52 return FALSE;
53
54 Success = SpInfGetStringField(Context,
55 FieldIndex,
56 InfData,
57 dwSize,
58 NULL);
59 if (!Success)
60 {
61 RtlFreeHeap(ProcessHeap, 0, InfData);
62 return FALSE;
63 }
64
65 *Data = InfData;
66 return TRUE;
67
68 #else
69
70 *Data = SpInfGetField(Context, FieldIndex);
71 return !!*Data;
72
73 #endif
74 }
75
76 BOOLEAN
INF_GetData(IN PINFCONTEXT Context,OUT PCWSTR * Key,OUT PCWSTR * Data)77 INF_GetData(
78 IN PINFCONTEXT Context,
79 OUT PCWSTR* Key,
80 OUT PCWSTR* Data)
81 {
82 BOOL Success;
83 PCWSTR InfData[2] = {NULL, NULL};
84
85 if (Key)
86 *Key = NULL;
87
88 if (Data)
89 *Data = NULL;
90
91 /*
92 * Verify that the INF file has only one value field, in addition to its key name.
93 * Note that SpInfGetFieldCount() does not count the key name as a field.
94 */
95 if (SpInfGetFieldCount(Context) != 1)
96 {
97 DPRINT1("SpInfGetFieldCount != 1\n");
98 return FALSE;
99 }
100
101 if (Key)
102 {
103 Success = INF_GetDataField(Context, 0, &InfData[0]);
104 if (!Success)
105 return FALSE;
106 }
107
108 if (Data)
109 {
110 Success = INF_GetDataField(Context, 1, &InfData[1]);
111 if (!Success)
112 {
113 INF_FreeData(InfData[0]);
114 return FALSE;
115 }
116 }
117
118 if (Key)
119 *Key = InfData[0];
120
121 if (Data)
122 *Data = InfData[1];
123
124 return TRUE;
125 }
126
127 /* EOF */
128