Пример #1
0
BOOL file_listnext(FLISTH hdl, FLINFO *fli) {

	FLHDL		flhdl;
	ItemCount	count;
	OSStatus	r;
	UTCDateTime	*dt;

	flhdl = (FLHDL)hdl;
	if ((flhdl == NULL) || (flhdl->eoff)) {
		goto ffn_err;
	}
	r = FSGetCatalogInfoBulk(flhdl->fsi, 1, &count, NULL,
						kFSCatInfoNodeFlags | kFSCatInfoDataSizes |
						kFSCatInfoAllDates,
						&flhdl->fsci, NULL, NULL, &flhdl->name);
	if (r != noErr) {
		flhdl->eoff = TRUE;
		if (r != errFSNoMoreItems) {
			goto ffn_err;
		}
	}
	if (count != 1) {
		flhdl->eoff = TRUE;
		goto ffn_err;
	}
	if (fli) {
		fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME;
		if (flhdl->fsci.nodeFlags & kFSNodeIsDirectoryMask) {
			fli->attr = FILEATTR_DIRECTORY;
			fli->size = 0;
			dt = &flhdl->fsci.createDate;
		}
		else {
			fli->attr = FILEATTR_ARCHIVE;
			fli->size = (UINT32)flhdl->fsci.dataLogicalSize;
			dt = &flhdl->fsci.contentModDate;
		}
		if (flhdl->fsci.nodeFlags & kFSNodeLockedMask) {
			fli->attr |= FILEATTR_READONLY;
		}
		cnvdatetime(dt, &fli->date, &fli->time);
		char2str(fli->path, sizeof(fli->path),
								flhdl->name.unicode, flhdl->name.length);
	}
	return(SUCCESS);

ffn_err:
	return(FAILURE);
}
Пример #2
0
void	HLDirectory::FetchItems()
{
	if(!mItemsFetched)
	{
		mItems = new ItemList;
		
		//	make an FSIterator for this directory
		FSIterator theFSIterator;
		OSStatus theError = FSOpenIterator(&mFSRef, kFSIterateFlat, &theFSIterator);
		ThrowIfError(theError, CAException(theError), "HLDirectory::FetchItems: couldn't allocate the FSIterator");
		
		try
		{
			//	iterate through the items in the directory and get the FSRefs
			do
			{
				FSRef theFSRef;
				UInt32 theNumberItemsFetched = 0;
				
				theError = FSGetCatalogInfoBulk(theFSIterator, 1, &theNumberItemsFetched, NULL, kFSCatInfoNone, NULL, &theFSRef, NULL, NULL);
				ThrowIf((theError != 0) && (theError != errFSNoMoreItems), CAException(theError), "HLDirectory::FetchItems: couldn't get the catalog info");
				
				if(theError != errFSNoMoreItems)
				{
					mItems->push_back(theFSRef);
				}
			}
			while(theError != errFSNoMoreItems);
		
			mItemsFetched = true;
		}
		catch(...)
		{
			FSCloseIterator(theFSIterator);
			throw;
		}
	
		//	close the iterator
		FSCloseIterator(theFSIterator);
	}
}
Пример #3
0
static OSStatus AddCCLsInFolderToArray(const FSRef *folderRef, CFMutableArrayRef result)
	// Iterates through the contents of the folder specified by folderRef, 
	// adding the name of each CCL file (ie any file that's visible) to 
	// the result array.
{
	OSStatus			err;
	OSStatus			junk;
	FSRef *				scriptRefs;
	HFSUniStr255 *		scriptNames;
	FSIterator 			iter;
	ItemCount  			actCount;
	ItemCount			thisItemIndex;
	Boolean    			done;

	iter = NULL;
	scriptRefs = NULL;
	scriptNames = NULL;
	
	// Allocate buffers for the FSRefs and long Unicode names.  Given that 
	// we're processing 50 files at a time, these buffers are way too big 
	// to store on the stack (25 KB for scriptNames alone).
	
	scriptRefs  = (FSRef *) malloc( kFolderItemsPerBulkCall * sizeof(FSRef) );
	scriptNames = (HFSUniStr255 *) malloc( kFolderItemsPerBulkCall * sizeof(HFSUniStr255) );
	err = noErr;
	if (scriptRefs == NULL || scriptNames == NULL) {
		err = memFullErr;
	}
	
	// Create the iterator.
	
	if (err == noErr) {
		err = FSOpenIterator(folderRef, kFSIterateFlat, &iter);
	}
	
	// Iterate over the contents of the directory.  For each item found 
	// we check whether it's a visible plain file and, if it is, add its 
	// name to the array.
	
	if (err == noErr) {
		done = false;
		do {
			err = FSGetCatalogInfoBulk(iter, kFolderItemsPerBulkCall, &actCount, NULL, kFSCatInfoNone, NULL, 
									   scriptRefs, NULL, scriptNames);
			if (err == errFSNoMoreItems) {
				// We ran off the end of the directory.  Record that we're
				// done, but set err to noErr so that we process any partial
				// results.
				done = true;
				err = noErr;
			}
			if (err == noErr) {
				for (thisItemIndex = 0; thisItemIndex < actCount; thisItemIndex++) {
					Boolean visible;

					err = MyIsVisibleFile(&scriptRefs[thisItemIndex], &visible);
					if ( (err == noErr) && visible ) {
						CFStringRef thisItemName;
						
						thisItemName = CFStringCreateWithCharacters(NULL, scriptNames[thisItemIndex].unicode, scriptNames[thisItemIndex].length);
						if (thisItemName == NULL) {
							err = coreFoundationUnknownErr;
						}
						if (err == noErr) {
							CFArrayAppendValue(result, thisItemName);
						}
						CFQRelease(thisItemName);
					}
					if (err != noErr) {
						break;
					}
				}						
			}
		} while (err == noErr && !done);
	}

	// Clean up.
	
	if (iter != NULL) {
		junk = FSCloseIterator(iter);
		assert(junk == noErr);
	}
	if (scriptRefs != NULL) {
		free(scriptRefs);
	}
	if (scriptNames != NULL) {
		free(scriptNames);
	}

	return err;
}
Пример #4
0
// Search through the directory specified by 'parent' for an item that appears to be a Second Life viewer.
static OSErr findAppBundleOnDiskImage(FSRef *parent, FSRef *app)
{
	FSIterator		iterator;
	bool			found = false;

	OSErr err = FSOpenIterator( parent, kFSIterateFlat, &iterator );
	if(!err)
	{
		do
		{
			ItemCount actualObjects = 0;
			Boolean containerChanged = false;
			FSCatalogInfo info;
			FSRef ref;
			HFSUniStr255 unicodeName;
			err = FSGetCatalogInfoBulk( 
					iterator, 
					1, 
					&actualObjects, 
					&containerChanged,
					kFSCatInfoNodeFlags, 
					&info, 
					&ref,
					NULL, 
					&unicodeName );
			
			if(actualObjects == 0)
				break;
				
			if(!err)
			{
				// Call succeeded and not done with the iteration.
				std::string name = HFSUniStr255_to_utf8str(&unicodeName);

				llinfos << "Considering \"" << name << "\"" << llendl;

				if(info.nodeFlags & kFSNodeIsDirectoryMask)
				{
					// This is a directory.  See if it's a .app
					if(name.find(".app") != std::string::npos)
					{
						// Looks promising.  Check to see if it has the right bundle identifier.
						if(isFSRefViewerBundle(&ref))
						{
							llinfos << name << " is the one" << llendl;
							// This is the one.  Return it.
							*app = ref;
							found = true;
							break;
						} else {
							llinfos << name << " is not the bundle we are looking for; move along" << llendl;
						}

					}
				}
			}
		}
		while(!err);
		
		llinfos << "closing the iterator" << llendl;
		
		FSCloseIterator(iterator);
		
		llinfos << "closed" << llendl;
	}
	
	if(!err && !found)
		err = fnfErr;
		
	return err;
}
Пример #5
0
// -------------------------------------------------------------------------- //
//  * GetFolderItems( TDCLMacFiles*, const FSRef*, KUInt32* ) ...
// -------------------------------------------------------------------------- //
TDCLFSItemRef*
TDCLMacCarbonFolder::GetFolderItems(
				TDCLMacFiles* inFilesIntf,
				const FSRef* inRef,
				KUInt32* outCount ) 
{
	const ItemCount	kRequestCount = 4096; 
	TDCLFSItemRef* theResult =
						(TDCLFSItemRef*) ::malloc( sizeof( TDCLFSItemRef ) );
		// Terminateur
	KUInt32 theResultIndex = 0;

	// CrŽation d'un itŽrateur.
	FSIterator theIterator;
	OSStatus myStatus =
			::FSOpenIterator( inRef, kFSIterateFlat, &theIterator );

	if( myStatus != noErr )
	{
		throw DCLPlatformUnknownError( myStatus );
	}

	// Allocate storage for the returned information
	FSCatalogInfo* catalogInfoArray =
				(FSCatalogInfo *) ::malloc(
									sizeof(FSCatalogInfo) * kRequestCount );
	FSRef* fsRefArray =
				(FSRef *) ::malloc( sizeof(FSRef) * kRequestCount );

	ItemCount actualCount;
	Boolean gotThemAll = false;
	while ( !gotThemAll ) {
		myStatus = FSGetCatalogInfoBulk(
						theIterator,
						kRequestCount,
						&actualCount,
						NULL,
						kFSCatInfoNodeFlags | kFSCatInfoFinderInfo,
						catalogInfoArray,
						fsRefArray,
						NULL,
						NULL );

		if (myStatus == noErr)
		{
			gotThemAll = false;
		} else if (myStatus == errFSNoMoreItems) {
			gotThemAll = true;
		} else {
			// Nettoyage.
			::free( catalogInfoArray );
			::free( fsRefArray );
			KUInt32 indexResult;
			for (
					indexResult = 0;
					indexResult < theResultIndex;
					indexResult++)
			{
				theResult[indexResult].~TDCLFSItemRef();
			}
			::free( theResult );
			throw DCLPlatformUnknownError( myStatus );
		}
		
		// On redimensionne le rŽsultat.
		theResult = (TDCLFSItemRef*) ::realloc(
							theResult, 
							sizeof( TDCLFSItemRef )
								* (theResultIndex + 1 + actualCount) );

		// Ajout des ŽlŽments.		
		KUInt32 indexElements;
		for( indexElements = 0; indexElements < actualCount; indexElements++ )
		{
			if ( catalogInfoArray[indexElements].nodeFlags
												& kFSNodeIsDirectoryMask )
			{
				// bummer another folder...
				new (&theResult[theResultIndex++]) TDCLFSItemRef(
							new TDCLMacCarbonFolder(
										inFilesIntf,
										&fsRefArray[indexElements] ));
			} else {
				// congratulations, it's a file!
				new (&theResult[theResultIndex++]) TDCLFSItemRef(
							new TDCLMacCarbonFile(
										inFilesIntf,
										&fsRefArray[indexElements] ));
			}
		}
	}
	
	// LibŽration des tableaux.
	::free( (void *) catalogInfoArray );
	::free( (void *) fsRefArray );

	// Ajout du terminateur.
	new (&theResult[theResultIndex]) TDCLFSItemRef();
	
	// On retourne le nombre.
	if (outCount)
	{
		*outCount = theResultIndex;
	}

	return theResult;
}
Пример #6
0
bool wxDirData::Read(wxString *filename)
{
    wxString result;
    OSStatus err = noErr ;
    if ( NULL == m_iterator )
    {
        FSRef dirRef;
        err = wxMacPathToFSRef( m_dirname , &dirRef ) ;
        if ( err == noErr )
        {
            err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator);
        }
        if ( err )
        {
            Close() ;
            return false ;
        }
    }

    wxString name ;
    wxString lowerfilespec = m_filespec.Lower();

    while( noErr == err )
    {
        HFSUniStr255 uniname ;
        FSRef fileRef;
        FSCatalogInfo catalogInfo;
        ItemCount 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 ) ;
        wxString lowername = name.Lower();

        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(lowerfilespec, lowername , false) )
        {
            continue ;
        }

        break ;
    }
    if ( err != noErr )
    {
        return false ;
    }

    *filename = name ;
    return true;
}
Пример #7
0
void SplitForks(FSRef * inFileReference,FSRef * inParentReference,Boolean inFirstLevel)
{
	OSErr tErr;
	FSIterator tIterator;
	
	if (inFirstLevel==TRUE)
	{
		FSCatalogInfo tInfo;
		HFSUniStr255 tUnicodeFileName;
		
		// We need to split forks of the first level (and it allows us to check whether it's a folder or not)
		
		tErr=FSGetCatalogInfo(inFileReference,kFSCatInfoGettableInfo,&tInfo,&tUnicodeFileName,NULL,NULL);
		
		if (tErr==noErr)
		{
			// Check this is not a Hard Link
				
			if ((tInfo.nodeFlags & kFSNodeHardLinkMask)==0)
			{
				tErr=SplitFileIfNeeded(inFileReference,inParentReference,&tInfo,&tUnicodeFileName);
				
				if (tErr==noErr)
				{
					if (tInfo.nodeFlags & kFSNodeIsDirectoryMask)
					{
						// It's a folder
					
						// We need to proceed with the contents of the folder
					
						SplitForks(inFileReference,inParentReference,FALSE);
					}
				}
				else
				{
					exit(-1);
				}
			}
		}
		else
		{
			logerror("An error while getting Catalog Information for the File\n");
		}
		
		return;
	}
	
	tErr=FSOpenIterator(inFileReference,kFSIterateFlat,&tIterator);
	
	if (tErr==noErr)
	{
		ItemCount tLookForItems,tFoundItems;
		FSCatalogInfo * tFoundCatInfo;
		FSRef * tFoundReferences;
		HFSUniStr255 * tFoundFileNames;
		FSRef tPreviousCacheRef;
		Boolean tPreviousCacheRefSet=FALSE;
		
		tLookForItems=1;
			
		tFoundCatInfo=(FSCatalogInfo *) malloc(tLookForItems*sizeof(FSCatalogInfo));
			
		tFoundReferences=(FSRef *) malloc(tLookForItems*sizeof(FSRef));
		
		tFoundFileNames=(HFSUniStr255 *) malloc(tLookForItems*sizeof(HFSUniStr255));
		
		do
		{
			tErr=FSGetCatalogInfoBulk(tIterator, tLookForItems, &tFoundItems,
				NULL, kFSCatInfoGettableInfo, tFoundCatInfo,
				tFoundReferences, NULL, tFoundFileNames);
			
			if (tErr==noErr)
			{
				if (tPreviousCacheRefSet==TRUE)
				{
					if (FSCompareFSRefs(&tPreviousCacheRef,&tFoundReferences[0])==noErr)
					{
						// We need to skip the file since this is the one we processed previously
					
						continue;
					}
				}
				else
				{
					tPreviousCacheRefSet=TRUE;
				}
				
				tPreviousCacheRef=tFoundReferences[0];
				
				// Check this is not a Hard Link
				
				if ((tFoundCatInfo[0].nodeFlags & kFSNodeHardLinkMask)==0)
				{
					tErr=SplitFileIfNeeded(&tFoundReferences[0],inFileReference,&tFoundCatInfo[0],&tFoundFileNames[0]);
						
					if (tErr==noErr)
					{
						if (tFoundCatInfo[0].nodeFlags & kFSNodeIsDirectoryMask)
						{				
							// 2. We need to proceed with the contents of the folder
						
							SplitForks(&tFoundReferences[0],inFileReference,FALSE);
						}
					}
					else
					{
						exit(-1);
					}
				}
			}
			else
			{
				// A COMPLETER
			}
		}
		while (tErr==noErr);
		
		free(tFoundCatInfo);
		
		free(tFoundReferences);
		
		free(tFoundFileNames);
		
		FSCloseIterator (tIterator);
	}
	
	if (tErr!=noErr)
	{
		switch(tErr)
		{
			case errFSNoMoreItems:
				// No more items in the folder, this is perfectly ok
				break;
			case afpAccessDenied:
				break;
			default:
				// A COMPLETER
		
				break;
		}
	}
}
Пример #8
0
CHXDirectory::FSOBJ 
CHXDirectory::FindNext(char* szPath, UINT16 nSize)
{
	FSOBJ resultObjType;

	OSErr err;
	Boolean bIsDir;
	CHXString strTemp;
	HXBOOL bNameMatchesPattern;
	
	const ItemCount kWantOneItem = 1;
	Boolean * kDontCareIfContainerChanged = NULL;
	FSSpec * kDontWantFSSpecs = NULL;
	FSRef itemFSRef;
	HFSUniStr255 uniName;
	ItemCount actualCount;
	FSCatalogInfo catInfo;

	require_nonnull(m_FSIterator, bail); 

	// get an item, looping if it doesn't match the pattern
	do
	{
		err = FSGetCatalogInfoBulk(m_FSIterator, 
			kWantOneItem, &actualCount,
			kDontCareIfContainerChanged,
			kFSCatInfoNodeFlags, &catInfo,
			&itemFSRef, kDontWantFSSpecs,
			&uniName);
		
		if (err == noErr)
		{
			strTemp.SetFromHFSUniStr255(uniName, CFStringGetSystemEncoding());

			bNameMatchesPattern = CMacFindFile::pmatch((const char *) m_strFindPattern, (const char *) strTemp);
		}
		
	} while (err == noErr && !bNameMatchesPattern);
	
	if (err == noErr)
	{
		// got a file or directory that matches
		err = HFSPathFromFSRef(&itemFSRef, strTemp);
		require_noerr(err, bail);
		
		if (nSize >= (1 + strTemp.GetLength()))
		{
		    SafeStrCpy(szPath, (const char *) strTemp, nSize);
		}
		
		bIsDir = ((catInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0);

		resultObjType = (bIsDir ? FSOBJ_DIRECTORY : FSOBJ_FILE);
	}
	else
	{
		// no more found
		resultObjType = FSOBJ_NOTVALID;
	}

	return resultObjType;

bail:
	return FSOBJ_NOTVALID;

}
Пример #9
0
void TTFoundationLoadExternalClassesFromFolder(const TTString& fullpath)
{
#ifdef TT_PLATFORM_MAC
	FSRef							ref;
	Boolean							isDirectory;
	OSStatus						status = noErr;
	ItemCount						count = 0;	
    FSIterator						iterator;
	HFSUniStr255*					names = NULL;
	CFStringRef						name;
	char							cname[4096];
	TTString						path;
	TTCString						cpath = (char*)fullpath.c_str();
	void*							handle;
	TTExtensionInitializationMethod	initializer;
	TTErr							err;
	
	status = FSPathMakeRef((UInt8*)cpath, &ref, &isDirectory);
	if (status != noErr) {
#ifdef TT_DEBUG
		TTLogMessage("TTFoundation - no extensions location found @ %s\n", cpath);
#endif
		return;
	}
	
	status = FSOpenIterator(&ref, kFSIterateFlat, &iterator);
	if (!status) {
        names = (HFSUniStr255 *)malloc(sizeof(HFSUniStr255) * 4096);
        if (names) {
            // Request information about files in the given directory,
            // until we get a status code back from the File Manager
            do{
				status = FSGetCatalogInfoBulk(iterator, 4096, &count, NULL, kFSCatInfoNone, NULL, NULL, NULL, names);
				
                // Process all items received
                if (status == OSStatus(noErr) || status == OSStatus(errFSNoMoreItems)) {
                    for (UInt32 i=0; i < count; i += 1) {
  						name = CFStringCreateWithCharacters(kCFAllocatorDefault, names[i].unicode, names[i].length);
// TODO: filter on name.  We only want to try and load .ttdylib files						
						CFStringGetCString(name, cname, 4096, kCFStringEncodingUTF8);
						path = fullpath;
						path += "/";
						path += cname;
						
						handle = dlopen(path.c_str(), RTLD_LAZY);
// TODO: assert -- or at least do a log post -- if handle is NULL
						initializer = (TTExtensionInitializationMethod)dlsym(handle, "loadTTExtension");
						if (initializer)
							err = initializer();
						CFRelease(name);
                    }
                }
            }
            while (status == OSStatus(noErr));
			
            // errFSNoMoreItems tells us we have successfully processed all
            // items in the directory -- not really an error
            if (status == OSStatus(errFSNoMoreItems))
                status = noErr;
			
            // Free the array memory
            free( (void *) names );
        }
		FSCloseIterator(iterator);
    }
#elif TT_PLATFORM_WIN
	HANDLE							fdHandle;
	WIN32_FIND_DATA					findFileData;
	TTString						path;
	HANDLE							hLib = NULL;
	TTExtensionInitializationMethod	initializer;
	TTErr							err;

	path = fullpath;
	path += "*.ttdll";
	fdHandle = FindFirstFile(path.c_str(), &findFileData);
	if (fdHandle && (fdHandle != INVALID_HANDLE_VALUE)) {
		while (fdHandle) {
			path = fullpath;
			path += findFileData.cFileName;

			hLib = LoadLibrary(path.c_str());
			if (hLib) {
				initializer = (TTExtensionInitializationMethod)GetProcAddress((HMODULE)hLib, "loadTTExtension");
				if (initializer)
					err = initializer();
			}
			if (!FindNextFile(fdHandle, &findFileData))
				break;
		}
	}
#else
	;
#endif
}
Пример #10
0
//
// Get the next file in the directory. Filters according to pattern
//
char* CMacFindFile::OS_GetNextFile()
{
	require_nonnull_return(m_FSIterator, NULL); // be sure OS_OpenDirectory happened

	OSErr err;
	ItemCount actualCount;
	HFSUniStr255 uniName;
	FSCatalogInfo catInfo;
	Boolean bIsDir;
	
	const ItemCount kWantOneItem = 1;
	Boolean * kDontCareIfContainerChanged = NULL;
	FSSpec * kDontWantFSSpecs = NULL;
	FSRef * kDontWantFSRefs = NULL;
	
	// reset our output string; we'll return nil if we fail, anyway
	HX_VECTOR_DELETE(m_pszOutFileName);

	// get an item, looping if we got a directory
	do
	{
		err = FSGetCatalogInfoBulk(m_FSIterator, 
			kWantOneItem, &actualCount,
			kDontCareIfContainerChanged,
			kFSCatInfoNodeFlags, &catInfo,
			kDontWantFSRefs, kDontWantFSSpecs, 
			&uniName);
			
		bIsDir = ((catInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0);
                
#ifdef _MAC_MACHO
                if (!err && m_pattern)
                {
                    if (!strcmp(m_pattern, "*.bundle"))
                    {
                        // if we're looking for bundles let's assume we can
                        // call directories whose names end with ".bundle"
                        // files so plugin counters work.
                        CHXCFString str(uniName);
                        CFStringRef strR = str;
                        char buf[1024];
                        CFStringGetCString(strR, buf, 1023, kCFStringEncodingMacRoman);
                        
                        // xxxbobclark use a better way to figure out if it's really a bundle
                        
                        if (strstr(buf, ".bundle"))
                        {
                            bIsDir = false; // fake it because it's a bundle
                        }
                    }
                }
#endif
	} while (err == noErr && bIsDir);
	
	if (err == noErr)
	{
		// got a file; convert to a C-string and return a pointer
		
#ifdef _MAC_MACHO
                CHXCFString str(uniName);
                CFStringRef strR = str;
                char buf[1024];
                size_t bufSize = 1023;
                CFStringGetCString(strR, buf, bufSize, kCFStringEncodingMacRoman);
                CHXString strName(buf);
#else
                CHXString strName;
		
		strName.SetFromHFSUniStr255(uniName, CFStringGetSystemEncoding());
#endif
		
		m_pszOutFileName = new char[1 + strName.GetLength()];
		check_nonnull(m_pszOutFileName);
		
		if (m_pszOutFileName)
		{
			strcpy(m_pszOutFileName, (const char *) strName); /* Flawfinder: ignore */
		}
	}
	else
	{
		// no more found; return the nil pointer
	}
	
	return m_pszOutFileName;
}
Пример #11
0
int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks)
{
    OSStatus        result = -1;
    FSIterator      iterator;
    ItemCount       actualObjects;
    FSRef           rootDirectory;
    FSRef           ref;
    HFSUniStr255    nameStr;
    
    result = FSGetVolumeInfo (theVolume,
                              0,
                              NULL,
                              kFSVolInfoFSInfo,
                              NULL,
                              NULL,
                              &rootDirectory); 
                                 
    if (result != noErr) {
        SDL_SetError ("ListTrackFiles: FSGetVolumeInfo returned %d", result);
        return result;
    }

    result = FSOpenIterator (&rootDirectory, kFSIterateFlat, &iterator);
    if (result == noErr) {
        do
        {
            result = FSGetCatalogInfoBulk (iterator, 1, &actualObjects,
                                           NULL, kFSCatInfoNone, NULL, &ref, NULL, &nameStr);
            if (result == noErr) {
                
                CFStringRef  name;
                name = CFStringCreateWithCharacters (NULL, nameStr.unicode, nameStr.length);
                
                
                if (CFStringHasSuffix (name, CFSTR(".aiff")) ||
                    CFStringHasSuffix (name, CFSTR(".cdda"))) {
                    
                    
                    int trackID = 0, i = 0;
                    while (i < nameStr.length && !isdigit(nameStr.unicode[i])) {
                        ++i;
                    }
                    while (i < nameStr.length && isdigit(nameStr.unicode[i])) {
                        trackID = 10 * trackID +(nameStr.unicode[i] - '0');
                        ++i;
                    }

                    #if DEBUG_CDROM
                    printf("Found AIFF for track %d: '%s'\n", trackID, 
                    CFStringGetCStringPtr (name, CFStringGetSystemEncoding()));
                    #endif
                    
                    
                    trackID--;
                    
                    assert(0 <= trackID && trackID <= SDL_MAX_TRACKS);
                    
                    if (trackID < numTracks)
                        memcpy (&trackFiles[trackID], &ref, sizeof(FSRef));
                }
                CFRelease (name);
            }
        } while(noErr == result);
        FSCloseIterator (iterator);
    }
    
    return 0;
}