• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Temporary badging on Files and Folders.What is wrong in the code attached? - Part 1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Temporary badging on Files and Folders.What is wrong in the code attached? - Part 1


  • Subject: Temporary badging on Files and Folders.What is wrong in the code attached? - Part 1
  • From: Manish Pattath <email@hidden>
  • Date: Sat, 6 Nov 2004 11:42:44 +0000 (GMT)

Hi,
I want to temporarily apply badge on selected files and folders.
though i am successful in it,there are some hiccups.
 
1] If a badge is applied and then removed on a folder. Again try to apply badge on the same folder,it does not get applied.
 
I want the addition and removal of badges to be really smooth and the finder should update without relaunching it.
 
Can anyone please see the code below and tell me what wrong am i doing?
 
Any kind of help is appreciated.
 
Boolean AddBadgeToItem(char *path, char *icon ) 
{
    FSCatalogInfo info;
    FSRef pToFSRef;
    FSRef pToFSRef2;
    Boolean isDirectory = false;
 OSErr osErrResult = noErr;
 
 if (nil == path)
  return false;
 
   osErrResult = FSPathMakeRef(path,&pToFSRef,&isDirectory) ;
    if (icon && (osErrResult==noErr))
 {
  HFSUniStr255 fork;
        SInt16 refnum = kResFileNotOpened;
        osErrResult = FSGetResourceForkName(&fork);
  if(osErrResult != noErr)
   return false;
        if (isDirectory)
  {
      memset(&info,0,sizeof(info));
            ((FileInfo*)(&info.finderInfo))->finderFlags = kIsInvisible;
   osErrResult = FSCreateResourceFile(&pToFSRef,8,(UniChar*)"\000I\000c\000o\000n\000\r",kFSCatInfoFinderXInfo,&info,fork.length,fork.unicode,&pToFSRef2,NULL);      
        }
  else
  {
   BlockMoveData(&pToFSRef,&pToFSRef2,sizeof(FSRef));
   osErrResult = FSCreateResourceFork(&pToFSRef2,fork.length,fork.unicode,0);
   //here take care of condition !=noErr &
   //errFSForkExists -1421 An attempt to create a fork, but that fork already exists.
   //even with this function failing,FSOpenResourceFile succeeds!!,naturally:-))
   //so let it pass through.
        }
  
  osErrResult = FSOpenResourceFile(&pToFSRef2,fork.length,fork.unicode,fsRdWrPerm,&refnum);
  if (osErrResult!=noErr)
   return false;
  
  if (refnum!=kResFileNotOpened)
  {
   CustomBadgeResource* cbr;
   struct stat fs ;   
   stat ( icon, &fs ) ;
   int len = fs.st_size;
   
   char *bytes = malloc ( len ) ;
   FILE *fp = fopen ( icon, "rb" ) ;   
   fread ( bytes, sizeof (char), len, fp ) ;
   fclose ( fp ) ;   
   
   Handle h = NewHandle(len);
   if (h)
   {
    BlockMoveData(bytes,*h,len);
    AddResource(h,kIconFamilyType,128,"\p");
    WriteResource(h);
    ReleaseResource(h);
   }
   h = NewHandle(sizeof(CustomBadgeResource));
   if (h)
   {
    cbr = (CustomBadgeResource*)*h;
    memset(cbr,0,sizeof(CustomBadgeResource));
    cbr->version = kCustomBadgeResourceVersion;
    cbr->customBadgeResourceID = 128;
    AddResource(h,kCustomBadgeResourceType,kCustomBadgeResourceID,"\p");
    WriteResource(h);
    ReleaseResource(h);
   }
   
   UpdateResFile(refnum);
   CloseResFile(refnum);
   ! if (FSGetCatalogInfo(&pToFSRef,kFSCatInfoFinderXInfo,&info,NULL,NULL,NULL)==noErr)
   {
    ((ExtendedFileInfo*)(&info.extFinderInfo))->extendedFinderFlags = kExtendedFlagHasCustomBadge;
    FSSetCatalogInfo(&pToFSRef,kFSCatInfoFinderXInfo,&info);
   }
   MoreFEUpdateItemFSRef(&pToFSRef);
   return true;
  }
 }
    return false;
}
 
FSCreateResourceFile - returns -48 and FSOpenResourceFile - returns
-35. Why is this? Am i not removing the badge correctly that it is not allwoing the re - applying of badge?
 
The Removal Part of the code is in Part II of the mail.
 
 
 

Yahoo! India Matrimony: Find your life partner online.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Temporary badging on Files and Folders.What is wrong in the code attached? - Part 1
      • From: Frederick Cheung <email@hidden>
  • Prev by Date: Outline View Loading Data
  • Next by Date: Part II - Temporary badging on Files and Folders.What is wrong in the code attached?
  • Previous by thread: Re: Outline View Loading Data
  • Next by thread: Re: Temporary badging on Files and Folders.What is wrong in the code attached? - Part 1
  • Index(es):
    • Date
    • Thread