home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / what's new? / sample code / human interface toolbox / packagetool / packageutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-02  |  2.6 KB  |  74 lines

  1. /*
  2.     file PackageUtils.c
  3.     
  4.     Description:
  5.     This file contains the package utility function IdentifyPackage that
  6.     package savy applications can use for identifying document packages.
  7.     
  8.     PackageTool is an application illustrating how to create application
  9.     packages in Mac OS 9.  It provides a simple interface for converting
  10.     correctly formatted folders into packages and vice versa.
  11.  
  12.     Copyright: © 1999 by Apple Computer, Inc.
  13.     all rights reserved.
  14.     
  15.     Disclaimer:
  16.     You may incorporate this sample code into your applications without
  17.     restriction, though the sample code has been provided "AS IS" and the
  18.     responsibility for its operation is 100% yours.  However, what you are
  19.     not permitted to do is to redistribute the source as "DSC Sample Code"
  20.     after having made changes. If you're going to re-distribute the source,
  21.     we require that you make it clear in the source that the code was
  22.     descended from Apple Sample Code, but that you've made changes.
  23.     
  24.     Change History (most recent first):
  25.     10/19/99 created
  26. */
  27.  
  28. #include "PackageUtils.h"
  29. #include <Aliases.h>
  30.  
  31. /* IdentifyPackage returns true if the file system object refered to
  32.     by *target refers to a package.  If it is a package, then 
  33.     *mainPackageFile is set to refer to the package's main file. */
  34. Boolean IdentifyPackage(FSSpec *target, FSSpec *mainPackageFile) {
  35.     CInfoPBRec cat;
  36.     OSErr err;
  37.     long packageFolderDirID;
  38.     Str255 name;
  39.     FSSpec aliasFile;
  40.     Boolean targetIsFolder, wasAliased;
  41.         /* check the target's flags */
  42.     cat.dirInfo.ioNamePtr = target->name;
  43.     cat.dirInfo.ioVRefNum = target->vRefNum;
  44.     cat.dirInfo.ioFDirIndex = 0;
  45.     cat.dirInfo.ioDrDirID = target->parID;
  46.     err = PBGetCatInfoSync(&cat);
  47.     if (err != noErr) return false;
  48.     if (((cat.dirInfo.ioFlAttrib & 16) != 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kHasBundle) != 0)) {
  49.             /* search for a top level alias file */
  50.         packageFolderDirID = cat.dirInfo.ioDrDirID;
  51.         cat.dirInfo.ioNamePtr = name;
  52.         cat.dirInfo.ioVRefNum = target->vRefNum;
  53.         cat.dirInfo.ioFDirIndex = 1;
  54.         cat.dirInfo.ioDrDirID = packageFolderDirID;
  55.             /* find the first alias file in the directory */
  56.         while (PBGetCatInfoSync(&cat) == noErr) {
  57.             if (((cat.dirInfo.ioFlAttrib & 16) == 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kIsAlias) != 0)) {
  58.                 err = FSMakeFSSpec(target->vRefNum, packageFolderDirID, name, &aliasFile);
  59.                 if (err != noErr) return false;
  60.                 err = ResolveAliasFile(&aliasFile, false, &targetIsFolder, &wasAliased);
  61.                 if (err != noErr) return false;
  62.                 if (mainPackageFile != NULL)
  63.                     *mainPackageFile = aliasFile;
  64.                 return true;
  65.             }
  66.             cat.dirInfo.ioFDirIndex++;
  67.             cat.dirInfo.ioDrDirID = packageFolderDirID;
  68.         }
  69.     }
  70.         /* no matching files found */
  71.     return false;
  72. }
  73.  
  74.