Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Get all the connected drives on the running machine.
  2. std::vector<std::string> AssiFileFinder::get_connected_drives()
  3. {
  4.     std::list<std::wstring> usb_list;
  5.  
  6.     wchar_t drives[256];
  7.     wchar_t* temp = drives;
  8.  
  9.     GetLogicalDriveStrings(256, drives);
  10.  
  11.     // Check for each drive if they are removable
  12.     while(*temp != NULL)
  13.     {
  14.         const auto drive_type = GetDriveTypeW(temp);
  15.  
  16.         // Check if the drive is removable
  17.         if(drive_type == 2 || drive_type == 3)
  18.         {
  19.             usb_list.emplace_back(temp);
  20.         }
  21.  
  22.         temp += lstrlenW(temp) + 1;
  23.     }
  24.  
  25.     std::vector<std::string> connected_drives;
  26.  
  27.     // Add drives to vector
  28.     for (auto element : usb_list)
  29.     {
  30.         std::string connected_drive(element.begin(), element.end());
  31.         connected_drives.push_back(connected_drive);
  32.     }
  33.  
  34.     return connected_drives;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement