boolean setfilecomment (FSSpec *pfs, bigstring bscomment) { DTPBRec dt; clearbytes (&dt, longsizeof (dt)); if (!hasdesktopmanager ((*pfs).vRefNum)) return (false); dt.ioVRefNum = (*pfs).vRefNum; if (PBDTGetPath (&dt) != noErr) return (false); dt.ioNamePtr = (*pfs).name; dt.ioDirID = (*pfs).parID; dt.ioDTBuffer = (Ptr) bscomment + 1; dt.ioDTReqCount = stringlength (bscomment); if (PBDTSetCommentSync (&dt) != noErr) return (false); PBDTFlushSync (&dt); return (true); } /*setfilecomment*/
boolean getfilecomment (FSSpec *pfs, bigstring bscomment) { DTPBRec dt; clearbytes (&dt, longsizeof (dt)); setemptystring (bscomment); /*default return*/ if (!hasdesktopmanager ((*pfs).vRefNum)) return (false); dt.ioVRefNum = (*pfs).vRefNum; if (PBDTGetPath (&dt) != noErr) return (false); dt.ioNamePtr = (*pfs).name; dt.ioDirID = (*pfs).parID; dt.ioDTBuffer = (Ptr) bscomment + 1; dt.ioDTReqCount = lenbigstring; if (PBDTGetCommentSync (&dt) != noErr) return (false); setstringlength (bscomment, dt.ioDTActCount); return (true); } /*getfilecomment*/
/////////////////////////////////////////////////////////////////// // We set the MacOS 9 Finder comment using the File Manager API's // Desktop Database functions. /////////////////////////////////////////////////////////////////// static OSErr OS9_SetComment (FSSpec *fileSpec, char *comment, bool *unsupported) { #if !__LP64__ OSErr err = noErr; DTPBRec dt; dt.ioVRefNum = (*fileSpec).vRefNum; err = PBDTGetPath(&dt); if (err != noErr) { *unsupported = true; return err; } //fill in the relevant fields (using parameters) dt.ioNamePtr = (*fileSpec).name; dt.ioDirID = (*fileSpec).parID; dt.ioDTBuffer = comment; dt.ioDTReqCount = strlen(comment); if (PBDTSetCommentSync (&dt) != noErr) return (err); err = PBDTSetCommentSync(&dt); if (err != noErr) return err; err = PBDTFlushSync (&dt); #endif return (noErr); }
boolean findapplication (short vnum, OSType creator, boolean flappsonly, FSSpec *pfs) { /* dmb 9/21/93: keep looping until an APPL is found, or PBDTGetAPPLSync returns an error. (it will eventually return afpItemNotFound.) dmb 9/24/93: added flappsonly parameter. a non-app, such as an extension or desk accessory, can own a document type. */ DTPBRec dt; bigstring appname; tyfileinfo info; if (!hasdesktopmanager (vnum)) return (false); clearbytes (&dt, longsizeof (dt)); dt.ioVRefNum = vnum; if (PBDTGetPath (&dt) != noErr) return (false); dt.ioNamePtr = (StringPtr) &appname; dt.ioFileCreator = creator; for (dt.ioIndex = 0; ; ++dt.ioIndex) { if (PBDTGetAPPLSync (&dt) != noErr) return (false); if (!filemakespec (vnum, dt.ioAPPLParID, appname, pfs)) continue; if (!fileexists (pfs)) continue; if (!filegetinfo (pfs, &info)) continue; if (!flappsonly) /*dmb 9/24/93: some callers don't require apps*/ return (true); if (info.filetype == 'APPL') /*DW 9/16/93: desktop db can contain references to non-apps*/ return (true); } } /*findapplication*/
boolean findapponanydisk (OSType appid, FSSpec *fs) { /* find the app whose creator id is appid. return true if we found it, false otherwise. */ DTPBRec dt; ParamBlockRec pb; Str255 appfname; clearbytes (&pb, (long) sizeof (pb)); while (true) { ++pb.volumeParam.ioVolIndex; if (PBGetVInfoSync (&pb) != noErr) return (false); if (!hasdesktopmanager (pb.volumeParam.ioVRefNum)) continue; dt.ioNamePtr = NULL; dt.ioVRefNum = pb.volumeParam.ioVRefNum; if (PBDTGetPath (&dt) != noErr) return (false); dt.ioNamePtr = (StringPtr) &appfname; dt.ioIndex = 0; dt.ioFileCreator = appid; if (PBDTGetAPPLSync (&dt) == noErr) { if (FSMakeFSSpec (pb.volumeParam.ioVRefNum, dt.ioAPPLParID, appfname, fs) == noErr) return (true); } } /*while*/ return (false); } /*findapponanydisk*/
pascal OSErr DTOpen(ConstStr255Param volName, short vRefNum, short *dtRefNum, Boolean *newDTDatabase) { OSErr error; GetVolParmsInfoBuffer volParmsInfo; long infoSize; DTPBRec pb; /* Check for volume Desktop Manager support before calling */ infoSize = sizeof(GetVolParmsInfoBuffer); error = HGetVolParms(volName, vRefNum, &volParmsInfo, &infoSize); if ( error == noErr ) { if ( hasDesktopMgr(&volParmsInfo) ) { pb.ioNamePtr = (StringPtr)volName; pb.ioVRefNum = vRefNum; error = PBDTOpenInform(&pb); /* PBDTOpenInform informs us if the desktop was just created */ /* by leaving the low bit of ioTagInfo clear (0) */ *newDTDatabase = ((pb.ioTagInfo & 1L) == 0); if ( error == paramErr ) { error = PBDTGetPath(&pb); /* PBDTGetPath doesn't tell us if the database is new */ /* so assume it is not new */ *newDTDatabase = false; } *dtRefNum = pb.ioDTRefNum; } else { error = paramErr; } } return ( error ); }
static void PrintFileComment (char *path) { #if !__LP64__ OSErr err = noErr; FSRef fileRef; FSSpec fileSpec; DTPBRec dt; char buf[255] = "\0"; char comment[255] = "\0"; //see if the file in question exists and we can write it if (access(path, R_OK|F_OK) == -1) { perror(path); return; } //get file reference from path err = FSPathMakeRef(path, &fileRef, NULL); if (err != noErr) { fprintf(stderr, "FSPathMakeRef: Error %d for file %s\n", err, path); return; } //retrieve filespec from file ref err = FSGetCatalogInfo (&fileRef, NULL, NULL, NULL, &fileSpec, NULL); if (err != noErr) { fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec for %s\n", err, path); return; } ///////////// oK, now we can go about getting the comment ///////////// dt.ioVRefNum = fileSpec.vRefNum; err = PBDTGetPath(&dt); if (err != noErr) { fprintf(stderr, "Can't get OS 9 comments for %s\n", path); return; } //fill in the relevant fields (using parameters) dt.ioNamePtr = fileSpec.name; dt.ioDirID = fileSpec.parID; dt.ioDTBuffer = (char *)&buf; PBDTGetCommentSync(&dt); if (dt.ioDTActCount != 0) //if zero, that means no comment { strncpy((char *)&comment, (char *)&buf, dt.ioDTActCount); if (!printFileName) printf("%s\n", (char *)&comment); else printf("Comment for '%s':\n%s\n", path, (char *)&comment); } return; #endif }