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. diff --git a/progmgr/group.c b/progmgr/group.c index 4804b3c..18e9c7e 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; } @@ -112,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; @@ -171,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) @@ -193,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; @@ -240,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) @@ -306,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 @@ -315,6 +392,7 @@ PITEM CreateItem(_In_ HWND hWndGroup, _In_ PITEM pi) \* * * */ BOOL RemoveItem(_In_ PITEM pi) { + // TODO: implement this // return NULL if we can't get to the group if (pi == NULL) return FALSE; @@ -358,6 +436,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; @@ -371,10 +450,47 @@ VOID UpdateGroup(_In_ PGROUP pg) // Set FILETIME GetSystemTimeAsFileTime(&pg->ftLastWrite); + + // Get the group window rect + // GetClientRect(hWndGroup, &rcGroupWindow); 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. @@ -391,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 d04c784..f95cd47 100644 --- a/progmgr/group.h +++ b/progmgr/group.h @@ -80,10 +80,12 @@ 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 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/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; }