Esempio n. 1
0
CFDataRef copyIconData(CFStringRef path)
{
	CFDataRef data = NULL;


	CFURLRef URL = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
																	              path,       // file path name
																	              kCFURLPOSIXPathStyle,    // interpret as POSIX path
																	              false );                 // is it a directory?
	

	if (URL) {
		FSRef ref;
		if (CFURLGetFSRef(URL, &ref)) {
			IconRef icon = NULL;
			SInt16 label_noOneCares;
			OSStatus err = GetIconRefFromFileInfo(&ref,
												  /*inFileNameLength*/ 0U, /*inFileName*/ NULL,
												  kFSCatInfoNone, /*inCatalogInfo*/ NULL,
												  kIconServicesNoBadgeFlag | kIconServicesUpdateIfNeededFlag,
												  &icon,
												  &label_noOneCares);

			if (err != noErr) {
				printf("Could not get icon\n");
			} else {
				IconFamilyHandle fam = NULL;
				// err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &fam);
				err = ReadIconFromFSRef(&ref, &fam);
				
				if (err != noErr) {
					printf("Could not get icon\n");
				} else {
					HLock((Handle)fam);
					data = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)*(Handle)fam, GetHandleSize((Handle)fam));
					HUnlock((Handle)fam);
					DisposeHandle((Handle)fam);
				}
				ReleaseIconRef(icon);
			}
		}
	}
	
	CFSafeRelease(URL);
	
	return data;
	
}
Esempio n. 2
0
static PyObject *Icn_ReadIconFromFSRef(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSStatus _err;
	FSRef ref;
	IconFamilyHandle iconFamily;
#ifndef ReadIconFromFSRef
	PyMac_PRECHECK(ReadIconFromFSRef);
#endif
	if (!PyArg_ParseTuple(_args, "O&",
	                      PyMac_GetFSRef, &ref))
		return NULL;
	_err = ReadIconFromFSRef(&ref,
	                         &iconFamily);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O&",
	                     ResObj_New, iconFamily);
	return _res;
}