fix registry loading once and for all or something

This commit is contained in:
Brady McDermott
2024-10-20 00:54:56 -06:00
parent f0ae48cd10
commit 306621f084
2 changed files with 49 additions and 10 deletions

View File

@@ -113,6 +113,8 @@ HWND CreateGroup(_In_ PGROUP pg)
// error checking, if we get trash don't try to // error checking, if we get trash don't try to
// make a group out of it // make a group out of it
// TODO: if a group is garbled, throw an error
// and ask the user if they want to delete it!
if (pg->dwSignature != GRP_SIGNATURE) if (pg->dwSignature != GRP_SIGNATURE)
return NULL; return NULL;

View File

@@ -304,18 +304,28 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups)
for (i = 0; i < cGroupVals; i++) for (i = 0; i < cGroupVals; i++)
{ {
WCHAR szGroupValName[MAX_TITLE_LENGTH] = TEXT(""); WCHAR szGroupValName[MAX_TITLE_LENGTH] = TEXT("");
UINT cbGroupValName = 0; UINT cbGroupValName = MAX_TITLE_LENGTH;
UINT cbGroup = 0; UINT cbGroup = 0;
PGROUP pGroup = NULL; PGROUP pGroup = NULL;
LSTATUS error = ERROR_SUCCESS;
// 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, i, (LPWSTR)&szGroupValName, error = RegEnumValue(hKeyProgramGroups, i, (LPWSTR)&szGroupValName,
&cbGroupValName, NULL, NULL, NULL, &cbGroup); &cbGroupValName, NULL, NULL, NULL, &cbGroup);
if (error == ERROR_NO_MORE_ITEMS)
break;
else if (error != ERROR_SUCCESS)
{
OutputDebugString(TEXT("REGISTRY.C: RegEnumValue failure.\n"));
break;
}
// allocate memory for the group // allocate memory for the group
pGroup = malloc(cbGroup); pGroup = malloc(cbGroup);
@@ -326,25 +336,52 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups)
} }
// retrieve the group // retrieve the group
RegGetValue(hKeyProgramGroups, NULL, (LPWSTR)&szGroupValName, // TODO: add error_checking, ERROR_FILE_NOT_FOUND
RRF_RT_REG_BINARY, NULL, pGroup, &cbGroup); // stuff like that, please
// error checking makes reliability....
error = RegGetValue(hKeyProgramGroups, NULL, szGroupValName, RRF_RT_REG_BINARY, NULL, pGroup, &cbGroup);
/*error = RegQueryValueEx(hKeyProgramGroups, szGroupValName, NULL, NULL, pGroup, &cbGroup);*/
if (error == ERROR_FILE_NOT_FOUND)
{
OutputDebugString(TEXT("REGISTRY.C: Group not found!\n"));
OutputDebugString(TEXT("REGISTRY.C: Group retrieved.\n")); dwConfigStatus = dwConfigStatus && RCE_GROUPS;
}
if (error == ERROR_MORE_DATA)
{
OutputDebugString(TEXT("REGISTRY.C: Buffer too small!\n"));
dwConfigStatus = dwConfigStatus && RCE_GROUPS;
}
else if (error != ERROR_SUCCESS)
{
OutputDebugString(TEXT("REGISTRY.C: Group retrieval failed!\n"));
dwConfigStatus = dwConfigStatus && RCE_GROUPS;
}
else
OutputDebugString(TEXT("REGISTRY.C: Group retrieved.\n"));
// create the group // create the group
if (pGroup) if (pGroup)
{ {
CreateGroup(pGroup); if (pGroup->dwSignature == GRP_SIGNATURE)
{
OutputDebugString(TEXT("REGISTRY.C: Group created.\n")); CreateGroup(pGroup);
OutputDebugString(TEXT("REGISTRY.C: Group created.\n"));
}
else
{
OutputDebugString(TEXT("REGISTRY.C: Group creation aborted.\n"));
}
// free memory // free memory
free(pGroup); free(pGroup);
} }
else else
{ {
dwConfigStatus = dwConfigStatus && RCE_SETTINGS; dwConfigStatus = dwConfigStatus && RCE_GROUPS;
OutputDebugString(TEXT("REGISTRY.C: Failed create group!\n")); OutputDebugString(TEXT("REGISTRY.C: Failed to create group!\n"));
} }
} }
} }