| 109 | } |
| 110 | |
| 111 | bool DInputSource::ReloadDevices() |
| 112 | { |
| 113 | // detect any removals |
| 114 | PollEvents(); |
| 115 | |
| 116 | // look for new devices |
| 117 | std::vector<DIDEVICEINSTANCEW> devices; |
| 118 | m_dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumCallback, &devices, DIEDFL_ATTACHEDONLY); |
| 119 | |
| 120 | DevCon.WriteLn("Enumerated %zu devices", devices.size()); |
| 121 | |
| 122 | bool changed = false; |
| 123 | for (DIDEVICEINSTANCEW inst : devices) |
| 124 | { |
| 125 | // do we already have this one? |
| 126 | if (std::any_of( |
| 127 | m_controllers.begin(), m_controllers.end(), [&inst](const ControllerData& cd) { return inst.guidInstance == cd.guid; })) |
| 128 | { |
| 129 | // yup, so skip it |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | ControllerData cd; |
| 134 | cd.guid = inst.guidInstance; |
| 135 | HRESULT hr = m_dinput->CreateDevice(inst.guidInstance, cd.device.put(), nullptr); |
| 136 | if (FAILED(hr)) |
| 137 | { |
| 138 | Console.Warning("Failed to create instance of device [%s, %s]", inst.tszProductName, inst.tszInstanceName); |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | const std::string name(StringUtil::WideStringToUTF8String(inst.tszProductName)); |
| 143 | if (AddDevice(cd, name)) |
| 144 | { |
| 145 | const u32 index = static_cast<u32>(m_controllers.size()); |
| 146 | m_controllers.push_back(std::move(cd)); |
| 147 | InputManager::OnInputDeviceConnected(GetDeviceIdentifier(index), name); |
| 148 | changed = true; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return changed; |
| 153 | } |
| 154 | |
| 155 | void DInputSource::Shutdown() |
| 156 | { |
nothing calls this directly
no test coverage detected