diff --git a/progmgr/registry.c b/progmgr/registry.c index 82402ff..1659e63 100644 --- a/progmgr/registry.c +++ b/progmgr/registry.c @@ -115,19 +115,17 @@ BOOL IsProgMgrDefaultShell() Finds and collapses all settings and saves them to the registry. RETURNS - - TRUE if successful, FALSE if unsuccessful. + RCE_* configuration error value \* * * */ -BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups) +DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups) { - BOOL bConfigStatus = TRUE; - WINDOWPLACEMENT wpProgMgr; - RECT rcWindow; + DWORD bConfigStatus = RCE_SUCCESS; if (bSettings) { // Shrink the settings into the bitmask and save it // There's definitely a better way to do this but... - // I'll get to it later :) + // TODO: do this more efficiently dwSettingsMask = (bAutoArrange && PMS_AUTOARRANGE) * PMS_AUTOARRANGE | (bMinOnRun && PMS_MINONRUN) * PMS_MINONRUN | @@ -137,11 +135,14 @@ BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups) if (!RegSetValueEx(hKeySettings, pszSettingsMask, 0, REG_DWORD, (const BYTE*)&dwSettingsMask, sizeof(dwSettingsMask)) == ERROR_SUCCESS) - bConfigStatus = FALSE; + bConfigStatus = bConfigStatus && RCE_SETTINGS; } if (bPos) { + WINDOWPLACEMENT wpProgMgr; + RECT rcWindow; + // Get and save window position wpProgMgr.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hWndProgMgr, &wpProgMgr); @@ -149,42 +150,64 @@ BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups) if (!RegSetValueEx(hKeySettings, pszSettingsWindow, 0, REG_BINARY, (const BYTE*)&rcWindow, sizeof(rcWindow)) == ERROR_SUCCESS) - bConfigStatus = FALSE; + bConfigStatus = bConfigStatus && RCE_POSITION; + } + + if (bGroups) + { + // TODO: Get list of groups, iterate through, + // save each one as an individual subkey based + // on the name of the group + bConfigStatus = bConfigStatus && RCE_GROUPS; } return bConfigStatus; } /* * * *\ - BOOL LoadConfig() - + LoadConfig() - Finds all settings and retrieves them from the registry. RETURNS - - TRUE if successful, FALSE if unsuccessful. + RCE_* configuration error value \* * * */ -BOOL LoadConfig() +DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups) { - BOOL bConfigStatus = TRUE; + DWORD bConfigStatus = RCE_SUCCESS; DWORD dwType; - DWORD dwBufferSize = sizeof(dwSettingsMask); - DWORD dwRectBufferSize = sizeof(rcMainWindow); - // Load settings bitmask - if (!RegQueryValueEx(hKeySettings, pszSettingsMask, 0, &dwType, - (LPBYTE)&dwSettingsMask, &dwBufferSize) == ERROR_SUCCESS) - bConfigStatus = FALSE; - - // Apply bitmask to booleans - bAutoArrange = (dwSettingsMask & PMS_AUTOARRANGE); - bMinOnRun = (dwSettingsMask & PMS_MINONRUN); - bTopMost = (dwSettingsMask & PMS_TOPMOST); - bSaveSettings = (dwSettingsMask & PMS_SAVESETTINGS); - bShowUsername = (dwSettingsMask & PMS_SHOWUSERNAME); + if (bSettings) + { + DWORD dwBufferSize = sizeof(dwSettingsMask); - // Load window position... and apply it! - if (!RegQueryValueEx(hKeySettings, pszSettingsWindow, 0, &dwType, - (LPBYTE)&rcMainWindow, &dwRectBufferSize) == ERROR_SUCCESS) - bConfigStatus = FALSE; + // Load settings bitmask + if (!RegQueryValueEx(hKeySettings, pszSettingsMask, 0, &dwType, + (LPBYTE)&dwSettingsMask, &dwBufferSize) == ERROR_SUCCESS) + bConfigStatus = bConfigStatus && RCE_SETTINGS; + + // Apply bitmask to booleans + bAutoArrange = (dwSettingsMask & PMS_AUTOARRANGE); + bMinOnRun = (dwSettingsMask & PMS_MINONRUN); + bTopMost = (dwSettingsMask & PMS_TOPMOST); + bSaveSettings = (dwSettingsMask & PMS_SAVESETTINGS); + bShowUsername = (dwSettingsMask & PMS_SHOWUSERNAME); + } + + if (bPos) + { + DWORD dwRectBufferSize = sizeof(rcMainWindow); + + // Load window position + if (!RegQueryValueEx(hKeySettings, pszSettingsWindow, 0, &dwType, + (LPBYTE)&rcMainWindow, &dwRectBufferSize) == ERROR_SUCCESS) + bConfigStatus = bConfigStatus && RCE_POSITION; + } + + if (bGroups) + { + // TODO: this is unbearable + bConfigStatus = bConfigStatus && RCE_GROUPS; + } return bConfigStatus; } diff --git a/progmgr/registry.h b/progmgr/registry.h index 739a0ee..1e3bbf7 100644 --- a/progmgr/registry.h +++ b/progmgr/registry.h @@ -20,7 +20,12 @@ // #define PROGMAN_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Program Manager" // #define WINDOWS_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows" #define PROGMGR_KEY L"Software\\Vortesys\\Program Manager II" -// Settings Bitmask Values (DWORD) +// Registry configuration error values (DWORD) +#define RCE_SUCCESS 0x0000000 +#define RCE_SETTINGS 0x0000001 +#define RCE_POSITION 0x0000002 +#define RCE_GROUPS 0x0000004 +// Settings values (DWORD) #define PMS_AUTOARRANGE 0x00000001 #define PMS_MINONRUN 0x00000002 #define PMS_TOPMOST 0x00000004 @@ -43,5 +48,5 @@ extern RECT rcMainWindow; /* Function Prototypes */ BOOL InitializeRegistryKeys(VOID); BOOL IsProgMgrDefaultShell(VOID); -BOOL LoadConfig(VOID); -BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups); +DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups); +DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups);