コード例 #1
0
ファイル: osx.cpp プロジェクト: r0ssar00/platform
int SetFileComment(std::string spath, std::string scomment) {
	const char *path = spath.c_str();
	const char *comment = scomment.c_str();
	OSErr err = noErr;
	FSRef fileRef;
	FSSpec fileSpec;

	// see if the file in question exists and we can write it
	if (access(path, R_OK | W_OK | F_OK) == - 1) {
		return 1;
	}

	// get file reference from path
	err = FSPathMakeRef( (const UInt8 *) path, &fileRef, NULL);
	if (err != noErr) {
		return 1;
	}

	// retrieve filespec from file ref
	err = FSGetCatalogInfo(&fileRef, NULL, NULL, NULL, &fileSpec, NULL);
	if (err != noErr) {
		return 1;
	}
	// being by setting MacOS X Finder Comment
	Str255 pCommentStr;
	CopyCStringToPascal(comment, pCommentStr);
	err = MoreFESetComment(&fileSpec, pCommentStr, NULL);
	if (err != noErr) {
		return 1;
	}
	return 0;
}
コード例 #2
0
ファイル: setfcomment.c プロジェクト: Airr/osxutils
///////////////////////////////////////////////////////////////////
// We set the MacOS X Finder comment by sending an Apple Event to
// the Finder.  As far as I know, there is no other way.
// This will fail if the Finder isn't running....:(
///////////////////////////////////////////////////////////////////
static OSErr OSX_SetComment (FSRef *fileRef, FSSpec *fileSpec, char *comment)
{
    OSErr	err = noErr;
    Str255	pCommentStr;

    if (strlen(comment) > MAX_COMMENT_LENGTH)
        return true;

    // make a pascal string
    strncpy((char*)pCommentStr + 1, comment, 255);
    int len = strlen(comment);
    if (len > 255)
        len = 255;
    pCommentStr[0] = len;

    err = MoreFESetComment(fileRef, fileSpec, pCommentStr, NULL);
    
    return(err);
}