it no longer freezes on startup and falls into an infinite loop of loading program groups (that may or may not exist!)

This commit is contained in:
Brady McDermott
2024-10-20 00:23:32 -06:00
parent aef812ae92
commit f0ae48cd10

View File

@@ -279,64 +279,74 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups)
{ {
DWORD dwBufferSize = sizeof(dwSettingsMask); DWORD dwBufferSize = sizeof(dwSettingsMask);
DWORD dwType = REG_BINARY; DWORD dwType = REG_BINARY;
PGROUP pGroup = NULL; UINT cGroupVals = 0;
UINT cbGroup = 0;
UINT cGroupKeys = 0;
UINT cGroupIndex = 0;
OutputDebugString(TEXT("REGISTRY.C: Loading groups...\n"));
// Get the num of group values, if we fail then ABORT!
if (!(RegQueryInfoKey(hKeyProgramGroups, NULL, NULL, NULL, if (!(RegQueryInfoKey(hKeyProgramGroups, NULL, NULL, NULL,
NULL, NULL, NULL, &cGroupKeys, NULL, NULL, NULL, &cGroupVals,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)) NULL, NULL, NULL, NULL) == ERROR_SUCCESS))
{ {
dwConfigStatus = dwConfigStatus && RCE_SETTINGS; dwConfigStatus = dwConfigStatus && RCE_SETTINGS;
// I can get away with returning here upon // I can get away with returning here upon
// failure since this is the last one // failure since this is the last one
OutputDebugString(TEXT("REGISTRY.C: Failed to get # of values!\n"));
return dwConfigStatus; return dwConfigStatus;
} }
if (cGroupKeys > 0) // Enumerate through the registry values
if (cGroupVals)
{ {
while (cGroupKeys >= cGroupIndex) DWORD i = 0;
for (i = 0; i < cGroupVals; i++)
{ {
WCHAR szValueName[MAX_TITLE_LENGTH] = TEXT(""); WCHAR szGroupValName[MAX_TITLE_LENGTH] = TEXT("");
UINT cbValueName = 0; UINT cbGroupValName = 0;
UINT cbGroup = 0;
PGROUP pGroup = NULL;
// TODO: figure out where i'm really going to store the // TODO: figure out where i'm really going to store the
// group name, if not in the group structure then in // group name, if not in the group structure then in
// the name of the registry key (val 3 here) // the name of the registry key (val 3 here)
// get the size of the group // get the size of the group
RegEnumValue(hKeyProgramGroups, cGroupIndex, (LPWSTR)&szValueName, RegEnumValue(hKeyProgramGroups, i, (LPWSTR)&szGroupValName,
&cbValueName, NULL, NULL, NULL, &cbGroup); &cbGroupValName, NULL, NULL, NULL, &cbGroup);
// allocate memory for the group // allocate memory for the group
pGroup = malloc(cbGroup); pGroup = malloc(cbGroup);
if (pGroup == NULL) if (pGroup == NULL)
{ {
dwConfigStatus = dwConfigStatus && RCE_GROUPS; dwConfigStatus = dwConfigStatus && RCE_GROUPS;
return dwConfigStatus; return dwConfigStatus;
} }
ZeroMemory(pGroup, cbGroup); // retrieve the group
RegGetValue(hKeyProgramGroups, NULL, (LPWSTR)&szGroupValName,
RRF_RT_REG_BINARY, NULL, pGroup, &cbGroup);
// get the group OutputDebugString(TEXT("REGISTRY.C: Group retrieved.\n"));
RegQueryValueEx(hKeyProgramGroups, (LPWSTR)&szValueName, NULL, NULL,
(LPBYTE)pGroup, &cbGroup);
// load the group // create the group
if (pGroup) if (pGroup)
{ {
CreateGroup(pGroup); CreateGroup(pGroup);
OutputDebugString(TEXT("REGISTRY.C: Group created.\n"));
// free memory // free memory
free(pGroup); free(pGroup);
} }
else
{
dwConfigStatus = dwConfigStatus && RCE_SETTINGS;
OutputDebugString(TEXT("REGISTRY.C: Failed create group!\n"));
}
} }
// increment
cGroupIndex++;
} }
} }