Skip to content

Commit

Permalink
i hate this
Browse files Browse the repository at this point in the history
  • Loading branch information
freedom7341 committed Oct 29, 2023
1 parent f1e0a17 commit 7dd1875
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
39 changes: 36 additions & 3 deletions progmgr/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ BOOL LoadItems(_In_ HWND hWndGroup)
\* * * */
BOOL RemoveItem(_In_ PITEM pi)
{
// TODO: implement this
// return NULL if we can't get to the group
if (pi == NULL)
return FALSE;
Expand Down Expand Up @@ -456,6 +457,40 @@ VOID UpdateGroup(_In_ PGROUP pg)
return;
}

/* * * *\
VerifyGroup -
Verifies that a group contains the
correct information about itself.
ABSTRACT -
This function will check the checksum,
verify the number of items, check other
parts of the strucutre. If requested,
it will repair the group if it is damaged.
RETURNS -
TRUE if group appears to be fine
FALSE if the group is damaged
\* * * */
BOOL VerifyGroup(_In_ PGROUP pg, _In_ BOOL bRepair)
{
if (pg->dwSignature != GRP_SIGNATURE)
return FALSE;

// if (pg->wVersion != GRP_VERSION)
// some sort of version difference handling

if (pg->wChecksum == 1234)
// TODO: calculate checksum function
return FALSE;

// TODO: use ftlastwrite to throw an error
// if system clock is in the future

// calculate the size of the group based on item of numbers

// TODO: change to return a dword error value
return TRUE;
}

/* * * *\
CalculateGroupMemory -
Calculates the memory needed by a group.
Expand All @@ -472,9 +507,7 @@ UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems, _In_ BOOL bLean)
// first add the size of a group strucutre
cbGroupSize += sizeof(GROUP);

// calculate the total amount of items wanted, set
// to 16 if there's less than 16 items so we always
// have some memory ready
// calculate the total amount of items wanted
cItemBlock = pGroup->cItemArray + cItems;

if (!bLean)
Expand Down
1 change: 1 addition & 0 deletions progmgr/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ BOOL RemoveItem(_In_ PITEM pi);
BOOL ExecuteItem(_In_ PITEM pi);
// Save/Load helper functions
VOID UpdateGroup(_In_ PGROUP pg);
BOOL VerifyGroup(_In_ PGROUP pg, _In_ BOOL bRepair);
// Helper functions
UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems, _In_ BOOL bLean);
// Group Window
Expand Down
11 changes: 3 additions & 8 deletions progmgr/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ DWORD RegistrySaveGroup(_In_ PGROUP pg)
// Save group
UpdateGroup(pg);
if (!RegSetValueEx(hKeyProgramGroups, pg->szName, 0, REG_BINARY,
(const BYTE*)pg, sizeof(*pg)) == ERROR_SUCCESS)
(LPBYTE)pg, CalculateGroupMemory(pg, 0, 1)) == ERROR_SUCCESS)
dwConfigStatus = dwConfigStatus && RCE_GROUPS;

return dwConfigStatus;
Expand All @@ -148,8 +148,6 @@ DWORD RegistryLoadGroup(_Inout_ PGROUP pg, _Out_ DWORD dwBufferSize)

dwBufferSize = 0;

// TODO: rethink this

// If the pointers are invalid then fail out
if (pg == NULL)
return RCE_FAILURE;
Expand Down Expand Up @@ -209,10 +207,7 @@ DWORD SaveConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups, _In_ BO
{
HWND hWndGroup = NULL;

// TODO: Get list of groups, iterate through,
// save each one as an individual subkey based
// on the name of the group

// Save each group that exists as a window
EnumChildWindows(hWndMDIClient, &SaveWindowEnumProc, (LPARAM)bExit);
}

Expand Down Expand Up @@ -348,7 +343,7 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups)

// get the group
dwTemp = RegQueryValueEx(hKeyProgramGroups, szValueName, NULL,
&dwType, pGroup, &cbGroup);
&dwType, (LPBYTE)pGroup, &cbGroup);

// verify part of the group is valid
// TODO: use checksums instead of/alongside signatures
Expand Down

0 comments on commit 7dd1875

Please sign in to comment.