+ if ( FSGetVRefNum(&((*theVolRefs)[index]), &vRefNum) != noErr ) {
+ continue;
+ }
+ if ( FSGetVInfo(vRefNum, &volumeName, NULL, NULL) != noErr ) {
+ continue;
+ }
+ // get C string from Unicode HFS name
+ // see: http://developer.apple.com/carbon/tipsandtricks.html
+ CFStringRef cfstr = CFStringCreateWithCharacters( kCFAllocatorDefault,
+ volumeName.unicode,
+ volumeName.length );
+ // Do something with str
+ char *cstr = NewPtr(CFStringGetLength(cfstr) + 1);
+ if (( cstr == NULL ) ||
+ !CFStringGetCString(cfstr, cstr, CFStringGetLength(cfstr) + 1,
+ kCFStringEncodingMacRoman))
+ {
+ CFRelease( cstr );
+ continue;
+ }
+ wxString name( cstr , wxConvLocal );
+ DisposePtr( cstr );
+ CFRelease( cfstr );
+
+ GetVolParmsInfoBuffer volParmsInfo;
+ UInt32 actualSize;
+ if ( FSGetVolParms(vRefNum, sizeof(volParmsInfo), &volParmsInfo, &actualSize) != noErr ) {
+ continue;
+ }
+
+ paths.Add(path);
+ names.Add(name);
+
+ if ( VolIsEjectable(&volParmsInfo) )
+ icon_ids.Add(wxFileIconsTable::cdrom);
+ else
+ icon_ids.Add(wxFileIconsTable::drive);
+ }
+ ::HUnlock( (Handle)theVolRefs );
+ ::DisposeHandle( (Handle)theVolRefs );
+ }
+#else // !__DARWIN__
+ FSSpec volume;
+ short index = 1;
+ while(1)
+ {
+ short actualCount = 0 ;
+ if (OnLine(&volume, 1, &actualCount, &index ) != noErr || actualCount==0)
+ {
+ break;
+ }
+
+ wxString name = wxMacFSSpec2MacFilename( &volume );
+ paths.Add(name + wxFILE_SEP_PATH);
+ names.Add(name);
+ icon_ids.Add(wxFileIconsTable::drive);
+ }
+#endif // __DARWIN__
+
+#elif defined(__UNIX__)
+ paths.Add(wxT("/"));
+ names.Add(wxT("/"));
+ icon_ids.Add(wxFileIconsTable::computer);
+#else
+ #error "Unsupported platform in wxGenericDirCtrl!"
+#endif
+ return paths.GetCount();
+}
+
+// ----------------------------------------------------------------------------
+// wxIsDriveAvailable
+// ----------------------------------------------------------------------------
+
+#if defined(__DOS__)
+
+bool wxIsDriveAvailable(const wxString& dirName)
+{
+ // FIXME_MGL - this method leads to hang up under Watcom for some reason
+#ifndef __WATCOMC__
+ if ( dirName.Len() == 3 && dirName[1u] == wxT(':') )
+ {
+ wxString dirNameLower(dirName.Lower());
+ // VS: always return TRUE for removable media, since Win95 doesn't
+ // like it when MS-DOS app accesses empty floppy drive
+ return (dirNameLower[0u] == wxT('a') ||
+ dirNameLower[0u] == wxT('b') ||
+ wxPathExists(dirNameLower));
+ }
+ else
+#endif
+ return TRUE;
+}
+
+#elif defined(__WINDOWS__) || defined(__OS2__)
+
+int setdrive(int drive)
+{
+#ifdef __WXWINCE__
+ return 0;
+#elif defined(__GNUWIN32__) && \
+ (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
+ return _chdrive(drive);
+#else
+ wxChar newdrive[4];
+
+ if (drive < 1 || drive > 31)
+ return -1;
+ newdrive[0] = (wxChar)(wxT('A') + drive - 1);
+ newdrive[1] = wxT(':');
+#ifdef __OS2__
+ newdrive[2] = wxT('\\');
+ newdrive[3] = wxT('\0');
+#else
+ newdrive[2] = wxT('\0');
+#endif
+#if defined(__WXMSW__)
+ if (::SetCurrentDirectory(newdrive))
+#else
+ // VA doesn't know what LPSTR is and has its own set
+ if (!DosSetCurrentDir((PSZ)newdrive))
+#endif
+ return 0;
+ else
+ return -1;
+#endif // !GNUWIN32
+}
+
+bool wxIsDriveAvailable(const wxString& dirName)
+{
+#ifdef __WXWINCE__
+ return FALSE;
+#else
+#ifdef __WIN32__
+ UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+#endif
+ bool success = TRUE;
+
+ // Check if this is a root directory and if so,
+ // whether the drive is available.
+ if (dirName.Len() == 3 && dirName[(size_t)1] == wxT(':'))
+ {
+ wxString dirNameLower(dirName.Lower());
+#if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
+ success = wxPathExists(dirNameLower);
+#else
+ #if defined(__OS2__)
+ // Avoid changing to drive since no media may be inserted.
+ if (dirNameLower[(size_t)0] == 'a' || dirNameLower[(size_t)0] == 'b')
+ return success;
+ #endif
+ int currentDrive = _getdrive();
+ int thisDrive = (int) (dirNameLower[(size_t)0] - 'a' + 1) ;
+ int err = setdrive( thisDrive ) ;
+ setdrive( currentDrive );
+
+ if (err == -1)
+ {
+ success = FALSE;
+ }
+#endif
+ }
+#ifdef __WIN32__
+ (void) SetErrorMode(errorMode);
+#endif
+
+ return success;
+#endif
+}
+#endif // __WINDOWS__ || __OS2__