home *** CD-ROM | disk | FTP | other *** search
- #include <MacTypes.h>
- #include <QuickDraw.h>
- #include <WindowMgr.h>
- #include <DialogMgr.h>
- #include <EventMgr.h>
- #include <FileMgr.h>
- #include <HFS.h>
-
- #include "fix.h"
-
- #define RETURN_KEY 0x24
- #define TAB_KEY 0x30
- #define ENTER_KEY 0x34
-
- enum {
- ITEM_VOLUME_OK = 1,
- ITEM_VOLUME_CANCEL,
- ITEM_VOLUME_VOLNAME = 4,
- ITEM_VOLUME_DRIVE,
- ITEM_VOLUME_EJECT
- };
-
- int get_volume_info(int index, int *refnum, unsigned char *name, int *drive,
- int *is_hfs);
- pascal Boolean disk_filter(DialogPtr the_dialog, EventRecord *the_event,
- int *item_hit);
-
- /* Volume selection and utilities. */
-
- /* Select which volume to process. */
-
- int select_volume_dialog(refnum, is_hfs) /* Return 1 if OK, 0 if canceled */
- int *refnum, *is_hfs;
- {
- register DialogPtr the_dialog;
- register Handle the_item;
- int item, drive;
- register int current_index, index_changed, done;
- unsigned char volume_name[NAME_SIZE];
-
- the_dialog = GetNewDialog(DIALOG_VOLUME, NIL, MINUS_ONE);
- the_item = get_item(the_dialog, ITEM_VOLUME_VOLNAME);
-
- index_changed = current_index = 1;
- done = 0;
- do {
- if (index_changed) {
- register int err;
-
- index_changed = 0;
- err = get_volume_info(current_index, refnum, volume_name, &drive,
- is_hfs);
- while (!err && !drive) { /* List only on-line volumes... */
- current_index++;
- err = get_volume_info(current_index, refnum, volume_name,
- &drive,is_hfs);
- }
- if (err) /* If at end of list, just use first volume. */
- get_volume_info(current_index = 1, refnum, volume_name,
- &drive, is_hfs);
- SetIText(the_item, volume_name);
- }
- ModalDialog(disk_filter, &item);
- if (item < 0) { /* Disk inserted: try to find it. */
- register int found;
-
- item = -item;
- current_index = 1;
- found = 0;
- while (!found) {
- if (get_volume_info(current_index, refnum, volume_name, &drive,
- is_hfs) != 0)
- found = current_index = 1; /* Abort on error. */
- else
- if (drive == item) /* We found it! */
- found = 1;
- else
- current_index++;
- }
- index_changed = 1;
- }
- else
- switch (item) {
- case ITEM_VOLUME_OK:
- case ITEM_VOLUME_CANCEL:
- done = 1;
- break;
- case ITEM_VOLUME_DRIVE:
- current_index++;
- index_changed = 1;
- break;
- case ITEM_VOLUME_EJECT:
- Eject(NIL, *refnum);
- index_changed = 1;
- break;
- }
- } while (!done);
- DisposDialog(the_dialog);
-
- if (item == ITEM_VOLUME_OK) {
- ParamText(volume_name, NIL, NIL, NIL); /* Set volume name */
- return(1);
- }
- else
- return(0);
- }
-
- /* Get information about a volume, given its index. */
-
- int get_volume_info(index, refnum, name, drive, is_hfs)
- int index, *refnum, *drive, *is_hfs;
- unsigned char *name;
- {
- register int err;
- HParamBlockRec blob;
-
- blob.volumeParam.ioCompletion = NIL;
- blob.volumeParam.ioNamePtr = name;
- blob.volumeParam.ioVolIndex = index;
- err = PBHGetVInfo(&blob, 0);
-
- if (!err) {
- *refnum = blob.volumeParam.ioVRefNum;
- *drive = blob.volumeParam.ioVDrvInfo;
- *is_hfs = (blob.volumeParam.ioVSigWord == 'BD');
- }
- return(err);
- }
-
- /* Filter to allow mounting of volumes within a dialog. */
-
- static pascal Boolean disk_filter(the_dialog, the_event, item_hit)
- DialogPtr the_dialog;
- register EventRecord *the_event;
- register int *item_hit;
- {
- if (the_event->what == keyDown) {
- register int key_code;
-
- key_code = (the_event->message >> 8) & 0xFF; /* Keyboard key */
- if ((key_code == RETURN_KEY) || (key_code == ENTER_KEY)) {
- *item_hit = ITEM_VOLUME_OK;
- return (TRUE);
- }
- else if (key_code == TAB_KEY) {
- *item_hit = ITEM_VOLUME_DRIVE;
- return (TRUE);
- }
- }
- else if (the_event->what == nullEvent) {
- EventRecord disk_event;
-
- if (GetNextEvent(diskMask, &disk_event))
- if (HiWord(disk_event.message))
- Eject(NIL, LoWord(disk_event.message));
- else {
- *item_hit = -LoWord(disk_event.message);
- return (TRUE);
- }
- };
-
- return (FALSE);
- }
-