implemented enabling/disabling of devices Modified: trunk/reactos/lib/devmgr/advprop.c Modified: trunk/reactos/lib/devmgr/misc.c Modified: trunk/reactos/lib/devmgr/precomp.h _____
Modified: trunk/reactos/lib/devmgr/advprop.c --- trunk/reactos/lib/devmgr/advprop.c 2005-12-05 20:12:32 UTC (rev 19915) +++ trunk/reactos/lib/devmgr/advprop.c 2005-12-05 20:23:23 UTC (rev 19916) @@ -34,13 +34,6 @@
typedef HPROPSHEETPAGE (WINAPI *PCREATEPROPERTYSHEETPAGEW)(LPCPROPSHEETPAGEW); typedef BOOL (WINAPI *PDESTROYPROPERTYSHEETPAGE)(HPROPSHEETPAGE);
-typedef enum -{ - DEA_DISABLE = 0, - DEA_ENABLE, - DEA_UNKNOWN -} DEVENABLEACTION; - typedef struct _DEVADVPROP_INFO { HWND hWndGeneralPage; @@ -83,14 +76,10 @@ { INT Index; UINT i; - struct + UINT Actions[] = { - UINT szId; - DEVENABLEACTION Action; - } Actions[] = - { - {IDS_ENABLEDEVICE, DEA_ENABLE}, - {IDS_DISABLEDEVICE, DEA_DISABLE}, + IDS_ENABLEDEVICE, + IDS_DISABLEDEVICE, };
for (i = 0; @@ -99,7 +88,7 @@ { /* fill in the device usage combo box */ if (LoadString(hDllInstance, - Actions[i].szId, + Actions[i], dap->szTemp, sizeof(dap->szTemp) / sizeof(dap->szTemp[0]))) { @@ -112,11 +101,11 @@ SendMessage(hComboBox, CB_SETITEMDATA, (WPARAM)Index, - (LPARAM)Actions[i].Action); + (LPARAM)Actions[i]);
- switch (Actions[i].Action) + switch (Actions[i]) { - case DEA_ENABLE: + case IDS_ENABLEDEVICE: if (dap->DeviceEnabled) { SendMessage(hComboBox, @@ -126,7 +115,7 @@ } break;
- case DEA_DISABLE: + case IDS_DISABLEDEVICE: if (!dap->DeviceEnabled) { SendMessage(hComboBox, @@ -145,11 +134,11 @@ }
-static DEVENABLEACTION +static UINT GetSelectedUsageAction(IN HWND hComboBox) { INT Index; - DEVENABLEACTION Ret = DEA_UNKNOWN; + UINT Ret = 0;
Index = (INT)SendMessage(hComboBox, CB_GETCURSEL, @@ -161,9 +150,9 @@ CB_GETITEMDATA, (WPARAM)Index, 0); - if (iRet != CB_ERR && iRet < (INT)DEA_UNKNOWN) + if (iRet != CB_ERR) { - Ret = (DEVENABLEACTION)iRet; + Ret = (UINT)iRet; } }
@@ -171,44 +160,70 @@ }
-static VOID +static BOOL ApplyGeneralSettings(IN HWND hwndDlg, IN PDEVADVPROP_INFO dap) { + BOOL Ret = FALSE; + if (dap->DeviceUsageChanged && dap->IsAdmin) { - DEVENABLEACTION SelectedUsageAction; + UINT SelectedUsageAction; + BOOL NeedReboot = FALSE;
SelectedUsageAction = GetSelectedUsageAction(GetDlgItem(hwndDlg,
IDC_DEVUSAGE)); - if (SelectedUsageAction != DEA_UNKNOWN) + switch (SelectedUsageAction) { - switch (SelectedUsageAction) - { - case DEA_ENABLE: - if (!dap->DeviceEnabled) - { - /* FIXME - enable device */ - } - break; + case IDS_ENABLEDEVICE: + if (!dap->DeviceEnabled) + { + Ret = EnableDevice(dap->DeviceInfoSet, + &dap->DeviceInfoData, + TRUE, + 0, + &NeedReboot); + } + break;
- case DEA_DISABLE: - if (dap->DeviceEnabled) - { - /* FIXME - disable device */ - } - break; + case IDS_DISABLEDEVICE: + if (dap->DeviceEnabled) + { + Ret = EnableDevice(dap->DeviceInfoSet, + &dap->DeviceInfoData, + FALSE, + 0, + &NeedReboot); + } + break;
- default: - break; + default: + break; + } + + if (Ret) + { + if (NeedReboot) + { + /* make PropertySheet() return PSM_REBOOTSYSTEM */ + PropSheet_RebootSystem(hwndDlg); } } + else + { + /* FIXME - display an error message */ + DPRINT1("Failed to enable/disable device! LastError: %d\n", + GetLastError()); + } } + else + Ret = !dap->DeviceUsageChanged;
/* disable the apply button */ PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg); dap->DeviceUsageChanged = FALSE; + return Ret; }
_____
Modified: trunk/reactos/lib/devmgr/misc.c --- trunk/reactos/lib/devmgr/misc.c 2005-12-05 20:12:32 UTC (rev 19915) +++ trunk/reactos/lib/devmgr/misc.c 2005-12-05 20:23:23 UTC (rev 19916) @@ -613,6 +613,71 @@
BOOL +EnableDevice(IN HDEVINFO DeviceInfoSet, + IN PSP_DEVINFO_DATA DevInfoData OPTIONAL, + IN BOOL bEnable, + IN DWORD HardwareProfile OPTIONAL, + OUT BOOL *bNeedReboot OPTIONAL) +{ + SP_PROPCHANGE_PARAMS pcp; + SP_DEVINSTALL_PARAMS dp; + DWORD LastErr; + BOOL Ret = FALSE; + + pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); + pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; + pcp.HwProfile = HardwareProfile; + + if (bEnable) + { + /* try to enable/disable the device on the global profile */ + pcp.StateChange = DICS_ENABLE; + pcp.Scope = DICS_FLAG_GLOBAL; + + /* ignore errors */ + LastErr = GetLastError(); + if (SetupDiSetClassInstallParams(DeviceInfoSet, + DevInfoData, + &pcp.ClassInstallHeader, + sizeof(SP_PROPCHANGE_PARAMS))) + { + SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, + DeviceInfoSet, + DevInfoData); + } + SetLastError(LastErr); + } + + /* try config-specific */ + pcp.StateChange = (bEnable ? DICS_ENABLE : DICS_DISABLE); + pcp.Scope = DICS_FLAG_CONFIGSPECIFIC; + + if (SetupDiSetClassInstallParams(DeviceInfoSet, + DevInfoData, + &pcp.ClassInstallHeader, + sizeof(SP_PROPCHANGE_PARAMS)) && + SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, + DeviceInfoSet, + DevInfoData)) + { + dp.cbSize = sizeof(SP_DEVINSTALL_PARAMS); + if (SetupDiGetDeviceInstallParams(DeviceInfoSet, + DevInfoData, + &dp)) + { + if (bNeedReboot != NULL) + { + *bNeedReboot = ((dp.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT)) != 0); + } + + Ret = TRUE; + } + } + return Ret; +} + + +BOOL GetDeviceTypeString(IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize) _____
Modified: trunk/reactos/lib/devmgr/precomp.h --- trunk/reactos/lib/devmgr/precomp.h 2005-12-05 20:12:32 UTC (rev 19915) +++ trunk/reactos/lib/devmgr/precomp.h 2005-12-05 20:23:23 UTC (rev 19916) @@ -267,6 +267,13 @@
OUT BOOL *IsEnabled);
BOOL +EnableDevice(IN HDEVINFO DeviceInfoSet, + IN PSP_DEVINFO_DATA DevInfoData OPTIONAL, + IN BOOL bEnable, + IN DWORD HardwareProfile OPTIONAL, + OUT BOOL *bNeedReboot OPTIONAL); + +BOOL GetDeviceTypeString(IN PSP_DEVINFO_DATA DeviceInfoData, OUT LPWSTR szBuffer, IN DWORD BufferSize);