home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / Get_custom_file_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  2.5 KB  |  84 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: Get_custom_file_icon.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21.  
  22. #include <Finder.h>
  23. #include <Icons.h>
  24. #include <Resources.h>
  25. #include <Errors.h>
  26. #include "Get_custom_file_icon.h"
  27. #include "cheap-exceptions.h"
  28. #include "Copy_each_icon.h"
  29. #include "Get_resource_icons.h"
  30.  
  31. /*    ------------------------------------------------------------------
  32.     Get_custom_file_icon        Fill a suite with the custom icon of a
  33.                                 specified file.
  34.     ------------------------------------------------------------------
  35. */
  36. /*
  37.     Custom icons numbered -16496 appear in aliases to volumes and
  38.     servers.  I don't know where this is documented.
  39. */
  40. #define    kVolumeAliasIconResource    -16496
  41.  
  42. OSErr    Get_custom_file_icon(
  43. /* --> */    const FSSpec    *filespec,
  44. /* --> */    MetaSelectorValue    icon_selector,
  45. /* <-- */    Handle    *the_suite
  46. )
  47. {
  48.     short    save_resfile, custom_resfile;
  49.     IconSelectorValue    second_selector;
  50.     OSErr    err;
  51.     
  52.     ExpandMetaSelector( icon_selector, &icon_selector, &second_selector );
  53.  
  54.     save_resfile = CurResFile();
  55.     SetResLoad( false );
  56.     custom_resfile = FSpOpenResFile( filespec, fsRdPerm );
  57.     SetResLoad( true );
  58.     forbid_action( custom_resfile == -1, FSpOpenResFile,
  59.         err = ResError() );
  60.     
  61.     err = Get1_resource_icons( the_suite, kCustomIconResource, icon_selector );
  62.     if ( (*the_suite == NULL) && (second_selector != 0) )
  63.     {
  64.         err = Get1_resource_icons( the_suite, kCustomIconResource,
  65.             second_selector );
  66.     }
  67.  
  68.     if (err == noMaskFoundErr)
  69.     {
  70.         err = Get1_resource_icons( the_suite, kVolumeAliasIconResource,
  71.             icon_selector );
  72.         if ( (*the_suite == NULL) && (second_selector != 0) )
  73.         {
  74.             err = Get1_resource_icons( the_suite, kVolumeAliasIconResource,
  75.                 second_selector );
  76.         }
  77.     }
  78.     
  79.     CloseResFile( custom_resfile );
  80.     UseResFile( save_resfile );
  81. FSpOpenResFile:
  82.     return err;
  83. }
  84.