1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| FSRef fs_rep;
FSIterator fs_it;
if (FSPathMakeRef((uchar*)sequence->getRepertoire(), &fs_rep, 0) == fnfErr)
{
fprintf(stderr,"Repertoire non trouve %s\n",sequence->getRepertoire());
return;
}
if (FSOpenIterator(&fs_rep, kFSIterateFlat, &fs_it))
{
fprintf(stderr,"Iterateur non valide %s\n",sequence->getRepertoire());
return;
}
CFStringRef str;
char nom_seq_unicode[256];
str = CFStringCreateWithCString(NULL, sequence->getNom(), kCFStringEncodingMacRoman);
CFStringGetCString( str, nom_seq_unicode, 256, kCFStringEncodingUnicode ); // Get the unicode string
FSSearchParams criteres_recherche;
FSCatalogInfo searchInfo1;
FSCatalogInfo searchInfo2;
//
// Initialize the searchCriteria, the searchInfo1 and the searchInfo2 records.
// These tell FSCatalogSearch what to find.
//
criteres_recherche.searchTime = 0; // timeout as used by a Time Manager task, or 0 for no timeout
criteres_recherche.searchBits = fsSBPartialName + fsSBFlAttrib; // fields to look at in searchInfo1 and searchInfo2 structs
criteres_recherche.searchName = (UniChar*)nom_seq_unicode;
criteres_recherche.searchNameLength = CFStringGetLength(str);
criteres_recherche.searchInfo1 = &searchInfo1; // the catalog info to match
criteres_recherche.searchInfo2 = &searchInfo2; // the catalog info mask
// only match files (not directories)
searchInfo1.nodeFlags = 0; // kFSNodeIsDirectoryBit set to 0 for files
searchInfo2.nodeFlags = kFSNodeIsDirectoryMask; // check only this nodeFlag bit
// search for this fileType
// ((FileInfo *)&searchInfo1.finderInfo)->fileType = 'TGA'; // AppleWorks WP files
// ((FileInfo *)&searchInfo2.finderInfo)->fileType = (OSType)0xffffffff;
// search for this fileCreator
// ((FileInfo *)&searchInfo1.finderInfo)->fileCreator = 'BOBO'; // AppleWorks
// ((FileInfo *)&searchInfo2.finderInfo)->fileCreator = (OSType)0xffffffff;
// find only visible files
((FileInfo *)&searchInfo1.finderInfo)->finderFlags = 0;
((FileInfo *)&searchInfo2.finderInfo)->finderFlags = kIsInvisible;
// zero all other FileInfo fields
((FileInfo *)&searchInfo1.finderInfo)->location.v = 0;
((FileInfo *)&searchInfo1.finderInfo)->location.h = 0;
((FileInfo *)&searchInfo1.finderInfo)->reservedField = 0;
((FileInfo *)&searchInfo2.finderInfo)->location.v = 0;
((FileInfo *)&searchInfo2.finderInfo)->location.h = 0;
((FileInfo *)&searchInfo2.finderInfo)->reservedField = 0;
// nombre de fichiers trouves (1 ou 0)
ulong nb_trouve;
FSRef fs_image;
HFSUniStr255 nom_image;
OSErr err;
err = FSCatalogSearch( fs_it, &criteres_recherche, 1, &nb_trouve, 0, kFSCatInfoNone, 0, &fs_image, 0, &nom_image);
while ( !err )
{
CFStringRef str = CFStringCreateWithCharacters( kCFAllocatorDefault,
nom_image.unicode, nom_image.length );
char* output = NewPtr(CFStringGetLength(str)+1);
// check output for NULL
CFStringGetCString(str, output, CFStringGetLength(str)+1, kCFStringEncodingMacRoman);
CFRelease( str );
fprintf(stderr,"%s\n",output);
// TODO
delete output;
err = FSCatalogSearch( fs_it, &criteres_recherche, 1, &nb_trouve, 0, kFSCatInfoNone, 0, &fs_image, 0, &nom_image);
}
fprintf(stderr, "sortie : %d \n", err); |
Partager