home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / tarsrc.sit / dir.c < prev    next >
Text File  |  1989-09-14  |  2KB  |  82 lines

  1. /*
  2.  * Macintosh Tar
  3.  *
  4.  * dir.c - routines dealing with directory selection
  5.  *
  6.  * Written by Craig Ruff
  7.  */
  8.  
  9. #include "tar.h"
  10.  
  11. #define ROOTDIR        2        /* WATCH OUT!  Subject to change? */
  12.  
  13. #define dirID        130        /* Directory selection dialog */
  14.  
  15. short        dirVRefNum;        /* Selected directory VRefNum */
  16. long        dirDirID;        /* Selected directory DirID */
  17.  
  18. /*
  19.  * GetDir - manage the directory selection dialog
  20.  */
  21. Boolean
  22. GetDir(text, extract)
  23. char    *text;
  24. Boolean    extract;
  25. {
  26.     Point        where;
  27.     SFReply        reply;
  28.     WDPBRec        wdpb;
  29.     HParamBlockRec    volpb;
  30.     Str255        name;
  31.     char        *routine = "\pGetDir";
  32.  
  33.     name[0] = 1;
  34.     name[1] = 'x';
  35.     where.h = where.v = 75;
  36.     SFPPutFile(where, text, name, nil, &reply, dirID, nil);
  37.     if (!reply.good)
  38.         return(false);
  39.  
  40.     name[0] = 0;
  41.     volpb.volumeParam.ioCompletion = nil;
  42.     volpb.volumeParam.ioNamePtr = name;
  43.     volpb.volumeParam.ioVRefNum = reply.vRefNum;
  44.     volpb.volumeParam.ioVolIndex = 0;
  45.     PBHGetVInfo(&volpb, false);
  46.     if (volpb.volumeParam.ioResult != noErr) {
  47.         OSAlert(routine, "\pPBHGetVInfo", name,
  48.                 volpb.volumeParam.ioResult);
  49.         return(false);
  50.     }
  51.  
  52.     if (volpb.volumeParam.ioVSigWord != 0x4244) {
  53.         HFSAlert();
  54.         return(false);
  55.     }
  56.     
  57.     if (extract) {
  58.         /*
  59.          * If we are extracting, we only need a working
  60.          * directory vRefNum.  The SFPPutFile dialog
  61.          * provides this for us.
  62.          */
  63.         dirVRefNum = reply.vRefNum;
  64.     
  65.     } else {
  66.         wdpb.ioCompletion = nil;
  67.         wdpb.ioVRefNum = reply.vRefNum;
  68.         wdpb.ioWDIndex = 0;
  69.         wdpb.ioWDProcID = 0;
  70.         wdpb.ioWDVRefNum = 0;
  71.         if (PBGetWDInfo(&wdpb, false) != noErr) {
  72.             OSAlert("\pGetDir", "\pPBGetWDInfo", nil, wdpb.ioResult);
  73.             return(false);
  74.         }
  75.         
  76.         dirDirID = wdpb.ioWDDirID;
  77.         dirVRefNum = wdpb.ioWDVRefNum;
  78.     }
  79.     
  80.     return(true);
  81. }
  82.