From 60261f9699eee72ebcaf6de40cb4542b302de5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Fri, 30 Sep 2005 11:07:15 +0000 Subject: [PATCH] Add newdev.dll, and implement DevInstallW function. It permits to install devices from command line. ATM, very little functionality is supported. svn path=/trunk/; revision=18165 --- reactos/lib/directory.xml | 3 + reactos/lib/newdev/newdev.c | 218 ++++++++++++++++++++++++++++++++++ reactos/lib/newdev/newdev.def | 16 +++ reactos/lib/newdev/newdev.xml | 6 + 4 files changed, 243 insertions(+) create mode 100644 reactos/lib/newdev/newdev.c create mode 100644 reactos/lib/newdev/newdev.def create mode 100644 reactos/lib/newdev/newdev.xml diff --git a/reactos/lib/directory.xml b/reactos/lib/directory.xml index 5efdea6181b..3e645743323 100644 --- a/reactos/lib/directory.xml +++ b/reactos/lib/directory.xml @@ -164,6 +164,9 @@ + + + diff --git a/reactos/lib/newdev/newdev.c b/reactos/lib/newdev/newdev.c new file mode 100644 index 00000000000..0f481e471b7 --- /dev/null +++ b/reactos/lib/newdev/newdev.c @@ -0,0 +1,218 @@ +/* + * ReactOS New devices installation + * Copyright (C) 2004 ReactOS Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* + * PROJECT: ReactOS New devices installation + * FILE: lib/newdev/newdev.c + * PURPOSE: New devices installation + * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org) + */ + +#include +#include + +ULONG DbgPrint(PCH Format,...); +#define UNIMPLEMENTED \ + DbgPrint("NEWDEV: %s at %s:%d is UNIMPLEMENTED!\n",__FUNCTION__,__FILE__,__LINE__) +#define DPRINT1 DbgPrint("(%s:%d) ", __FILE__, __LINE__), DbgPrint + +BOOL +DevInstallW( + IN HWND Hwnd, + IN HINSTANCE Handle, + IN LPCWSTR InstanceId, + IN INT Show) +{ + HDEVINFO hDevInfo; + SP_DEVINFO_DATA devInfoData; + SP_DRVINFO_DATA_W drvInfoData; + DWORD index; + BOOL ret; + + DbgPrint("OK\n"); + DbgPrint("Installing device %S\n", InstanceId); + + hDevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL); + if (hDevInfo == INVALID_HANDLE_VALUE) + { + DPRINT1("SetupDiCreateDeviceInfoListExW() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + ret = SetupDiOpenDeviceInfoW( + hDevInfo, + InstanceId, + NULL, + 0, /* Open flags */ + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiOpenDeviceInfoW() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiBuildDriverInfoList(hDevInfo, &devInfoData, SPDIT_COMPATDRIVER); + if (!ret) + { + DPRINT1("SetupDiBuildDriverInfoList() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + +#ifndef NDEBUG + ret = TRUE; + index = 0; + drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA_W); + while (ret) + { + ret = SetupDiEnumDriverInfoW( + hDevInfo, + &devInfoData, + SPDIT_COMPATDRIVER, + index, + &drvInfoData); + if (!ret) + { + if (GetLastError() != ERROR_NO_MORE_ITEMS) + { + DPRINT1("SetupDiEnumDriverInfoW() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + break; + } + index++; + DPRINT1("- %S: %S\n", drvInfoData.MfgName, drvInfoData.Description); + } +#endif + + ret = SetupDiCallClassInstaller( + DIF_SELECTBESTCOMPATDRV, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_ALLOW_INSTALL, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_NEWDEVICEWIZARD_PREANALYZE, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_NEWDEVICEWIZARD_POSTANALYZE, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_INSTALLDEVICEFILES, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_REGISTER_COINSTALLERS, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_INSTALLINTERFACES, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_INSTALLDEVICE, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_NEWDEVICEWIZARD_FINISHINSTALL, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiCallClassInstaller( + DIF_DESTROYPRIVATEDATA, + hDevInfo, + &devInfoData); + if (!ret) + { + DPRINT1("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiDestroyDriverInfoList(hDevInfo, &devInfoData, SPDIT_COMPATDRIVER); + if (!ret) + { + DPRINT1("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + ret = SetupDiDestroyDeviceInfoList(hDevInfo); + if (!ret) + { + DPRINT1("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError()); + return FALSE; + } + + return TRUE; +} diff --git a/reactos/lib/newdev/newdev.def b/reactos/lib/newdev/newdev.def new file mode 100644 index 00000000000..60146144e7c --- /dev/null +++ b/reactos/lib/newdev/newdev.def @@ -0,0 +1,16 @@ +LIBRARY newdev.dll + +EXPORTS +DevInstallW +;InstallDevInst +;InstallDevInstEx +;InstallNewDevice +;InstallSelectedDevice +;InstallSelectedDriver +;InstallWindowsUpdateDriver +;RollbackDriver +;UpdateDriverForPlugAndPlayDevicesA +;UpdateDriverForPlugAndPlayDevicesA@20=UpdateDriverForPlugAndPlayDevicesA +;UpdateDriverForPlugAndPlayDevicesW + +;EOF \ No newline at end of file diff --git a/reactos/lib/newdev/newdev.xml b/reactos/lib/newdev/newdev.xml new file mode 100644 index 00000000000..8348cbc81d9 --- /dev/null +++ b/reactos/lib/newdev/newdev.xml @@ -0,0 +1,6 @@ + + + newdev.c + ntdll + setupapi +