static PyObject * MacOS_SetCreatorAndType(PyObject *self, PyObject *args) { Str255 name; ResType creator, type; FInfo info; OSErr err; if (!PyArg_ParseTuple(args, "O&O&O&", PyMac_GetStr255, &name, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) return NULL; if ((err = GetFInfo(name, 0, &info)) != noErr) return PyErr_Mac(MacOS_Error, err); info.fdCreator = creator; info.fdType = type; if ((err = SetFInfo(name, 0, &info)) != noErr) return PyErr_Mac(MacOS_Error, err); Py_INCREF(Py_None); return Py_None; }
static PyObject * MacOS_GetCreatorAndType(PyObject *self, PyObject *args) { Str255 name; FInfo info; PyObject *creator, *type, *res; OSErr err; if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, &name)) return NULL; if ((err = GetFInfo(name, 0, &info)) != noErr) return PyErr_Mac(MacOS_Error, err); creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4); type = PyString_FromStringAndSize((char *)&info.fdType, 4); res = Py_BuildValue("OO", creator, type); Py_DECREF(creator); Py_DECREF(type); return res; }
static PyObject * MacOS_SetCreatorAndType(PyObject *self, PyObject *args) { ResType creator, type; FSRef ref; FileInfo* finfo; OSErr err; FSCatalogInfo cataloginfo; if (!PyArg_ParseTuple(args, "O&O&O&", PyMac_GetFSRef, &ref, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) { #ifndef __LP64__ /* Try to handle FSSpec arguments, for backward compatibility */ FSSpec fss; FInfo info; if (!PyArg_ParseTuple(args, "O&O&O&", PyMac_GetFSSpec, &fss, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) return NULL; if ((err = FSpGetFInfo(&fss, &info)) != noErr) return PyErr_Mac(MacOS_Error, err); info.fdCreator = creator; info.fdType = type; if ((err = FSpSetFInfo(&fss, &info)) != noErr) return PyErr_Mac(MacOS_Error, err); Py_INCREF(Py_None); return Py_None; #else /* __LP64__ */ return NULL; #endif /* __LP64__ */ } err = FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo, NULL, NULL, NULL); if (err != noErr) { PyErr_Mac(MacOS_Error, err); return NULL; } if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) { /* Directory: doesn't have type/creator info. * * The specific error code is for backward compatibility with * earlier versions. */ PyErr_Mac(MacOS_Error, fnfErr); return NULL; } finfo = (FileInfo*)&(cataloginfo.finderInfo); finfo->fileCreator = creator; finfo->fileType = type; err = FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &cataloginfo); if (err != noErr) { PyErr_Mac(MacOS_Error, fnfErr); return NULL; } Py_INCREF(Py_None); return Py_None; }
static PyObject * MacOS_GetCreatorAndType(PyObject *self, PyObject *args) { PyObject *creator, *type, *res; OSErr err; FSRef ref; FSCatalogInfo cataloginfo; FileInfo* finfo; if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref)) { #ifndef __LP64__ /* This function is documented to take an FSSpec as well, * which only works in 32-bit mode. */ PyErr_Clear(); FSSpec fss; FInfo info; if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) return NULL; if ((err = FSpGetFInfo(&fss, &info)) != noErr) { return PyErr_Mac(MacOS_Error, err); } creator = PyString_FromStringAndSize( (char *)&info.fdCreator, 4); type = PyString_FromStringAndSize((char *)&info.fdType, 4); res = Py_BuildValue("OO", creator, type); Py_DECREF(creator); Py_DECREF(type); return res; #else /* __LP64__ */ return NULL; #endif /* __LP64__ */ } err = FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo, NULL, NULL, NULL); if (err != noErr) { PyErr_Mac(MacOS_Error, err); return NULL; } if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) { /* Directory: doesn't have type/creator info. * * The specific error code is for backward compatibility with * earlier versions. */ PyErr_Mac(MacOS_Error, fnfErr); return NULL; } finfo = (FileInfo*)&(cataloginfo.finderInfo); creator = PyString_FromStringAndSize((char*)&(finfo->fileCreator), 4); type = PyString_FromStringAndSize((char*)&(finfo->fileType), 4); res = Py_BuildValue("OO", creator, type); Py_DECREF(creator); Py_DECREF(type); return res; }