Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with CompositeIconRef



Agreed that making a finder DYNAMICALLY give a custom icon to a file or folder is no Rocket Science but i am unable to make out the mistake that is causing it not to work properly. I may be missing something really small. Can any one please help me?.
 
I have a contextual menu plugin (XYZ.plugin) located
at "/Library/Contextual Menu Items/". This
is invoked when the user right-clicks on a
file/folder. There are custom items in the contextual
menu. Depending on the selection i need to provide a
custom icon to  the file/folder.
In the Plugin Code i do something like this: I have a
file abc.txt to which I need to give a custom icon.
Now I get the IconRef of the file abc.txt and get the
IconRef of the "bsd.icns" [Icon file] file and form a
composite IconRef and apply this composite IconRef to
abc.txt file.
In my plugin i am forcing the finder to call my
overrided function -

SCFinderIconOverlayGetIconRefFromFileInfo when it
makes a call to  "GetIconRefFromFileInfo" by using
 
mach_override("_GetIconRefFromFileInfo", NULL,
   SCFinderIconOverlayGetIconRefFromFileInfo,
   (void**) &gGetIconRefFromFileInfo);
 
and the code for

SCFinderIconOverlayGetIconRefFromFileInfo is here:
static OSStatus
SCFinderIconOverlayGetIconRefFromFileInfo(
  const FSRef *            inRef,        UniCharCount
           inFileNameLength,     
 const UniChar *          inFileName,       
FSCatalogInfoBitmap      inWhichInfo,     
 const FSCatalogInfo *    inCatalogInfo,     
IconServicesUsageFlags   inUsageFlags,     
IconRef *                outIconRef,       
  SInt16 *                 outLabel)

 osStat = FSRefMakePath(inRef,szBuffer,MAX_PATH);
 osStat = FSPathMakeRef(szBuffer,&fsRef1,&bDir);

if(strcmp(szBuffer,"/Users/Username/Desktop/Finder_OverlayIcon/abc.txt")!=0)
 {
  printf("FILE NOT MATCHING RET DEFAULT\n");
  err = gGetIconRefFromFileInfo(inRef,
      inFileNameLength,
      inFileName,
      inWhichInfo,
      inCatalogInfo,
      inUsageFlags,
      outIconRef,
      outLabel);  
  
  return noErr;
 }
 
 
 osStat = FSGetCatalogInfo (&fsRef1,
      inWhichInfo,
      &fsInfo1,
      &hfsUni1,
      &fsSpec1,
      NULL);
 
 //finder info for incoming file
 finderInfo.fdCreator! = kUnknownType;
 finderInfo.fdType = kUnknownType;
 newErr = FSpGetFInfo( &fsSpec1, &finderInfo );
 
 //Incoming file's icon for background.
 err = gGetIconRefFromFileInfo(inRef,
     inFileNameLength,
     inFileName,
     inWhichInfo,
     inCatalogInfo,
     inUsageFlags,
     &backgroundIconRef,
     outLabel);
 //bsd.icns file's icon for foreground.
 osStat =
FSPathMakeRef("/Users/Username/Desktop/Finder_OverlayIcon/bsd.icns",&fsRef,&bDir);
 osStat = FSGetCatalogInfo (&fsRef,
      inWhichInfo,
      &fsInfo,
      &hfsUni,
      &fsSpec,
      NULL );
 //even using the finderInfo.fdtype &
finderInfo.fdCreator is not useful.
 newErr =
RegisterIconRefFromFSRef(kUnknownType,kUnknownType,&fsRef,&foregroundIconRef);
 
 //the composite of the foreground and the background
icons.
 newErr = CompositeIconRef(backgroundIconRef,
foregroundIconRef, &compositeIconRef);
 
 *outIconRef = compositeIconRef; //send the composite
as the icon to be displayed for the abc.txt file
  
 //decrement the reference count of back & foreground
Icons.
 //cleanup
    
    return noErr;
}
On testing, to my astonishment, all the files with
file extension ".txt" on ANY VOLUME have a composite Icon while only
abc.txt should have the composite and the rest of the
.txt files should have their original icon. What's wrong?
Pls note that in the
SCFinderIconOverlayGetIconRefFromFileInfo function of
the plugin, i return the original icon if the file is
not abc.txt.
When i log the results, for all other files other than
abc.txt the SCFinderIconOverlayGetIconRefFromFileInfo
returns the default icon and composite icon for
abc.txt correctly.But the finder display shows otherwise.
 
Also when i edit other files other than abc.txt they loose their composite Icon, when the original file abc.txt is edited, all of them get back the composite Icon.
Why is this? Is the approach completly wrong?
Kindly help.
 
Thanks.

Yahoo! India Matrimony: Find your life partner online.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.