From a54b06c8cd7965b0dd865518e8c657614593a03c Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Fri, 8 Apr 2011 22:04:41 +0000 Subject: [PATCH] [SNDVOL32] - Always write line states configuration values in one step - Fixes the problem when old line state settings were not present - Advantage is that it is faster and sndvol32 now works in ReactOS svn path=/trunk/; revision=51286 --- reactos/base/applications/sndvol32/misc.c | 66 ++----------------- reactos/base/applications/sndvol32/sndvol32.c | 20 +++++- reactos/base/applications/sndvol32/sndvol32.h | 4 +- 3 files changed, 25 insertions(+), 65 deletions(-) diff --git a/reactos/base/applications/sndvol32/misc.c b/reactos/base/applications/sndvol32/misc.c index 48c1d955f3b..2eabfc9ed2c 100644 --- a/reactos/base/applications/sndvol32/misc.c +++ b/reactos/base/applications/sndvol32/misc.c @@ -160,13 +160,10 @@ CloseAppConfig(VOID) BOOL WriteLineConfig(IN LPTSTR szDeviceName, IN LPTSTR szLineName, - IN LPTSTR szControlName, - IN DWORD Flags) + IN PSNDVOL_REG_LINESTATE LineState, + IN DWORD cbSize) { HKEY hLineKey; - DWORD Type; - DWORD i, Size = 0; - PSNDVOL_REG_LINESTATE LineStates = NULL; TCHAR szDevRegKey[MAX_PATH]; BOOL Ret = FALSE; @@ -185,67 +182,14 @@ WriteLineConfig(IN LPTSTR szDeviceName, &hLineKey, NULL) == ERROR_SUCCESS) { - if (RegQueryValueEx(hLineKey, - LineStatesValue, - NULL, - &Type, - NULL, - &Size) != ERROR_SUCCESS || - Type != REG_BINARY || - Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0)) - { - goto ExitClose; - } + /* now update line states */ + RegSetValueEx(hLineKey, LineStatesValue, 0, REG_BINARY, (const BYTE*)LineState, cbSize); + Ret = TRUE; - LineStates = HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, - Size); - - if (LineStates != NULL) - { - if (RegQueryValueEx(hLineKey, - LineStatesValue, - NULL, - &Type, - (LPBYTE)LineStates, - &Size) != ERROR_SUCCESS || - Type != REG_BINARY || - Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0)) - { - goto ExitClose; - } - - /* try to find the control */ - for (i = 0; i < Size / sizeof(SNDVOL_REG_LINESTATE); i++) - { - if (!_tcscmp(szControlName, - LineStates[i].LineName)) - { - LineStates[i].Flags = Flags; - Ret = TRUE; - break; - } - } - - /* now update line states */ - if (Ret) - { - RegSetValueEx(hLineKey, LineStatesValue, 0, REG_BINARY, (const BYTE*)LineStates, Size); - } - } - -ExitClose: - HeapFree(GetProcessHeap(), - 0, - LineStates); RegCloseKey(hLineKey); } return Ret; - - - - } BOOL diff --git a/reactos/base/applications/sndvol32/sndvol32.c b/reactos/base/applications/sndvol32/sndvol32.c index df69bb9cf0a..895949cbc81 100644 --- a/reactos/base/applications/sndvol32/sndvol32.c +++ b/reactos/base/applications/sndvol32/sndvol32.c @@ -347,6 +347,7 @@ WriteLineSettings(PREFERENCES_CONTEXT Context, HWND hwndDlg) WCHAR LineName[MIXER_LONG_NAME_CHARS]; WCHAR DestinationName[MIXER_LONG_NAME_CHARS]; DWORD Flags; + PSNDVOL_REG_LINESTATE LineStates; /* get list view */ hwndControls = GetDlgItem(hwndDlg, IDC_CONTROLS); @@ -364,6 +365,14 @@ WriteLineSettings(PREFERENCES_CONTEXT Context, HWND hwndDlg) } /* allocate line states array */ + LineStates = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SNDVOL_REG_LINESTATE) * Count); + if (LineStates == NULL) + { + /* failed to allocate line states array */ + return; + } + + for(Index = 0; Index < Count; Index++) { /* set to empty */ @@ -378,11 +387,18 @@ WriteLineSettings(PREFERENCES_CONTEXT Context, HWND hwndDlg) /* get check state */ Flags = (ListView_GetCheckState(hwndControls, Index) == 0 ? 0x4 : 0); - /* write configuration */ - WriteLineConfig(Preferences.DeviceName, DestinationName, LineName, Flags); + /* copy line name */ + wcscpy(LineStates[Index].LineName, LineName); + + /* store flags */ + LineStates[Index].Flags = Flags; } + /* now write the line config */ + WriteLineConfig(Preferences.DeviceName, DestinationName, LineStates, sizeof(SNDVOL_REG_LINESTATE) * Count); + /* free line states */ + HeapFree(GetProcessHeap(), 0, LineStates); } static INT_PTR CALLBACK diff --git a/reactos/base/applications/sndvol32/sndvol32.h b/reactos/base/applications/sndvol32/sndvol32.h index 520ff7d59ff..d6d3e10244f 100644 --- a/reactos/base/applications/sndvol32/sndvol32.h +++ b/reactos/base/applications/sndvol32/sndvol32.h @@ -160,7 +160,7 @@ ReadLineConfig(IN LPTSTR szDeviceName, BOOL WriteLineConfig(IN LPTSTR szDeviceName, IN LPTSTR szLineName, - IN LPTSTR szControlName, - IN DWORD Flags); + IN PSNDVOL_REG_LINESTATE LineState, + IN DWORD cbSize); #endif /* __SNDVOL32_H */