home *** CD-ROM | disk | FTP | other *** search
- /*
- * Macintosh Tar
- *
- * dir.c - routines dealing with directory selection
- *
- * NOTE: I think the worst thing lacking is a SFGetDirectory dialog.
- * It isn't clear at all what is valid in the reply structure
- * if an open is faked. I don't vouch for this code, but it
- * seems to work.
- *
- * Written by Craig Ruff
- */
-
- #include "tar.h"
- #include <SysEqu.h>
-
- #define ROOTDIR 2 /* WATCH OUT! Subject to change? */
-
- #define dirID 130 /* Directory selection dialog */
- #define selectItem 11 /* Select directory button */
-
- WDPBRec wdpb;
- Boolean dirSelected; /* True if 'Select' button used, next two vars set */
- short dirVRefNum; /* Selected directory VRefNum */
- long dirDirID; /* Selected directory DirID */
-
- pascal short
- DialogHook(item, theDialog)
- short item;
- DialogPtr theDialog;
- {
- #pragma unused(theDialog)
-
- switch (item) {
- case selectItem:
- dirSelected = true;
- item = getOpen;
- /* fall through */
-
- case getOpen:
- /*
- * Kludge! Access low memory.
- * This should be supplied in
- * the reply structure!!
- */
- dirVRefNum = -*(short *) SFSaveDisk;
- dirDirID = *(int *) CurDirStore;
- break;
- }
-
- return(item);
- }
-
- /*
- * GetDir - manage the directory selection dialog
- */
- Boolean
- GetDir(prompt, extract)
- char *prompt;
- Boolean extract;
- {
- Point where;
- SFReply reply;
- HParamBlockRec volpb;
- char *routine = "\pGetDir";
-
- where.h = where.v = 75;
- dirSelected = false;
- SFPGetFile(where, prompt, nil, -1, nil, DialogHook, &reply, dirID, nil);
- if (!reply.good)
- return(false);
-
- /*
- * Make sure the volume we are dealing with is a HFS volume.
- */
- volpb.volumeParam.ioCompletion = nil;
- volpb.volumeParam.ioNamePtr = nil;
- volpb.volumeParam.ioVRefNum = dirVRefNum;
- volpb.volumeParam.ioVolIndex = 0;
- PBHGetVInfo(&volpb, false);
- if (volpb.volumeParam.ioResult != noErr) {
- OSAlert(routine, "\pPBHGetVInfo", nil,
- volpb.volumeParam.ioResult);
- return(false);
- }
-
- if (volpb.volumeParam.ioVSigWord != 0x4244) {
- HFSAlert();
- return(false);
- }
-
- /*
- * For creation, rely on SFPGetFile providing the directory's VRefNum
- * and DirID via the low memory variables.
- */
- if (!extract)
- return(true);
-
- /*
- * If we are extracting, we only need a working directory vRefNum.
- */
- if (!dirSelected) {
- /* Real file selected, SFPGetFile provides this for us. */
- dirVRefNum = reply.vRefNum;
-
- } else {
- /*
- * We have a pseudo selection. Although SFPGetFile may have
- * opened a WD, it is not clear that on faking an open that
- * reply.vRefNum is set to a WD VRefNum.
- */
- memset(&wdpb, 0, sizeof(wdpb));
- wdpb.ioCompletion = nil;
- wdpb.ioNamePtr = nil;
- wdpb.ioVRefNum = dirVRefNum;
- wdpb.ioWDProcID = 0;
- wdpb.ioWDDirID = dirDirID;
- if (PBOpenWD(&wdpb, false) != noErr) {
- OSAlert(routine, "\pPBOpenWD", nil, wdpb.ioResult);
- return(false);
- }
-
- dirVRefNum = wdpb.ioVRefNum;
- }
-
- return(true);
- }
-
- /*
- * Return the working directory we allocated after a pseudo-selection
- * on an extract.
- */
-
- void
- RlsDir()
- {
- if (!dirSelected)
- return;
-
- if (PBCloseWD(&wdpb, false) != noErr) {
- OSAlert("\pRlsDir", "\pPBCloseWD", nil, wdpb.ioResult);
- return;
- }
- }