save groups

This commit is contained in:
freedom
2023-10-13 12:24:05 -06:00
parent 475d868825
commit 97784e31ae
5 changed files with 83 additions and 49 deletions

View File

@@ -206,7 +206,6 @@ BOOL RemoveGroup(_In_ HWND hWndGroup, _In_ BOOL bEliminate)
BOOL bReturn = TRUE;
// TODO: do i have to delete the titlebar icons?
// TODO: cleanup the image list as well, IMAGELIST_DESTORY
if (bEliminate == TRUE)
{
@@ -217,12 +216,12 @@ BOOL RemoveGroup(_In_ HWND hWndGroup, _In_ BOOL bEliminate)
// get the group struct pointer
if ((pGroup = (PGROUP)GetWindowLongPtr(hWndGroup, GWLP_USERDATA)) == NULL)
return FALSE;
free(pGroup);
bReturn = FALSE;
else
free(pGroup);
// close the group window
DestroyWindow(hWndGroup);
SendMessage(hWndMDIClient, WM_MDIDESTROY, (WPARAM)hWndGroup, 0);
return bReturn;
}
@@ -346,17 +345,16 @@ BOOL ExecuteItem(_In_ PITEM pi)
/* * * *\
SaveGroup -
Saves group from a group window
into a GROUP structure.
Updates group information to prepare
it for being saved.
ABSTRACT -
This function will extract all of the
necessary information from a group window
in order to produce a group structure.
This function will update all of the
relevant structures in a group struct
in preparation for saving the group.
RETURNS -
Formatted GROUP structure.
Upon failure, wChecksum will be 0.
Nothing.
\* * * */
GROUP SaveGroup(_In_ PGROUP pg)
VOID UpdateGroup(_In_ PGROUP pg)
{
GROUP grp = {
.dwSignature = GRP_SIGNATURE,
@@ -368,32 +366,16 @@ GROUP SaveGroup(_In_ PGROUP pg)
.cItemArray = 0,
.pItemArray = 0
};
HWND hWndGrp = NULL;
WCHAR szGroupName[MAX_TITLE_LENGTH];
// Find the group and copy it
grp = *pg;
// Set the group checksum
grp.wChecksum = 1; // NOTE: implement this for real later lol
pg->wChecksum = 1; // NOTE: implement this for real later lol
// Copy group information
if (hWndGrp != NULL)
{
GetWindowText(hWndGrp, szGroupName, MAX_TITLE_LENGTH);
StringCchCopy(grp.szName, MAX_TITLE_LENGTH, szGroupName);
}
grp.dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw);
pg->dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw);
// Set FILETIME
GetSystemTimeAsFileTime(&grp.ftLastWrite);
GetSystemTimeAsFileTime(&pg->ftLastWrite);
// Save items...
grp.cItemArray = 0;
// TODO: iterate through listview to save items
return grp;
return;
}
/* * * *\

View File

@@ -81,8 +81,8 @@ BOOL RemoveGroup(_In_ HWND hWndGroup, _In_ BOOL bEliminate);
PITEM CreateItem(_In_ HWND hWndGroup, _In_ PITEM pi);
BOOL RemoveItem(_In_ PITEM pi);
BOOL ExecuteItem(_In_ PITEM pi);
// Import/export functions
GROUP SaveGroup(_In_ PGROUP pg);
// Save/Load helper functions
VOID UpdateGroup(_In_ PGROUP pg);
// Helper functions
UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems);
// Group Window

View File

@@ -118,7 +118,7 @@ BOOL IsProgMgrDefaultShell(VOID)
RETURNS -
RCE_* configuration error value
\* * * */
DWORD SaveGroupToRegistry(_In_ PGROUP pg)
DWORD RegistrySaveGroup(_In_ PGROUP pg)
{
DWORD dwConfigStatus = RCE_SUCCESS;
@@ -127,21 +127,21 @@ DWORD SaveGroupToRegistry(_In_ PGROUP pg)
return RCE_FAILURE;
// Save group
// TODO: save items properly
UpdateGroup(pg);
if (!RegSetValueEx(hKeyProgramGroups, pg->szName, 0, REG_BINARY,
(const BYTE*)pg, (sizeof(*pg) + sizeof(ITEM) * pg->cItemArray)) == ERROR_SUCCESS)
(const BYTE*)pg, CalculateGroupMemory(pg, 0)) == ERROR_SUCCESS)
dwConfigStatus = dwConfigStatus && RCE_GROUPS;
return dwConfigStatus;
}
/* * * *\
LoadGroupFromRegistry -
RegistryLoadGroup -
Loads a group structure from the registry.
RETURNS -
RCE_* configuration error value
\* * * */
DWORD LoadGroupFromRegistry(_Inout_ PGROUP pg, _Out_ PDWORD pdwBufferSize)
DWORD RegistryLoadGroup(_Inout_ PGROUP pg, _Out_ PDWORD pdwBufferSize)
{
DWORD dwConfigStatus = RCE_SUCCESS;
DWORD dwType = REG_BINARY;
@@ -167,7 +167,7 @@ DWORD LoadGroupFromRegistry(_Inout_ PGROUP pg, _Out_ PDWORD pdwBufferSize)
RETURNS -
RCE_* configuration error value
\* * * */
DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
DWORD SaveConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups, _In_ BOOL bExit)
{
DWORD dwConfigStatus = RCE_SUCCESS;
@@ -205,15 +205,65 @@ DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
if (bGroups)
{
HWND hWndGroup = NULL;
// TODO: Get list of groups, iterate through,
// save each one as an individual subkey based
// on the name of the group
dwConfigStatus = dwConfigStatus && RCE_GROUPS;
EnumChildWindows(hWndMDIClient, &SaveWindowEnumProc, bExit);
/*
while ((hWndGroup = (HWND)SendMessage(hWndMDIClient,
WM_MDIGETACTIVE, 0, (LPARAM)NULL)) != NULL)
{
// save it...
dwConfigStatus = dwConfigStatus &&
RegistrySaveGroup((PGROUP)GetWindowLongPtr(hWndGroup,
GWLP_USERDATA));
// close it...
if (!RemoveGroup(hWndGroup, FALSE))
dwConfigStatus = dwConfigStatus && RCE_GROUPS;
}
*/
}
return dwConfigStatus;
}
/* * * *\
SaveWindowEnumProc() -
Procedure for enumeration
of group windows to save
or close them
NOTES -
lParam is a BOOL that determines
whether to close the group or not
RETURNS -
TRUE to continue
FALSE to stop
\* * * */
BOOL CALLBACK SaveWindowEnumProc(HWND hWndGroup, LPARAM lParam)
{
if (hWndGroup == NULL)
return FALSE;
// save it...
if (RegistrySaveGroup((PGROUP)GetWindowLongPtr(hWndGroup,
GWLP_USERDATA)) != RCE_SUCCESS)
return FALSE;
// close it...
if ((BOOL)lParam == TRUE)
{
RemoveGroup(hWndGroup, FALSE);
return FALSE;
}
return TRUE;
}
/* * * *\
LoadConfig() -
Finds all settings and retrieves them
@@ -221,7 +271,7 @@ DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
RETURNS -
RCE_* configuration error value
\* * * */
DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups)
{
DWORD dwConfigStatus = RCE_SUCCESS;

View File

@@ -50,8 +50,10 @@ extern RECT rcMainWindow;
BOOL InitializeRegistryKeys(VOID);
BOOL IsProgMgrDefaultShell(VOID);
// Groups
DWORD SaveGroupToRegistry(_In_ PGROUP pg);
DWORD LoadGroupFromRegistry(_Inout_ PGROUP pg, _Out_ PDWORD pdwBufferSize);
DWORD RegistrySaveGroup(_In_ PGROUP pg);
DWORD RegistryLoadGroup(_Inout_ PGROUP pg, _Out_ PDWORD pdwBufferSize);
// Settings
DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups);
DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups);
DWORD SaveConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups, _In_ BOOL bExit);
DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups);
// Miscellaneous
BOOL CALLBACK SaveWindowEnumProc(HWND hWndGroup, LPARAM lParam);

View File

@@ -63,7 +63,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_CLOSE:
if (bSaveSettings)
SaveConfig(TRUE, TRUE, TRUE);
SaveConfig(TRUE, TRUE, TRUE, TRUE);
if (bIsDefaultShell && (GetShellWindow() != NULL))
SetShellWindow(0);
@@ -143,7 +143,7 @@ LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
case IDM_OPTIONS_SAVENOW:
SaveConfig:
SaveConfig(TRUE, TRUE, TRUE);
SaveConfig(TRUE, TRUE, TRUE, FALSE);
break;
case IDM_WINDOW_CASCADE: