void System::onRawArrival( HANDLE handle ) { UINT pathLength = 0; if ( GetRawInputDeviceInfoW( handle, RIDI_DEVICENAME, NULL, &pathLength ) ) NIL_EXCEPT_WINAPI( "GetRawInputDeviceInfoW failed" ); wideString rawPath( pathLength, '\0' ); GetRawInputDeviceInfoW( handle, RIDI_DEVICENAME, &rawPath[0], &pathLength ); rawPath.resize( rawPath.length() - 1 ); for ( auto device : mDevices ) { if ( device->getHandler() != Device::Handler_RawInput ) continue; auto rawDevice = static_cast<RawInputDevice*>( device ); if ( !_wcsicmp( rawDevice->getRawPath().c_str(), rawPath.c_str() ) ) { deviceConnect( rawDevice ); return; } } auto device = new RawInputDevice( this, getNextID(), handle, rawPath ); if ( isInitializing() ) device->setStatus( Device::Status_Connected ); else deviceConnect( device ); mDevices.push_back( device ); }
static bool getPathsForPathCompletion(generic_string input, generic_string &rawPath_out, generic_string &pathToMatch_out) { generic_string rawPath; if(! getRawPath(input, rawPath)) { return false; } else if(isFile(rawPath) || isFile(removeTrailingSlash(rawPath))) { return false; } else if(isDirectory(rawPath)) { rawPath_out = rawPath; pathToMatch_out = rawPath; return true; } else { size_t last_occurrence = rawPath.rfind(L"\\"); if(last_occurrence == std::string::npos) // No match. { return false; } else { rawPath_out = rawPath; pathToMatch_out = rawPath.substr(0, last_occurrence); return true; } } }