+// ----------------------------------------------------------------------------
+// wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/")
+// ----------------------------------------------------------------------------
+
+size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids)
+{
+#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
+
+#ifdef __WXWINCE__
+ // No logical drives; return "\"
+ paths.Add(wxT("\\"));
+ names.Add(wxT("\\"));
+ icon_ids.Add(wxFileIconsTable::computer);
+#elif defined(__WIN32__)
+ wxChar driveBuffer[256];
+ size_t n = (size_t) GetLogicalDriveStrings(255, driveBuffer);
+ size_t i = 0;
+ while (i < n)
+ {
+ wxString path, name;
+ path.Printf(wxT("%c:\\"), driveBuffer[i]);
+ name.Printf(wxT("%c:"), driveBuffer[i]);
+
+ int imageId;
+ int driveType = ::GetDriveType(path);
+ switch (driveType)
+ {
+ case DRIVE_REMOVABLE:
+ if (path == wxT("a:\\") || path == wxT("b:\\"))
+ imageId = wxFileIconsTable::floppy;
+ else
+ imageId = wxFileIconsTable::removeable;
+ break;
+ case DRIVE_CDROM:
+ imageId = wxFileIconsTable::cdrom;
+ break;
+ case DRIVE_REMOTE:
+ case DRIVE_FIXED:
+ default:
+ imageId = wxFileIconsTable::drive;
+ break;
+ }
+
+ paths.Add(path);
+ names.Add(name);
+ icon_ids.Add(imageId);
+
+ while (driveBuffer[i] != wxT('\0'))
+ i ++;
+ i ++;
+ if (driveBuffer[i] == wxT('\0'))
+ break;
+ }
+#elif defined(__OS2__)
+ APIRET rc;
+ ULONG ulDriveNum = 0;
+ ULONG ulDriveMap = 0;
+ rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
+ if ( rc == 0)
+ {
+ size_t i = 0;
+ while (i < 26)
+ {
+ if (ulDriveMap & ( 1 << i ))
+ {
+ wxString path, name;
+ path.Printf(wxT("%c:\\"), 'A' + i);
+ name.Printf(wxT("%c:"), 'A' + i);
+
+ // Note: If _filesys is unsupported by some compilers,
+ // we can always replace it by DosQueryFSAttach
+ char filesysname[20];
+ _filesys(name.fn_str(), filesysname, sizeof(filesysname));
+ /* FAT, LAN, HPFS, CDFS, NFS */
+ int imageId;
+ if (path == wxT("A:\\") || path == wxT("B:\\"))
+ imageId = wxFileIconsTable::floppy;
+ else if (!strcmp(filesysname, "CDFS"))
+ imageId = wxFileIconsTable::cdrom;
+ else if (!strcmp(filesysname, "LAN") ||
+ !strcmp(filesysname, "NFS"))
+ imageId = wxFileIconsTable::drive;
+ else
+ imageId = wxFileIconsTable::drive;
+ paths.Add(path);
+ names.Add(name);
+ icon_ids.Add(imageId);
+ }
+ i ++;
+ }
+ }
+#else // !__WIN32__, !__OS2__
+ int drive;
+
+ /* If we can switch to the drive, it exists. */
+ for( drive = 1; drive <= 26; drive++ )
+ {
+ wxString path, name;
+ path.Printf(wxT("%c:\\"), (char) (drive + 'a' - 1));
+ name.Printf(wxT("%c:"), (char) (drive + 'A' - 1));
+
+ if (wxIsDriveAvailable(path))
+ {
+ paths.Add(path);
+ names.Add(name);
+ icon_ids.Add((drive <= 2) ? wxFileIconsTable::floppy : wxFileIconsTable::drive);
+ }
+ }
+#endif // __WIN32__/!__WIN32__
+
+#elif defined(__WXMAC__)
+
+ ItemCount volumeIndex = 1;
+ OSErr err = noErr ;
+
+ while( noErr == err )
+ {
+ HFSUniStr255 volumeName ;
+ FSRef fsRef ;
+ FSVolumeInfo volumeInfo ;
+ err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef);
+ if( noErr == err )
+ {
+ wxString path = wxMacFSRefToPath( &fsRef ) ;
+ wxString name = wxMacHFSUniStrToString( &volumeName ) ;
+
+ if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) )
+ {
+ icon_ids.Add(wxFileIconsTable::cdrom);
+ }
+ else
+ {
+ icon_ids.Add(wxFileIconsTable::drive);
+ }
+ // todo other removable
+
+ paths.Add(path);
+ names.Add(name);
+ volumeIndex++ ;
+ }
+ }
+
+#elif defined(__UNIX__)
+ paths.Add(wxT("/"));
+ names.Add(wxT("/"));
+ icon_ids.Add(wxFileIconsTable::computer);
+#else
+ #error "Unsupported platform in wxGenericDirCtrl!"
+#endif
+ wxASSERT_MSG( (paths.GetCount() == names.GetCount()), wxT("The number of paths and their human readable names should be equal in number."));
+ wxASSERT_MSG( (paths.GetCount() == icon_ids.GetCount()), wxT("Wrong number of icons for available drives."));
+ return paths.GetCount();
+}
+
+// ----------------------------------------------------------------------------
+// wxIsDriveAvailable
+// ----------------------------------------------------------------------------
+
+#if defined(__DOS__)