diff options
Diffstat (limited to 'windows/driverlogic/src/device.cpp')
| -rw-r--r-- | windows/driverlogic/src/device.cpp | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/windows/driverlogic/src/device.cpp b/windows/driverlogic/src/device.cpp index e38709f01d..71abb56266 100644 --- a/windows/driverlogic/src/device.cpp +++ b/windows/driverlogic/src/device.cpp @@ -38,47 +38,6 @@ constexpr SIZE_T ST_DRIVER_STATE_STARTED = 1; // Onwards. // -void -ThrowUpdateException -( - DWORD lastError, - const char *operation -) -{ - if (ERROR_DEVICE_INSTALLER_NOT_READY == lastError) - { - bool deviceInstallDisabled = false; - - try - { - const auto key = common::registry::Registry::OpenKey - ( - HKEY_LOCAL_MACHINE, - L"SYSTEM\\CurrentControlSet\\Services\\DeviceInstall\\Parameters" - ); - - deviceInstallDisabled = (0 != key->readUint32(L"DeviceInstallDisabled")); - } - catch (...) - { - } - - if (deviceInstallDisabled) - { - throw common::error::WindowsException - ( - "Device installs must be enabled to continue. " - "Enable them in the Local Group Policy editor, or " - "update the registry value DeviceInstallDisabled in " - "[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\DeviceInstall\\Parameters]", - lastError - ); - } - } - - THROW_SETUPAPI_ERROR(lastError, operation); -} - } // anonymous namespace std::wstring @@ -196,135 +155,6 @@ GetDeviceNetCfgInstanceId } void -CreateDevice -( - const GUID &classGuid, - const std::wstring &deviceName, - const std::wstring &deviceHardwareId -) -{ - Log(L"Attempting to create device"); - - const auto deviceInfoSet = SetupDiCreateDeviceInfoList(&classGuid, 0); - - if (INVALID_HANDLE_VALUE == deviceInfoSet) - { - THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCreateDeviceInfoList"); - } - - common::memory::ScopeDestructor scopeDestructor; - - scopeDestructor += [&deviceInfoSet]() - { - SetupDiDestroyDeviceInfoList(deviceInfoSet); - }; - - SP_DEVINFO_DATA devInfoData {0}; - devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); - - auto status = SetupDiCreateDeviceInfoW - ( - deviceInfoSet, - deviceName.c_str(), - &classGuid, - nullptr, - 0, - DICD_GENERATE_ID, - &devInfoData - ); - - if (FALSE == status) - { - THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCreateDeviceInfoW"); - } - - status = SetupDiSetDeviceRegistryPropertyW - ( - deviceInfoSet, - &devInfoData, - SPDRP_HARDWAREID, - reinterpret_cast<const BYTE *>(deviceHardwareId.c_str()), - static_cast<DWORD>(deviceHardwareId.size() * sizeof(wchar_t)) - ); - - if (FALSE == status) - { - THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiSetDeviceRegistryPropertyW"); - } - - // - // Create a devnode in the PnP HW tree - // - status = SetupDiCallClassInstaller - ( - DIF_REGISTERDEVICE, - deviceInfoSet, - &devInfoData - ); - - if (FALSE == status) - { - THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCallClassInstaller"); - } - - Log(L"Created new device successfully"); -} - -void -InstallDriverForDevice -( - const std::wstring &deviceHardwareId, - const std::wstring &infPath -) -{ - Log(L"Attempting to install new driver"); - - DWORD installFlags = 0; - BOOL rebootRequired = FALSE; - - for (;;) - { - auto result = UpdateDriverForPlugAndPlayDevicesW - ( - nullptr, - deviceHardwareId.c_str(), - infPath.c_str(), - installFlags, - &rebootRequired - ); - - if (FALSE != result) - { - break; - } - - const auto lastError = GetLastError(); - - if (ERROR_NO_MORE_ITEMS == lastError - && (0 == (installFlags & INSTALLFLAG_FORCE))) - { - Log(L"Driver installation/update failed. Attempting forced install."); - installFlags |= INSTALLFLAG_FORCE; - - continue; - } - - ThrowUpdateException(lastError, "UpdateDriverForPlugAndPlayDevicesW"); - } - - // - // Driver successfully installed or updated - // - - std::wstringstream ss; - - ss << L"Device driver update complete. Reboot required: " - << rebootRequired; - - Log(ss.str()); -} - -void UninstallDevice ( const EnumeratedDevice &device |
