@mcesystems/usb-device-listener 1.0.38 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -222,31 +222,6 @@ void USBListener::HandleDeviceChange(WPARAM wParam, LPARAM lParam) {
222
222
  }
223
223
  }
224
224
 
225
- bool USBListener::GetDeviceInfoFromPath(const std::string& devicePath, DeviceInfo& info) {
226
- size_t hashPos = devicePath.rfind('#');
227
- if (hashPos == std::string::npos) {
228
- return false;
229
- }
230
-
231
- std::string deviceIdStr = devicePath.substr(4, hashPos - 4);
232
- std::replace(deviceIdStr.begin(), deviceIdStr.end(), '#', '\\');
233
-
234
- info.deviceId = deviceIdStr;
235
-
236
- if (!GetVidPid(info.deviceId, info.vid, info.pid)) {
237
- return false;
238
- }
239
-
240
- size_t lastHash = deviceIdStr.rfind('\\');
241
- if (lastHash != std::string::npos) {
242
- info.locationInfo = deviceIdStr.substr(lastHash + 1);
243
- } else {
244
- info.locationInfo = "";
245
- }
246
-
247
- return true;
248
- }
249
-
250
225
  /**
251
226
  * Format serial number in iOS-style dash-separated format
252
227
  * iOS UDIDs are typically 24-25 characters and formatted as: XXXXXXXX-XXXXXXXXXXXXXXXX
@@ -273,6 +248,35 @@ static std::string FormatSerialAsDeviceId(const std::string& serial) {
273
248
  return serial;
274
249
  }
275
250
 
251
+ bool USBListener::GetDeviceInfoFromPath(const std::string& devicePath, DeviceInfo& info) {
252
+ size_t hashPos = devicePath.rfind('#');
253
+ if (hashPos == std::string::npos) {
254
+ return false;
255
+ }
256
+
257
+ std::string deviceIdStr = devicePath.substr(4, hashPos - 4);
258
+ std::replace(deviceIdStr.begin(), deviceIdStr.end(), '#', '\\');
259
+
260
+ if (!GetVidPid(deviceIdStr, info.vid, info.pid)) {
261
+ return false;
262
+ }
263
+
264
+ // Extract serial number from the device ID (last segment after backslash)
265
+ // Format: USB\VID_XXXX&PID_XXXX\SERIAL_NUMBER
266
+ size_t lastBackslash = deviceIdStr.rfind('\\');
267
+ if (lastBackslash != std::string::npos && lastBackslash + 1 < deviceIdStr.length()) {
268
+ info.serialNumber = deviceIdStr.substr(lastBackslash + 1);
269
+ info.locationInfo = info.serialNumber;
270
+ // Format the serial number the same way as GetDeviceInfo does for cache key matching
271
+ info.deviceId = FormatSerialAsDeviceId(info.serialNumber);
272
+ } else {
273
+ info.locationInfo = "";
274
+ info.deviceId = deviceIdStr;
275
+ }
276
+
277
+ return true;
278
+ }
279
+
276
280
  bool USBListener::GetDeviceInfo(const std::string& devicePath, DeviceInfo& info) {
277
281
  size_t hashPos = devicePath.rfind('#');
278
282
  if (hashPos == std::string::npos) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcesystems/usb-device-listener",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "description": "Native cross-platform USB device listener for Windows and macOS",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",