-
Notifications
You must be signed in to change notification settings - Fork 422
/
Copy pathclist.c
185 lines (169 loc) · 4.02 KB
/
clist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "clist.h"
#include <Shlwapi.h>
PINTEGER_LIST CreateIntegerList()
{
PINTEGER_LIST list = NEW(INTEGER_LIST);
list->Count = 0;
list->Capacity = 16;
list->Values = NEW_ARRAY(INT, list->Capacity);
return list;
}
VOID LoadIntegerListFromRegistryKey(PINTEGER_LIST list, HKEY key)
{
DWORD count;
if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, &count, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
WCHAR valueName[100];
for (DWORD i = 0; i < count; i++)
{
DWORD valueNameLength = 100;
DWORD type;
DWORD value;
DWORD valueSize = sizeof(DWORD);
if (RegEnumValueW(key, i, valueName, &valueNameLength, NULL, &type, (LPBYTE)&value, &valueSize) == ERROR_SUCCESS && type == REG_DWORD && !IntegerListContains(list, value))
{
IntegerListAdd(list, value);
}
}
}
}
VOID DeleteIntegerList(PINTEGER_LIST list)
{
FREE(list->Values);
i_memset(list, 0, sizeof(INTEGER_LIST));
FREE(list);
}
VOID IntegerListAdd(PINTEGER_LIST list, INT value)
{
if (list->Count == list->Capacity)
{
list->Capacity += 16;
LPINT newValues = NEW_ARRAY(INT, list->Capacity);
i_memcpy(newValues, list->Values, list->Count * sizeof(INT));
LPINT oldValues = list->Values;
list->Values = newValues;
FREE(oldValues);
}
list->Values[list->Count++] = value;
}
BOOL IntegerListContains(PINTEGER_LIST list, INT value)
{
for (DWORD i = 0; i < list->Count; i++)
{
if (list->Values[i] == value) return TRUE;
}
return FALSE;
}
BOOL CompareIntegerList(PINTEGER_LIST listA, PINTEGER_LIST listB)
{
if (listA == listB)
{
return TRUE;
}
else if (listA == NULL || listB == NULL)
{
return FALSE;
}
else if (listA->Count != listB->Count)
{
return FALSE;
}
else
{
for (ULONG i = 0; i < listA->Count; i++)
{
if (listA->Values[i] != listB->Values[i]) return FALSE;
}
return TRUE;
}
}
PSTRING_LIST CreateStringList(BOOL ignoreCase)
{
PSTRING_LIST list = NEW(STRING_LIST);
list->Count = 0;
list->Capacity = 16;
list->IgnoreCase = ignoreCase;
list->Values = NEW_ARRAY(LPWSTR, list->Capacity);
return list;
}
VOID LoadStringListFromRegistryKey(PSTRING_LIST list, HKEY key, DWORD maxStringLength)
{
DWORD count;
if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, &count, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
WCHAR valueName[100];
PWCHAR value = NEW_ARRAY(WCHAR, maxStringLength + 1);
for (DWORD i = 0; i < count; i++)
{
DWORD valueNameLength = 100;
DWORD type;
DWORD valueSize = maxStringLength;
if (RegEnumValueW(key, i, valueName, &valueNameLength, NULL, &type, (LPBYTE)value, &valueSize) == ERROR_SUCCESS && type == REG_SZ && !StringListContains(list, value))
{
StringListAdd(list, value);
}
}
FREE(value);
}
}
VOID DeleteStringList(PSTRING_LIST list)
{
for (ULONG i = 0; i < list->Count; i++)
{
FREE(list->Values[i]);
}
FREE(list->Values);
i_memset(list, 0, sizeof(STRING_LIST));
FREE(list);
}
VOID StringListAdd(PSTRING_LIST list, LPCWSTR value)
{
if (value)
{
if (list->Count == list->Capacity)
{
list->Capacity += 16;
LPWSTR *newValues = NEW_ARRAY(LPWSTR, list->Capacity);
i_memcpy(newValues, list->Values, list->Count * sizeof(LPWSTR));
LPWSTR *oldValues = list->Values;
list->Values = newValues;
FREE(oldValues);
}
list->Values[list->Count] = NEW_ARRAY(WCHAR, lstrlenW(value) + 1);
StrCpyW(list->Values[list->Count++], value);
}
}
BOOL StringListContains(PSTRING_LIST list, LPCWSTR value)
{
if (value)
{
for (DWORD i = 0; i < list->Count; i++)
{
if (list->IgnoreCase ? !StrCmpIW(list->Values[i], value) : !StrCmpW(list->Values[i], value)) return TRUE;
}
}
return FALSE;
}
BOOL CompareStringList(PSTRING_LIST listA, PSTRING_LIST listB)
{
if (listA == listB)
{
return TRUE;
}
else if (listA == NULL || listB == NULL)
{
return FALSE;
}
else if (listA->Count != listB->Count)
{
return FALSE;
}
else
{
for (ULONG i = 0; i < listA->Count; i++)
{
if (listA->IgnoreCase && listB->IgnoreCase ? StrCmpIW(listA->Values[i], listB->Values[i]) : StrCmpW(listA->Values[i], listB->Values[i])) return FALSE;
}
return TRUE;
}
}