From: Aric Stewart Subject: [PATCH 4/5] programs/winedevice: Dynamically load devices into group device Message-Id: <8e1ee7e7-df47-9856-6dcb-b877d235df12@codeweavers.com> Date: Tue, 9 Aug 2016 11:40:29 -0500 Signed-off-by: Aric Stewart --- programs/winedevice/device.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/programs/winedevice/device.c b/programs/winedevice/device.c index 636ab2f..dfc9fc3 100644 --- a/programs/winedevice/device.c +++ b/programs/winedevice/device.c @@ -341,6 +341,43 @@ static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_ SetServiceStatus( service_handle, &status ); SetEvent( stop_event ); return NO_ERROR; + case SERVICE_USER_DEFINED_CONTROL+1: + { + int i; + + EnterCriticalSection(&group_cs); + WINE_TRACE( "Loading Device %s into group %s\n", debugstr_w(event_data) , debugstr_w(service_name)); + + /* check to see if driver is already loaded */ + for (i = 0; i < device_count; i++) + { + if (lstrcmpW(devices[i].driver_name, event_data) == 0) + { + WINE_TRACE("Driver already loaded\n"); + LeaveCriticalSection(&group_cs); + return NO_ERROR; + } + } + + if ( device_count + 1 >= devices_size ) + { + device *new_group; + devices_size *= 2; + new_group = HeapReAlloc( GetProcessHeap(), 0, devices, devices_size * sizeof(devices[0]) ); + devices = new_group; + } + + lstrcpyW(devices[device_count].driver_name, event_data); + device_count++; + + if (create_driver(event_data, &devices[device_count-1].driver_obj) != STATUS_SUCCESS) + { + WINE_ERR( "driver %s failed to load\n", wine_dbgstr_w(event_data) ); + } + + LeaveCriticalSection(&group_cs); + } + return NO_ERROR; default: WINE_FIXME( "got service ctrl %x for %s\n", ctrl, wine_dbgstr_w(service_name) ); status.dwCurrentState = SERVICE_RUNNING; @@ -401,11 +438,27 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv ) int wmain( int argc, WCHAR *argv[] ) { + static WCHAR szGroupArg[] = {'/','g','r','o','u','p',0}; SERVICE_TABLE_ENTRYW service_table[2]; static WCHAR szGroupName[] = {'g','r','o','u','p','_',0}; WCHAR *service_name; - if (!argv[1]) + if (argc == 3 && lstrcmpW(argv[1], szGroupArg) == 0) + { + device_count = 0; + devices_size = 5; + devices = HeapAlloc(GetProcessHeap(), 0, sizeof(*devices) * devices_size); + if (!devices) + { + WINE_ERR("Failed to allocate group\n"); + return 1; + } + + service_name = HeapAlloc(GetProcessHeap(), 0, lstrlenW(argv[2]) * sizeof(WCHAR) + sizeof(szGroupName)); + lstrcpyW(service_name, szGroupName); + lstrcatW(service_name, argv[2]); + } + else if (!argv[1]) { WINE_ERR( "missing device name, winedevice isn't supposed to be run manually\n" ); return 1;