Skip to content

Commit cc27a8e

Browse files
committed
Improve mxml usage (required for future mxml updates)
1 parent bb47a70 commit cc27a8e

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

ProcessHacker/ProcessHacker.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ EXPORTS
651651

652652
; mxml
653653
mxmlDelete
654+
mxmlElementGetAttrCount
655+
mxmlElementGetAttrByIndex
654656
mxmlElementSetAttr
655657
mxmlLoadFd
656658
mxmlNewOpaque

phlib/mxml/mxml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ PHMXMLAPI extern void mxmlDelete(mxml_node_t *node);
205205
PHMXMLAPI extern void mxmlElementDeleteAttr(mxml_node_t *node,
206206
const char *name);
207207
PHMXMLAPI extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
208-
extern const char *mxmlElementGetAttrByIndex(mxml_node_t *node, int idx, const char **name);
209-
extern int mxmlElementGetAttrCount(mxml_node_t *node);
208+
PHMXMLAPI extern const char *mxmlElementGetAttrByIndex(mxml_node_t *node, int idx, const char **name);
209+
PHMXMLAPI extern int mxmlElementGetAttrCount(mxml_node_t *node);
210210
PHMXMLAPI extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
211211
const char *value);
212212
extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name,

phlib/settings.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,11 @@ NTSTATUS PhLoadSettings(
790790
while (currentNode)
791791
{
792792
PPH_STRING settingName = NULL;
793+
PCSTR elementValue;
793794

794-
if (
795-
currentNode->type == MXML_ELEMENT &&
796-
currentNode->value.element.num_attrs >= 1 &&
797-
_stricmp(currentNode->value.element.attrs[0].name, "name") == 0
798-
)
795+
if (elementValue = mxmlElementGetAttr(currentNode, "name"))
799796
{
800-
settingName = PhConvertUtf8ToUtf16(currentNode->value.element.attrs[0].value);
797+
settingName = PhConvertUtf8ToUtf16((PSTR)elementValue);
801798
}
802799

803800
if (settingName)

plugins/UserNotes/db.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,32 @@ NTSTATUS LoadDb(
239239
PPH_STRING collapse = NULL;
240240
PPH_STRING affinityMask = NULL;
241241

242-
if (currentNode->type == MXML_ELEMENT &&
243-
currentNode->value.element.num_attrs >= 2)
242+
if (mxmlElementGetAttrCount(currentNode) >= 2)
244243
{
245-
for (INT i = 0; i < currentNode->value.element.num_attrs; i++)
244+
for (INT i = 0; i < mxmlElementGetAttrCount(currentNode); i++)
246245
{
247-
if (_stricmp(currentNode->value.element.attrs[i].name, "tag") == 0)
248-
PhMoveReference(&tag, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
249-
else if (_stricmp(currentNode->value.element.attrs[i].name, "name") == 0)
250-
PhMoveReference(&name, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
251-
else if (_stricmp(currentNode->value.element.attrs[i].name, "priorityclass") == 0)
252-
PhMoveReference(&priorityClass, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
253-
else if (_stricmp(currentNode->value.element.attrs[i].name, "iopriorityplusone") == 0)
254-
PhMoveReference(&ioPriorityPlusOne, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
255-
else if (_stricmp(currentNode->value.element.attrs[i].name, "backcolor") == 0)
256-
PhMoveReference(&backColor, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
257-
else if (_stricmp(currentNode->value.element.attrs[i].name, "collapse") == 0)
258-
PhMoveReference(&collapse, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
259-
else if (_stricmp(currentNode->value.element.attrs[i].name, "affinity") == 0)
260-
PhMoveReference(&affinityMask, PhConvertUtf8ToUtf16(currentNode->value.element.attrs[i].value));
246+
PSTR elementName;
247+
PSTR elementValue;
248+
249+
elementValue = (PSTR)mxmlElementGetAttrByIndex(currentNode, i, &elementName);
250+
251+
if (!(elementName && elementValue))
252+
continue;
253+
254+
if (_stricmp(elementName, "tag") == 0)
255+
PhMoveReference(&tag, PhConvertUtf8ToUtf16(elementValue));
256+
else if (_stricmp(elementName, "name") == 0)
257+
PhMoveReference(&name, PhConvertUtf8ToUtf16(elementValue));
258+
else if (_stricmp(elementName, "priorityclass") == 0)
259+
PhMoveReference(&priorityClass, PhConvertUtf8ToUtf16(elementValue));
260+
else if (_stricmp(elementName, "iopriorityplusone") == 0)
261+
PhMoveReference(&ioPriorityPlusOne, PhConvertUtf8ToUtf16(elementValue));
262+
else if (_stricmp(elementName, "backcolor") == 0)
263+
PhMoveReference(&backColor, PhConvertUtf8ToUtf16(elementValue));
264+
else if (_stricmp(elementName, "collapse") == 0)
265+
PhMoveReference(&collapse, PhConvertUtf8ToUtf16(elementValue));
266+
else if (_stricmp(elementName, "affinity") == 0)
267+
PhMoveReference(&affinityMask, PhConvertUtf8ToUtf16(elementValue));
261268
}
262269
}
263270

0 commit comments

Comments
 (0)