home *** CD-ROM | disk | FTP | other *** search
- #include "go.h"
- #include "display.h"
- #include "xfer.h"
-
- #include "window.proto.h"
- #include "sharedtransfer.proto.h"
- #include "disk.proto.h"
- #include "inithotband.proto.h"
- #include "alerts.proto.h"
- #include "mouse.proto.h"
- #include "menu.proto.h"
- #include "windlist.h"
-
- #include "PhysGestalt.h"
-
- /* TODO: move to .h file */
- #define FLOPPYDRIVE 1
- #define NAMEVOLDIALOG 203
- #define VOLNAMEITEM 2
- #define FORMATTEXTITEM 3
-
- void
- checkfordisk (void)
- {
- ParamBlockRec pb;
- OSErr e;
- EventRecord ev;
- short i;
- EvQEl *qp;
-
- /* Tell Executor/DOS to check for disks. */
-
- if (executor_p ())
- unixmount (0);
-
- pb.ioParam.ioVRefNum = FLOPPYDRIVE;
- e = PBMountVol (&pb);
- resetvolumes ();
- }
-
- static void
- close_all_vrefnum_windows (INTEGER vrefnum)
- {
- WindowPeek wp, nextwp;
-
- #ifdef THINK_C
- for (wp = WindowList; wp != 0; wp = nextwp)
- #else
- for (wp = LMGetWindowList (); wp != 0; wp = nextwp)
- #endif
- {
- nextwp = wp->nextWindow;
- if (browser_window_p ((WindowPtr) wp))
- {
- INTEGER wind_vref;
- wind_vref = (*(opendirinfo **) wp->refCon)->vrefnum;
- if (wind_vref == vrefnum)
- disposedirwindow ((WindowPtr) wp);
- }
- }
- }
-
- void
- format (void)
- {
- ParamBlockRec pb;
- OSErr e;
- short vrefnum, doit, type, itemhit;
- Rect r;
- long free;
- Str255 s;
- Handle h;
- DialogPtr dp;
-
- pb.ioParam.ioVRefNum = FLOPPYDRIVE;
- e = PBMountVol (&pb);
- switch (e)
- {
- case volOnLinErr:
- case noErr:
- e = GetVInfo (FLOPPYDRIVE, s, &vrefnum, &free);
- if (e == noErr)
- {
- close_all_vrefnum_windows (vrefnum);
- pb.ioParam.ioVRefNum = vrefnum;
- pb.ioParam.ioNamePtr = 0;
- PBUnmountVol (&pb);
- #ifdef THINK_C
- doit = (ask ((StringPtr) "\perase the floppy disk", s) == OK);
- #else
- doit = (ask ("\perase the floppy disk", s) == ok);
- #endif
- if (!doit)
- {
- pb.ioParam.ioVRefNum = FLOPPYDRIVE;
- PBMountVol (&pb);
- }
- break;
- }
- else
- /* FALL THROUGH */ ;
- case badMDBErr:
- case extFSErr:
- case noMacDskErr:
- case ioErr:
- #ifdef THINK_C
- doit = (ask ((StringPtr) "\pformat the floppy disk", (StringPtr) "\p") == OK);
- #else
- doit = (ask ("\pformat the floppy disk", (StringPtr) "\p") == ok);
- #endif
- break;
- case paramErr:
- case memFullErr:
- case nsDrvErr:
- case tmfoErr:
- default:
- ParamText ((StringPtr)
- "\pThe floppy disk could not be formatted because an error occurred.",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- #ifdef THINK_C
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- #else
- StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
- #endif
- doit = false;
- break;
- }
- if (doit)
- {
- dp = GetNewDialog (NAMEVOLDIALOG, 0, (WindowPtr) - 1);
- MoveWindow (dp, (qd.screenBits.bounds.right - qd.screenBits.bounds.left -
- dp->portRect.right + dp->portRect.left) / 2, 80, true);
- ShowWindow (dp);
- SelIText (dp, VOLNAMEITEM, 0, 32767);
- SelectWindow (dp);
- SetPort (dp);
- #ifdef THINK_C
- ModalDialog ((ProcPtr) 0, &itemhit);
- #else
- ModalDialog ((ModalFilterUPP) 0, &itemhit);
- #endif
- GetDItem (dp, VOLNAMEITEM, &type, &h, &r);
- GetIText (h, s);
- ParamText (s, (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
-
- InsetRect (&r, -100, -100);
- EraseRect (&r);
- OffsetRect (&r, -1000, -1000);
- SetDItem (dp, VOLNAMEITEM, type, h, &r);
-
- GetDItem (dp, itemhit, &type, &h, &r);
- /* EraseRect (&r); */
- OffsetRect (&r, -1000, -1000);
- SetDItem (dp, itemhit, type, h, &r);
-
- GetDItem (dp, FORMATTEXTITEM, &type, &h, &r);
- OffsetRect (&r, 20, 33);
- SetDItem (dp, FORMATTEXTITEM, type, h, &r);
-
- if (executor_p ())
- SetIText (h, (StringPtr) "\pSkipping low-level format");
- else
- SetIText (h, (StringPtr) "\pLow-level formatting disk");
- flush_screen_writes ();
- e = DIFormat (FLOPPYDRIVE);
- if (e != noErr)
- {
- long l;
-
- l = 0;
- PhysicalGestalt ('demo', &l);
-
- if (!l)
- ParamText ((StringPtr) "\pLow-level format failed", (StringPtr) "\p", (StringPtr) "\p",(StringPtr) "\p");
- else
- ParamText ((StringPtr) "\pYou can't format disks in the DEMO version of Executor",
- (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- #ifdef THINK_C
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- #else
- StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
- #endif
- DisposeDialog (dp);
- /*-->*/ goto DONE;
- }
- SetIText (h, (StringPtr) "\pVerifying low-level format");
- flush_screen_writes ();
- e = DIVerify (FLOPPYDRIVE);
- if (e != noErr)
- {
- ParamText ((StringPtr) "\pThis disk is bad or has not yet been low-level formatted", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- #ifdef THINK_C
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- #else
- StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
- #endif
- DisposeDialog (dp);
- /*-->*/ goto DONE;
- }
- SetIText (h, (StringPtr) "\pInitializing disk \"^0\"");
- flush_screen_writes ();
- e = DIZero (FLOPPYDRIVE, s);
- if (e != noErr)
- {
- ParamText ((StringPtr) "\pDisk initialization failed", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
- #ifdef THINK_C
- StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
- #else
- StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
- #endif
- }
- DisposeDialog (dp);
- #if 0
- pb.ioParam.ioVRefNum = FLOPPYDRIVE;
- e = PBMountVol (&pb);
- #else
- checkfordisk ();
- #endif
- }
- DONE:
- resetvolumes ();
- }
-
- OSErr
- get_HParamBlockRec_from_ControlHandle (HParamBlockRec * hpbp, ControlHandle c)
- {
- Str255 s;
-
- mystr255copy (s, (*c)->contrlTitle);
- hpbp->volumeParam.ioNamePtr = s;
- hpbp->volumeParam.ioVRefNum = 0;
- hpbp->volumeParam.ioVolIndex = -1;
- return PBHGetVInfo (hpbp, false);
- }
-
- void
- goeject (void)
- {
- ParamBlockRec pb;
- OSErr e;
- short vrefnum;
- WindowPeek wp, nextwp;
- ControlHandle c;
- HParamBlockRec hpb;
-
- e = get_HParamBlockRec_from_ControlHandle (&hpb, (**g_selection)[0]);
- if (e == noErr)
- {
- vrefnum = hpb.volumeParam.ioVRefNum;
- close_all_vrefnum_windows (vrefnum);
- pb.ioParam.ioVRefNum = vrefnum;
- pb.ioParam.ioNamePtr = 0;
- e = PBEject (&pb);
- /* FIXME - shouldn't we complain if this fails? */
- if (e == noErr)
- e = UnmountVol (0, vrefnum);
- if (e == noErr)
- disable_menu_item (eject_menuid);
- replaceselected((ControlHandle) 0);
- resetvolumes ();
- }
- }
-