int GetCurrentModulePath(char* lpModulePath, const int iPathMax) { if(lpModulePath == NULL || iPathMax <= 0) { return -1; } memset(lpModulePath, 0, iPathMax); char cCurrentPath[PATH_MAX]; memset(cCurrentPath, 0, PATH_MAX); Dl_info dlInfo; static int sDummy; dladdr((void*)&sDummy, &dlInfo); strlcpy(cCurrentPath, dlInfo.dli_fname, PATH_MAX); #if defined(__apple__) // whether is self a framework ? int locateNumber = 1; struct FSRef currentPath; OSStatus iStatus = FSPathMakeRef((unsigned char*)cCurrentPath, ¤tPath, NULL); if(noErr == iStatus) { LSItemInfoRecord info; iStatus = LSCopyItemInfoForRef(¤tPath, kLSRequestExtension, &info); if(noErr == iStatus && NULL == info.extension) { locateNumber = 4; } } #else int locateNumber = 1; #endif std::string strPath(cCurrentPath); int pos = std::string::npos; for(int i = 0; i < locateNumber; i++) { pos = strPath.rfind('/'); if(std::string::npos == pos) { break; } strPath.erase(pos); } if(std::string::npos == pos) { return -2; } cCurrentPath[pos] = 0; strlcpy(lpModulePath, cCurrentPath, iPathMax); strlcat(lpModulePath, "/", iPathMax); return 0; }
UInt32 HLFileSystemObject::GetCreator() const { // get the file creator from Launch Services LSItemInfoRecord theInfo; OSStatus theError = LSCopyItemInfoForRef(&mFSRef, kLSRequestTypeCreator, &theInfo); ThrowIfError(theError, CAException(theError), "HLFileSystemObject::SetName: couldn't rename the file"); return theInfo.creator; }
pascal Boolean CrossPlatformFilterCallback( AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode ) { OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ; if (filterMode == kNavFilteringBrowserList) { // We allow navigation to all folders. For files, we check against the current // filter string. // However, packages should be dealt with like files and not like folders. So // check if a folder is a package before deciding what to do. NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ; FSRef fsref; if ( theInfo->isFolder ) { // check bundle bit (using Finder Services - used by OS9 on some bundles) FSCatalogInfo catalogInfo; if (FSGetCatalogInfo (&fsref, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL) != noErr) return true; // Check bundle item (using Launch Services - used by OS-X through info.plist or APP) LSItemInfoRecord lsInfo; if (LSCopyItemInfoForRef(&fsref, kLSRequestBasicFlagsOnly, &lsInfo ) != noErr) return true; // If it's not a bundle, then it's a normal folder and it passes our filter FileInfo *fileInfo = (FileInfo *) catalogInfo.finderInfo; if ( !(fileInfo->finderFlags & kHasBundle) && !(lsInfo.flags & (kLSItemInfoIsApplication | kLSItemInfoIsPackage)) ) return true; } else { AECoerceDesc (theItem, typeFSRef, theItem); if ( AEGetDescData (theItem, &fsref, sizeof (FSRef)) == noErr) { wxString file = wxMacFSRefToPath( &fsref ) ; return CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; } } } return true; }
static PyObject *Launch_LSCopyItemInfoForRef(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; FSRef inItemRef; LSRequestedInfo inWhichInfo; LSItemInfoRecord outItemInfo; if (!PyArg_ParseTuple(_args, "O&l", PyMac_GetFSRef, &inItemRef, &inWhichInfo)) return NULL; _err = LSCopyItemInfoForRef(&inItemRef, inWhichInfo, &outItemInfo); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&", LSItemInfoRecord_New, &outItemInfo); return _res; }
//////////////////////////////////////// // Print whether the file is set to show // its suffix in the filename ////////////////////////////////////// static OSErr PrintIsExtensionHidden (FSRef *fileRef) { LSItemInfoRecord infoRecord; OSErr err = noErr; err = LSCopyItemInfoForRef(fileRef, kLSRequestExtensionFlagsOnly, &infoRecord); if (err) { fprintf(stderr, "Error %d in LSCopyItemInfoForRef()\n", err); return err; } if (infoRecord.flags & kLSItemInfoExtensionIsHidden) printf("Yes\n"); else printf("No\n"); return err; }
Boolean LLFilePicker::navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode) { Boolean result = true; ELoadFilter filter = *((ELoadFilter*) callBackUD); OSStatus error = noErr; if (filterMode == kNavFilteringBrowserList && filter != FFLOAD_ALL && (theItem->descriptorType == typeFSRef || theItem->descriptorType == typeFSS)) { // navInfo is only valid for typeFSRef and typeFSS NavFileOrFolderInfo *navInfo = (NavFileOrFolderInfo*) info; if (!navInfo->isFolder) { AEDesc desc; error = AECoerceDesc(theItem, typeFSRef, &desc); if (error == noErr) { FSRef fileRef; error = AEGetDescData(&desc, &fileRef, sizeof(fileRef)); if (error == noErr) { LSItemInfoRecord fileInfo; error = LSCopyItemInfoForRef(&fileRef, kLSRequestExtension | kLSRequestTypeCreator, &fileInfo); if (error == noErr) { if (filter == FFLOAD_IMAGE) { if (fileInfo.filetype != 'JPEG' && fileInfo.filetype != 'JPG ' && fileInfo.filetype != 'BMP ' && fileInfo.filetype != 'TGA ' && fileInfo.filetype != 'BMPf' && fileInfo.filetype != 'TPIC' && fileInfo.filetype != 'PNG ' && (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("jpeg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(fileInfo.extension, CFSTR("jpg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(fileInfo.extension, CFSTR("bmp"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(fileInfo.extension, CFSTR("tga"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(fileInfo.extension, CFSTR("png"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) { result = false; } } else if (filter == FFLOAD_WAV) { if (fileInfo.filetype != 'WAVE' && fileInfo.filetype != 'WAV ' && (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("wave"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && CFStringCompare(fileInfo.extension, CFSTR("wav"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) { result = false; } } else if (filter == FFLOAD_ANIM) { if (fileInfo.filetype != 'BVH ' && (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("bvh"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) { result = false; } } #ifdef _CORY_TESTING else if (filter == FFLOAD_GEOMETRY) { if (fileInfo.filetype != 'SLG ' && (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("slg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) { result = false; } } #endif else if (filter == FFLOAD_SLOBJECT) { llwarns << "*** navOpenFilterProc: FFLOAD_SLOBJECT NOT IMPLEMENTED ***" << llendl; } else if (filter == FFLOAD_RAW) { if (fileInfo.filetype != '\?\?\?\?' && (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("raw"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) { result = false; } } if (fileInfo.extension) { CFRelease(fileInfo.extension); } } } AEDisposeDesc(&desc); } } } return result; }