home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------------------------------------
- Find_icon, code for constructing icon suites for files and folders
-
- by James W. Walker
- preferred e-mail: <mailto:jwwalker@kagi.com>
- alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
- web: <http://users.aol.com/jwwalker/>
-
- File: Get_volume_icon.c
-
- Copyright ©1997 by James W. Walker
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours.
- If you're going to re-distribute the source, please make it clear
- that the code was descended from James W. Walker's code,
- but that you've made changes.
- ---------------------------------------------------------------------------------------------
- */
-
- #include <Icons.h>
- #ifndef __FILES__
- #include <Files.h>
- #endif
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #include "Get_volume_icon.h"
- #include "cheap-exceptions.h"
- #include "Get_resource_icons.h"
- #include "Copy_each_icon.h"
-
- /* ------------------------------------------------------------------
- Get_volume_icon Create an icon suite for a volume,
- assuming that it does not have a custom
- icon.
- ------------------------------------------------------------------
- */
- OSErr Get_volume_icon(
- /* --> */ short vRefNum,
- /* <-- */ Handle *the_suite
- )
- {
- OSErr err;
- HParamBlockRec pb;
- ParamBlockRec cpb;
- Handle iconHandle;
- short save_resfile;
- Ptr *drive_icon;
-
- pb.volumeParam.ioNamePtr = NULL;
- pb.volumeParam.ioVRefNum = vRefNum;
- pb.volumeParam.ioVolIndex = 0;
-
- err = PBHGetVInfoSync(&pb);
- forbid( err, PBHGetVInfoSync );
-
- // set up for Control call
- cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum;
- cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo;
- drive_icon = (Ptr *) &cpb.cntrlParam.csParam;
- *drive_icon = NULL;
-
- // Warning: Under A/UX 3.0, the csCode = 22 call can fail
- // without returning an error code.
- // try media icon
- cpb.cntrlParam.csCode = 22;
- err = PBControlSync( &cpb );
-
- if ( (err != noErr) || ((long)*drive_icon <= 0) )
- {
- // try physical drive icon;
- cpb.cntrlParam.csCode = 21;
- err = PBControlSync( &cpb );
- }
-
- if ( (err == noErr) && (0 < (long)*drive_icon) ) // we got an icon
- {
- err = NewIconSuite( the_suite ); // create the new suite
- forbid( err, NewIconSuite );
-
- err = PtrToHand( *drive_icon, &iconHandle, kLargeIconSize );
- forbid( err, PtrToHand );
-
- err = AddIconToSuite(iconHandle, *the_suite, large1BitMask);
- }
- else // maybe it's a Mac Plus floppy drive; see Tech Note DV 17
- {
- save_resfile = CurResFile();
- UseResFile(0); // we want a System resource
- err = Get1_resource_icons( the_suite, kFloppyIconResource,
- kSelectorAllAvailableData );
- UseResFile( save_resfile );
- }
-
- PtrToHand:
- NewIconSuite:
- PBHGetVInfoSync:
- return err;
- }
-