home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / disk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  6.4 KB  |  263 lines

  1. #include "go.h"
  2. #include "display.h"
  3. #include "xfer.h"
  4.  
  5. #include "window.proto.h"
  6. #include "sharedtransfer.proto.h"
  7. #include "disk.proto.h"
  8. #include "inithotband.proto.h"
  9. #include "alerts.proto.h"
  10. #include "mouse.proto.h"
  11. #include "menu.proto.h"
  12. #include "windlist.h"
  13.  
  14. #include "PhysGestalt.h"
  15.  
  16. /* TODO: move to .h file */
  17. #define FLOPPYDRIVE    1
  18. #define NAMEVOLDIALOG    203
  19. #define VOLNAMEITEM    2
  20. #define FORMATTEXTITEM    3
  21.  
  22. void
  23. checkfordisk (void)
  24. {
  25.   ParamBlockRec pb;
  26.   OSErr e;
  27.   EventRecord ev;
  28.   short i;
  29.   EvQEl *qp;
  30.  
  31. /* Tell Executor/DOS to check for disks. */
  32.  
  33.   if (executor_p ())
  34.     unixmount (0);
  35.  
  36.   pb.ioParam.ioVRefNum = FLOPPYDRIVE;
  37.   e = PBMountVol (&pb);
  38.   resetvolumes ();
  39. }
  40.  
  41. static void
  42. close_all_vrefnum_windows (INTEGER vrefnum)
  43. {
  44.   WindowPeek wp, nextwp;
  45.   
  46. #ifdef THINK_C
  47.   for (wp = WindowList; wp != 0; wp = nextwp)
  48. #else
  49.   for (wp = LMGetWindowList (); wp != 0; wp = nextwp)
  50. #endif
  51.     {
  52.       nextwp = wp->nextWindow;
  53.       if (browser_window_p ((WindowPtr) wp))
  54.         {
  55.           INTEGER wind_vref;
  56.           wind_vref = (*(opendirinfo **) wp->refCon)->vrefnum;
  57.         if (wind_vref == vrefnum)
  58.           disposedirwindow ((WindowPtr) wp);
  59.     }
  60.     }
  61. }
  62.  
  63. void
  64. format (void)
  65. {
  66.   ParamBlockRec pb;
  67.   OSErr e;
  68.   short vrefnum, doit, type, itemhit;
  69.   Rect r;
  70.   long free;
  71.   Str255 s;
  72.   Handle h;
  73.   DialogPtr dp;
  74.  
  75.   pb.ioParam.ioVRefNum = FLOPPYDRIVE;
  76.   e = PBMountVol (&pb);
  77.   switch (e)
  78.     {
  79.     case volOnLinErr:
  80.     case noErr:
  81.       e = GetVInfo (FLOPPYDRIVE, s, &vrefnum, &free);
  82.       if (e == noErr)
  83.         {
  84.           close_all_vrefnum_windows (vrefnum);
  85.           pb.ioParam.ioVRefNum = vrefnum;
  86.           pb.ioParam.ioNamePtr = 0;
  87.           PBUnmountVol (&pb);
  88. #ifdef THINK_C
  89.           doit = (ask ((StringPtr) "\perase the floppy disk", s) == OK);
  90. #else
  91.           doit = (ask ("\perase the floppy disk", s) == ok);
  92. #endif
  93.           if (!doit)
  94.         {
  95.           pb.ioParam.ioVRefNum = FLOPPYDRIVE;
  96.           PBMountVol (&pb);
  97.         }
  98.           break;
  99.         }
  100.       else
  101.         /* FALL THROUGH */ ;
  102.     case badMDBErr:
  103.     case extFSErr:
  104.     case noMacDskErr:
  105.     case ioErr:
  106. #ifdef THINK_C
  107.       doit = (ask ((StringPtr) "\pformat the floppy disk", (StringPtr) "\p") == OK);
  108. #else
  109.       doit = (ask ("\pformat the floppy disk", (StringPtr) "\p") == ok);
  110. #endif
  111.       break;
  112.     case paramErr:
  113.     case memFullErr:
  114.     case nsDrvErr:
  115.     case tmfoErr:
  116.     default:
  117.       ParamText ((StringPtr)
  118.       "\pThe floppy disk could not be formatted because an error occurred.",
  119.          (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  120. #ifdef THINK_C
  121.       StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
  122. #else
  123.       StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
  124. #endif
  125.       doit = false;
  126.       break;
  127.     }
  128.   if (doit)
  129.     {
  130.       dp = GetNewDialog (NAMEVOLDIALOG, 0, (WindowPtr) - 1);
  131.       MoveWindow (dp, (qd.screenBits.bounds.right - qd.screenBits.bounds.left -
  132.              dp->portRect.right + dp->portRect.left) / 2, 80, true);
  133.       ShowWindow (dp);
  134.       SelIText (dp, VOLNAMEITEM, 0, 32767);
  135.       SelectWindow (dp);
  136.       SetPort (dp);
  137. #ifdef THINK_C
  138.       ModalDialog ((ProcPtr) 0, &itemhit);
  139. #else
  140.       ModalDialog ((ModalFilterUPP) 0, &itemhit);
  141. #endif
  142.       GetDItem (dp, VOLNAMEITEM, &type, &h, &r);
  143.       GetIText (h, s);
  144.       ParamText (s, (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  145.  
  146.       InsetRect (&r, -100, -100);
  147.       EraseRect (&r);
  148.       OffsetRect (&r, -1000, -1000);
  149.       SetDItem (dp, VOLNAMEITEM, type, h, &r);
  150.       
  151.       GetDItem (dp, itemhit, &type, &h, &r);
  152.       /* EraseRect (&r); */
  153.       OffsetRect (&r, -1000, -1000);
  154.       SetDItem (dp, itemhit, type, h, &r);
  155.       
  156.       GetDItem (dp, FORMATTEXTITEM, &type, &h, &r);
  157.       OffsetRect (&r, 20, 33);
  158.       SetDItem (dp, FORMATTEXTITEM, type, h, &r);
  159.       
  160.       if (executor_p ())
  161.         SetIText (h, (StringPtr) "\pSkipping low-level format");
  162.       else
  163.         SetIText (h, (StringPtr) "\pLow-level formatting disk");
  164.       flush_screen_writes ();
  165.       e = DIFormat (FLOPPYDRIVE);
  166.       if (e != noErr)
  167.     {
  168.       long l;
  169.       
  170.       l = 0;
  171.       PhysicalGestalt ('demo', &l);
  172.       
  173.       if (!l)
  174.         ParamText ((StringPtr) "\pLow-level format failed", (StringPtr) "\p", (StringPtr) "\p",(StringPtr) "\p");
  175.       else
  176.         ParamText ((StringPtr) "\pYou can't format disks in the DEMO version of Executor",
  177.             (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  178. #ifdef THINK_C
  179.       StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
  180. #else
  181.       StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
  182. #endif
  183.       DisposeDialog (dp);
  184. /*-->*/      goto DONE;
  185.     }
  186.       SetIText (h, (StringPtr) "\pVerifying low-level format");
  187.       flush_screen_writes ();
  188.       e = DIVerify (FLOPPYDRIVE);
  189.       if (e != noErr)
  190.     {
  191.       ParamText ((StringPtr) "\pThis disk is bad or has not yet been low-level formatted", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  192. #ifdef THINK_C
  193.       StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
  194. #else
  195.       StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
  196. #endif
  197.       DisposeDialog (dp);
  198. /*-->*/      goto DONE;
  199.     }
  200.       SetIText (h, (StringPtr) "\pInitializing disk \"^0\"");
  201.       flush_screen_writes ();
  202.       e = DIZero (FLOPPYDRIVE, s);
  203.       if (e != noErr)
  204.     {
  205.       ParamText ((StringPtr) "\pDisk initialization failed", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p");
  206. #ifdef THINK_C
  207.       StopAlert (FOUR_PARAM_ALERT, (ProcPtr) 0);
  208. #else
  209.       StopAlert (FOUR_PARAM_ALERT, (ModalFilterUPP) 0);
  210. #endif
  211.     }
  212.       DisposeDialog (dp);
  213. #if 0
  214.       pb.ioParam.ioVRefNum = FLOPPYDRIVE;
  215.       e = PBMountVol (&pb);
  216. #else
  217.       checkfordisk ();
  218. #endif
  219.     }
  220. DONE:
  221.   resetvolumes ();
  222. }
  223.  
  224. OSErr
  225. get_HParamBlockRec_from_ControlHandle (HParamBlockRec * hpbp, ControlHandle c)
  226. {
  227.   Str255 s;
  228.  
  229.   mystr255copy (s, (*c)->contrlTitle);
  230.   hpbp->volumeParam.ioNamePtr = s;
  231.   hpbp->volumeParam.ioVRefNum = 0;
  232.   hpbp->volumeParam.ioVolIndex = -1;
  233.   return PBHGetVInfo (hpbp, false);
  234. }
  235.  
  236. void
  237. goeject (void)
  238. {
  239.   ParamBlockRec pb;
  240.   OSErr e;
  241.   short vrefnum;
  242.   WindowPeek wp, nextwp;
  243.   ControlHandle c;
  244.   HParamBlockRec hpb;
  245.  
  246.   e = get_HParamBlockRec_from_ControlHandle (&hpb, (**g_selection)[0]);
  247.   if (e == noErr)
  248.     {
  249.       vrefnum = hpb.volumeParam.ioVRefNum;
  250.       close_all_vrefnum_windows (vrefnum);
  251.       pb.ioParam.ioVRefNum = vrefnum;
  252.       pb.ioParam.ioNamePtr = 0;
  253.       e = PBEject (&pb);
  254. /* FIXME - shouldn't we complain if this fails? */
  255.       if (e == noErr)
  256.     e = UnmountVol (0, vrefnum);
  257.       if (e == noErr)
  258.     disable_menu_item (eject_menuid);
  259.       replaceselected((ControlHandle) 0);
  260.       resetvolumes ();
  261.     }
  262. }
  263.