- short err = noErr ;
-
- while ( err == noErr )
- {
- m_index++ ;
- m_CPB.dirInfo.ioFDirIndex = m_index;
- m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */
- err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB);
- if ( err != noErr )
- break ;
-
-#if TARGET_CARBON
- p2cstrcpy( c_name, m_name ) ;
- strcpy( (char *)m_name, c_name);
-#else
- p2cstr( m_name ) ;
-#endif
-#if TARGET_CARBON
- // under X thats the way the mounting points look like
- if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) )
- break ;
-#endif
- if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory
- break ;
-
- if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it
- continue ;
-
- if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it
- continue ;
-
- wxString file( m_name ) ;
- if ( m_filespec.IsEmpty() || m_filespec == "*.*" || m_filespec == "*" )
- {
- }
- else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" )
- {
- if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() )
- {
- continue ;
- }
- }
- else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" )
- {
- if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() )
- {
- continue ;
- }
- }
- else if ( file.Upper() != m_filespec.Upper() )
- {
- continue ;
- }
-
- break ;
- }
- if ( err != noErr )
- {
- return FALSE ;
- }
-
- *filename = (char*) m_name ;
-
- return TRUE;
+ wxString name ;
+
+ while( noErr == err )
+ {
+ HFSUniStr255 uniname ;
+ FSRef fileRef;
+ FSCatalogInfo catalogInfo;
+ UInt32 fetched = 0;
+
+ err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname );
+
+ // expected error codes
+
+ if ( errFSNoMoreItems == err )
+ return false ;
+ if ( afpAccessDenied == err )
+ return false ;
+
+ if ( noErr != err )
+ break ;
+
+ name = wxMacHFSUniStrToString( &uniname ) ;
+
+ if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) )
+ continue;
+
+ if ( ( name[0U] == '.' ) && !(m_flags & wxDIR_HIDDEN ) )
+ continue ;
+
+ if ( (((FileInfo*)&catalogInfo.finderInfo)->finderFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN ) )
+ continue ;
+
+ // its a dir and we don't want it
+ if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) && !(m_flags & wxDIR_DIRS) )
+ continue ;
+
+ // its a file but we don't want it
+ if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0 && !(m_flags & wxDIR_FILES ) )
+ continue ;
+
+ if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") )
+ {
+ }
+ else if ( !wxMatchWild(m_filespec, name , false) )
+ {
+ continue ;
+ }
+
+ break ;
+ }
+ if ( err != noErr )
+ {
+ return false ;
+ }
+
+ *filename = name ;
+ return true;