fork(1) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test {
  5. public static void Main() {
  6.  
  7. var text = @"
  8. 178 // Got a device. Get the details.
  9. 179 SP_DEVINFO_DATA devdata = {sizeof(SP_DEVINFO_DATA)};
  10. 180 bOk = SetupDiGetDeviceInterfaceDetail(hDevInfo,
  11. 181 &ifcData, pDetData, dwDetDataSize, NULL, &devdata);
  12. 182 if (bOk) {
  13. 183 CString strDevPath(pDetData->DevicePath);
  14. 184 // Got a path to the device. Try to get some more info.
  15. 185 TCHAR fname[256];
  16. 186 TCHAR desc[256];
  17. 187 BOOL bSuccess = SetupDiGetDeviceRegistryProperty(
  18. 188 hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL,
  19. 189 (PBYTE)fname, sizeof(fname), NULL);
  20. 190 bSuccess = bSuccess && SetupDiGetDeviceRegistryProperty(
  21. 191 hDevInfo, &devdata, SPDRP_DEVICEDESC, NULL,
  22. 192 (PBYTE)desc, sizeof(desc), NULL);
  23. 193 BOOL bUsbDevice = FALSE;
  24. 194 TCHAR locinfo[256];
  25. 195 if (SetupDiGetDeviceRegistryProperty(
  26. 196 hDevInfo, &devdata, SPDRP_LOCATION_INFORMATION, NULL,
  27. 197 (PBYTE)locinfo, sizeof(locinfo), NULL))
  28. 198 {
  29. 199 // Just check the first three characters to determine
  30. 200 // if the port is connected to the USB bus. This isn't
  31. 201 // an infallible method; it would be better to use the
  32. 202 // BUS GUID. Currently, Windows doesn't let you query
  33. 203 // that though (SPDRP_BUSTYPEGUID seems to exist in
  34. 204 // documentation only).
  35. 205 bUsbDevice = (strncmp(locinfo, " + @"USB" + @", 3)==0);
  36. 206 }
  37. 207 if (bSuccess) {
  38. 208 // Add an entry to the array
  39. 209 SSerInfo si;
  40. 210 si.strDevPath = strDevPath;
  41. 211 si.strFriendlyName = fname;
  42. 212 si.strPortDesc = desc;
  43. 213 si.bUsbDevice = bUsbDevice;
  44. 214 asi.Add(si);
  45. 215 }
  46. 216
  47. 217 }
  48. 218 else {
  49. 219 strErr.Format("+ @"SetupDiGetDeviceInterfaceDetail failed. (err=%lx)"+ @",
  50. 220 GetLastError());
  51. 221 throw strErr;
  52. 222 }
  53. 223 }
  54. 224 else {
  55. 225 DWORD err = GetLastError();
  56. 226 if (err != ERROR_NO_MORE_ITEMS) {
  57. 227 strErr.Format(" + @"SetupDiEnumDeviceInterfaces failed. (err=%lx)" + @", err);
  58. 228 throw strErr;
  59. 229 }
  60. 230 }
  61. ";
  62.  
  63. Console.WriteLine(
  64. Regex.Replace(
  65. text,
  66. @"^[\d-]*\s*",
  67. "",
  68. RegexOptions.Multiline
  69. )
  70. );
  71.  
  72. }
  73. }
Success #stdin #stdout 0.06s 34096KB
stdin
Standard input is empty
stdout
// Got a device. Get the details.
SP_DEVINFO_DATA devdata = {sizeof(SP_DEVINFO_DATA)};
bOk = SetupDiGetDeviceInterfaceDetail(hDevInfo,
&ifcData, pDetData, dwDetDataSize, NULL, &devdata);
if (bOk) {
CString strDevPath(pDetData->DevicePath);
// Got a path to the device. Try to get some more info.
TCHAR fname[256];
TCHAR desc[256];
BOOL bSuccess = SetupDiGetDeviceRegistryProperty(
hDevInfo, &devdata, SPDRP_FRIENDLYNAME, NULL,
(PBYTE)fname, sizeof(fname), NULL);
bSuccess = bSuccess && SetupDiGetDeviceRegistryProperty(
hDevInfo, &devdata, SPDRP_DEVICEDESC, NULL,
(PBYTE)desc, sizeof(desc), NULL);
BOOL bUsbDevice = FALSE;
TCHAR locinfo[256];
if (SetupDiGetDeviceRegistryProperty(
hDevInfo, &devdata, SPDRP_LOCATION_INFORMATION, NULL,
(PBYTE)locinfo, sizeof(locinfo), NULL))
{
// Just check the first three characters to determine
// if the port is connected to the USB bus. This isn't
// an infallible method; it would be better to use the
// BUS GUID. Currently, Windows doesn't let you query
// that though (SPDRP_BUSTYPEGUID seems to exist in
// documentation only).
bUsbDevice = (strncmp(locinfo, USB, 3)==0);
}
if (bSuccess) {
// Add an entry to the array
SSerInfo si;
si.strDevPath = strDevPath;
si.strFriendlyName = fname;
si.strPortDesc = desc;
si.bUsbDevice = bUsbDevice;
asi.Add(si);
}
}
else {
strErr.Format(SetupDiGetDeviceInterfaceDetail failed. (err=%lx),
GetLastError());
throw strErr;
}
}
else {
DWORD err = GetLastError();
if (err != ERROR_NO_MORE_ITEMS) {
strErr.Format(SetupDiEnumDeviceInterfaces failed. (err=%lx), err);
throw strErr;
}
}