From 309ce4702b5eac0ce555806bd1a2ed0ce9ff97df Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Tue, 24 Oct 2023 19:38:51 -0600 Subject: [PATCH 1/5] pain; suffering --- progmgr/registry.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/progmgr/registry.c b/progmgr/registry.c index 598bd9b..9d2b389 100644 --- a/progmgr/registry.c +++ b/progmgr/registry.c @@ -315,9 +315,9 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups) UINT cGroupKeys = 0; UINT cGroupIndex = 0; - if (!(RegQueryInfoKey(hKeyProgramGroups, NULL, NULL, NULL, + if (!RegQueryInfoKey(hKeyProgramGroups, NULL, NULL, NULL, NULL, NULL, NULL, &cGroupKeys, - NULL, NULL, NULL, NULL) == ERROR_SUCCESS)) + NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { dwConfigStatus = dwConfigStatus && RCE_SETTINGS; @@ -338,22 +338,31 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups) // the name of the registry key (val 3 here) // get the size of the group - RegEnumValue(hKeyProgramGroups, cGroupIndex, (LPWSTR)&szValueName, - &cbValueName, NULL, NULL, NULL, &cbGroup); + RegEnumValue(hKeyProgramGroups, cGroupIndex, (LPWSTR)szValueName, + &cbValueName, NULL, &dwType, NULL, &cbGroup); - // allocate memory for the group + // allocate and zero memory for the group pGroup = malloc(cbGroup); + ZeroMemory(pGroup, cbGroup); // get the group - RegQueryValueEx(hKeyProgramGroups, (LPWSTR)&szValueName, NULL, NULL, - (LPBYTE)pGroup, &cbGroup); + RegQueryValueEx(hKeyProgramGroups, (LPWSTR)szValueName, NULL, + &dwType, (LPBYTE)pGroup, &cbGroup); + /* + RegGetValue(hKeyProgramGroups, NULL, (LPWSTR)szValueName, + RRF_RT_REG_BINARY, &dwType, (LPBYTE)pGroup, &cbGroup); + */ - // load the group - CreateGroup(pGroup); + // verify part of the group is valid + // TODO: use checksums instead of/alongside signatures + if (pGroup->dwSignature == GRP_SIGNATURE) + { + // load the group + CreateGroup(pGroup); - // free memory - if (pGroup) + // free memory free(pGroup); + } // increment cGroupIndex++; From c1dd3ae99995f5b96048563217a608c71208c52f Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Wed, 25 Oct 2023 11:49:37 -0600 Subject: [PATCH 2/5] GROUPS LOAD --- progmgr/group.c | 6 +++++- progmgr/registry.c | 13 +++++-------- progmgr/wndproc.c | 5 ----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/progmgr/group.c b/progmgr/group.c index 4804b3c..3d6c004 100644 --- a/progmgr/group.c +++ b/progmgr/group.c @@ -77,8 +77,12 @@ BOOL InitializeGroups(VOID) if (!RegisterClassEx(&wce)) return FALSE; + + // Now we can create the groups + if(LoadConfig(FALSE, FALSE, TRUE) != RCE_SUCCESS) + return FALSE; - // TODO: go thru registry and load all saved groups here + // TODO: if loading groups fails, throw an error return TRUE; } diff --git a/progmgr/registry.c b/progmgr/registry.c index 9d2b389..02290b1 100644 --- a/progmgr/registry.c +++ b/progmgr/registry.c @@ -331,14 +331,15 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups) while (cGroupKeys >= cGroupIndex) { WCHAR szValueName[MAX_TITLE_LENGTH] = TEXT(""); - UINT cbValueName = 0; + UINT cbValueName = sizeof(szValueName); + DWORD dwTemp = 0; // TODO: figure out where i'm really going to store the // group name, if not in the group structure then in // the name of the registry key (val 3 here) // get the size of the group - RegEnumValue(hKeyProgramGroups, cGroupIndex, (LPWSTR)szValueName, + RegEnumValue(hKeyProgramGroups, cGroupIndex, szValueName, &cbValueName, NULL, &dwType, NULL, &cbGroup); // allocate and zero memory for the group @@ -346,12 +347,8 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups) ZeroMemory(pGroup, cbGroup); // get the group - RegQueryValueEx(hKeyProgramGroups, (LPWSTR)szValueName, NULL, - &dwType, (LPBYTE)pGroup, &cbGroup); - /* - RegGetValue(hKeyProgramGroups, NULL, (LPWSTR)szValueName, - RRF_RT_REG_BINARY, &dwType, (LPBYTE)pGroup, &cbGroup); - */ + dwTemp = RegQueryValueEx(hKeyProgramGroups, szValueName, NULL, + &dwType, pGroup, &cbGroup); // verify part of the group is valid // TODO: use checksums instead of/alongside signatures diff --git a/progmgr/wndproc.c b/progmgr/wndproc.c index 5bd99d8..79b4db9 100644 --- a/progmgr/wndproc.c +++ b/progmgr/wndproc.c @@ -35,11 +35,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_CREATE: { - // Now we can create the groups - if(LoadConfig(FALSE, FALSE, TRUE) != RCE_SUCCESS) - return FALSE; - - // TODO: if loading groups fails, throw an error return TRUE; } From f1e0a17b3d389e8d1610403492c1dd4b33aeca43 Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Wed, 25 Oct 2023 13:51:57 -0600 Subject: [PATCH 3/5] sorta load items --- progmgr/group.c | 95 ++++++++++++++++++++++++++++++++++++++++++++----- progmgr/group.h | 1 + 2 files changed, 87 insertions(+), 9 deletions(-) diff --git a/progmgr/group.c b/progmgr/group.c index 3d6c004..7a689a0 100644 --- a/progmgr/group.c +++ b/progmgr/group.c @@ -116,8 +116,7 @@ HWND CreateGroup(_In_ PGROUP pg) return NULL; // allocate memory for a new group - pGroup = (PGROUP)malloc(CalculateGroupMemory(pg, 0, 0)); - + pGroup = (PGROUP)malloc(CalculateGroupMemory(pg, 1, 0)); if (pGroup == NULL) return NULL; @@ -175,8 +174,7 @@ HWND CreateGroup(_In_ PGROUP pg) WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | LVS_ICON | LVS_SINGLESEL | LVS_AUTOARRANGE, mcs.x, mcs.y, mcs.cx, mcs.cy, - hWndGroup, NULL, hAppInstance, - NULL)) == NULL) + hWndGroup, NULL, hAppInstance, NULL)) == NULL) return NULL; // ((LVS_AUTOARRANGE & bAutoArrange) * LVS_AUTOARRANGE) @@ -197,6 +195,10 @@ HWND CreateGroup(_In_ PGROUP pg) GetSystemMetrics(SM_CYICON), ILC_COLOR32, 0, 1); ListView_SetImageList(hWndListView, hImageList, LVSIL_NORMAL); + // since the list is viewing we can load items if applicable + if (pGroup->cItemArray > 0) + LoadItems(hWndGroup); + // TODO: make sure the groups delete their icons upon destruction! // AND IMAGE LIST!!!!!!!!? i think it's nuked w/ listview though return hWndGroup; @@ -244,18 +246,16 @@ BOOL RemoveGroup(_In_ HWND hWndGroup, _In_ BOOL bEliminate) \* * * */ PITEM CreateItem(_In_ HWND hWndGroup, _In_ PITEM pi) { - HIMAGELIST hImageList = NULL; - HICON hIcon = NULL; - LVITEM lvi = { 0 }; PGROUP pGroup = NULL; PGROUP pNewGroup = NULL; PITEM pItem = NULL; - UINT uiTest = 0; HWND hWndListView = NULL; + HIMAGELIST hImageList = NULL; + HICON hIcon = NULL; + LVITEM lvi = { 0 }; // we actually just want the group pointer lol pGroup = (PGROUP)GetWindowLongPtr(hWndGroup, GWLP_USERDATA); - uiTest = pGroup->cItemArray; // return NULL if we can't get to the group or item if (hWndGroup == NULL) @@ -310,6 +310,79 @@ PITEM CreateItem(_In_ HWND hWndGroup, _In_ PITEM pi) return pItem; } +/* * * *\ + LoadItems - + Loads all of the items in a group structure + RETURNS - + TRUE if successful + FALSE otherwise +\* * * */ +BOOL LoadItems(_In_ HWND hWndGroup) +{ + PGROUP pGroup = NULL; + PGROUP pNewGroup = NULL; + PITEM pItem = NULL; + HWND hWndListView = NULL; + HIMAGELIST hImageList = NULL; + LVITEM lvi = { 0 }; + UINT cItemIndex = 0; + HICON hIcon = NULL; + + // return NULL if we can't get to the group + if (hWndGroup == NULL) + return FALSE; + + // retrieve the group pointer + pGroup = (PGROUP)GetWindowLongPtr(hWndGroup, GWLP_USERDATA); + if (pGroup == NULL) + return FALSE; + + // get the listview window + hWndListView = FindWindowEx(hWndGroup, NULL, WC_LISTVIEW, NULL); + if (hWndListView == NULL) + return FALSE; + + // make sure we have enough memory for the items + pNewGroup = realloc(pGroup, CalculateGroupMemory(pGroup, 0, 1)); + if (pNewGroup != NULL) + { + pGroup = pNewGroup; + SetWindowLongPtr(hWndGroup, GWLP_USERDATA, (LONG_PTR)pGroup); + } + + // then get the pointer to the group's image list + hImageList = ListView_GetImageList(hWndListView, LVSIL_NORMAL); + + while (pGroup->cItemArray > cItemIndex) + { + pItem = pGroup->pItemArray + cItemIndex; + + // extract that icon son!! + hIcon = ExtractIcon(hAppInstance, (LPWSTR)pItem->szIconPath, pItem->iIconIndex); + + // populate the listview with the relevant information + lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; + lvi.iItem = cItemIndex; + lvi.iSubItem = 0; + lvi.pszText = pItem->szName; + lvi.cchTextMax = ARRAYSIZE(pItem->szName); + lvi.iImage = ImageList_AddIcon(hImageList, hIcon); + lvi.lParam = (LPARAM)pItem; + + // copy that bad boy into the listview + ListView_InsertItem(hWndListView, &lvi); + + cItemIndex++; + } + + if (hIcon) + // get that hicon outta here + DestroyIcon(hIcon); + + // TODO: fail if the listview item isn't added + return TRUE; +} + /* * * *\ RemoveItem - Removes a program item @@ -362,6 +435,7 @@ BOOL ExecuteItem(_In_ PITEM pi) \* * * */ VOID UpdateGroup(_In_ PGROUP pg) { + DWORD dwFlags = 0; // Set the important flags pg->dwSignature = GRP_SIGNATURE; pg->wVersion = GRP_VERSION; @@ -375,6 +449,9 @@ VOID UpdateGroup(_In_ PGROUP pg) // Set FILETIME GetSystemTimeAsFileTime(&pg->ftLastWrite); + + // Get the group window rect + // GetClientRect(hWndGroup, &rcGroupWindow); return; } diff --git a/progmgr/group.h b/progmgr/group.h index d04c784..2915dc0 100644 --- a/progmgr/group.h +++ b/progmgr/group.h @@ -80,6 +80,7 @@ HWND CreateGroup(_In_ PGROUP pg); BOOL RemoveGroup(_In_ HWND hWndGroup, _In_ BOOL bEliminate); // Item Management PITEM CreateItem(_In_ HWND hWndGroup, _In_ PITEM pi); +BOOL LoadItems(_In_ HWND hWndGroup); BOOL RemoveItem(_In_ PITEM pi); BOOL ExecuteItem(_In_ PITEM pi); // Save/Load helper functions From 7dd1875e1d28778a9ff7a2ba5d7054a48b4fe3c6 Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Sat, 28 Oct 2023 22:15:24 -0600 Subject: [PATCH 4/5] i hate this --- progmgr/group.c | 39 ++++++++++++++++++++++++++++++++++++--- progmgr/group.h | 1 + progmgr/registry.c | 11 +++-------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/progmgr/group.c b/progmgr/group.c index 7a689a0..18e9c7e 100644 --- a/progmgr/group.c +++ b/progmgr/group.c @@ -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; @@ -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. @@ -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) diff --git a/progmgr/group.h b/progmgr/group.h index 2915dc0..f95cd47 100644 --- a/progmgr/group.h +++ b/progmgr/group.h @@ -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 diff --git a/progmgr/registry.c b/progmgr/registry.c index 02290b1..0670bd7 100644 --- a/progmgr/registry.c +++ b/progmgr/registry.c @@ -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; @@ -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; @@ -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); } @@ -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 From 972c56a15b9783b234304198d459f7a4d7fe702d Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Mon, 4 Dec 2023 13:25:26 -0700 Subject: [PATCH 5/5] Update msbuild.yml??? --- .github/workflows/msbuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index dbc5853..19ff345 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -14,7 +14,8 @@ on: env: # Path to the solution file relative to the root of the project. - SOLUTION_FILE_PATH: . + # SOLUTION_FILE_PATH: . + SOLUTION_FILE_PATH: Program-Manager-II.sln # Configuration type to build. # You can convert this to a build matrix if you need coverage of multiple configuration types.