home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / disk / format64 / source / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-10  |  4.1 KB  |  181 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <dos/dos.h>
  5. #include <dos/filehandler.h>
  6. #include <workbench/startup.h>
  7. #include <libraries/gadtools.h>
  8. #include <workbench/icon.h>
  9. #include <devices/trackdisk.h>
  10. #include <dos/rdargs.h>
  11.  
  12. /*Prototypes for system functions*/
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15. #include <proto/dos.h>
  16. #include <proto/gadtools.h>
  17. #include <proto/icon.h>
  18. #include <proto/graphics.h>
  19.  
  20. /*Other headers*/
  21. #include "Format.h"
  22. #include "gui.h"
  23. #include "string.h"
  24. #include "stdio.h"
  25.  
  26. extern BOOL FFS = FALSE;
  27. extern BOOL QuickFmt = FALSE;
  28. extern BOOL Verify = TRUE;
  29. extern BOOL Icon = TRUE;
  30. extern struct Library *ibase = NULL;
  31. extern struct Library *gbase = NULL;
  32. extern struct Library *GadToolsBase = NULL;
  33. extern struct Library *IconBase = NULL;
  34. extern BPTR StdErr = NULL;
  35. extern LONG args[6] = { NULL,NULL,0,0,0,0 };
  36. //extern Rect box;
  37. extern struct WBStartup *WBenchMsg;
  38.  
  39.  
  40. /*Used in askAreYouSure()*/
  41. struct EasyStruct areYouSure = {
  42.     sizeof(struct EasyStruct), 0, "Format Request...",
  43.    "Are you sure you want to format volume\n%s\n(the contents of the disk will be destroyed)?",
  44.    "Yes|No"
  45. };
  46. struct EasyStruct writeProtected = {
  47.    sizeof(struct EasyStruct), 0, "Format Request...",
  48.    "Volume\n%s\nis write protected", "Retry|Cancel"
  49. };
  50. struct EasyStruct errorReq = {
  51.    sizeof(struct EasyStruct), 0, "Format Request...", NULL, "Ok" };
  52.  
  53. char *oneLine="%s";
  54. char *twoLine="%s\n%s";
  55. char *threeLine="%s\n%s\n%s";
  56.  
  57.  
  58.  
  59. /*Ask the user if she really wants to format the disk*/
  60. BOOL askAreYouSure(char *volumeName,BOOL truncColon)
  61.     {
  62.    char name[36];
  63.    APTR args[2];
  64.    UBYTE result;
  65.  
  66.    /*Get the device name*/
  67.    strcpy(name,volumeName);
  68.  
  69.    /*Truncate the trailing colon if so specified*/
  70.    if(truncColon) name[strlen(name)-1] = NULL;
  71.  
  72.    /*Setup the device name as the argument to the requestor*/
  73.    args[0]=name;
  74.    args[1]=NULL;
  75.  
  76.    /*Put up the requestor*/
  77.    result=EasyRequestArgs(NULL,&areYouSure,NULL,args);
  78.  
  79.    /*Return the result*/
  80.    return(result==1);
  81.     }
  82.  
  83.  
  84. /*Alert the user to the fact that the disk is write protected, and give*/
  85. /*the user a chance to unprotect the disk*/
  86. BOOL alertIsWriteProtected(char *devName)
  87. {
  88.    APTR args[2];
  89.    BYTE result;
  90.  
  91.    /*Setup the device name as the argument to the requestor*/
  92.    args[0]=devName;
  93.    args[1]=NULL;
  94.  
  95.    /*Put up the requestor*/
  96.    result=EasyRequestArgs(NULL,&writeProtected,NULL,args);
  97.  
  98.    /*Return the result*/
  99.    return(result==1);
  100. }
  101.  
  102.  
  103. /*Print one, two, or three lines of error messages in an EasyRequestor*/
  104. /*or to 'StdErr'*/
  105. void printError(char *first,char *second,char *third)
  106. {
  107.    APTR args[4];
  108.    args[0]=args[3]=NULL;
  109.  
  110.    /*If were running from the CLI*/
  111.    if(WBenchMsg==NULL)
  112.        {
  113.       /*And a StdErr handle was opened successfully*/
  114.       if(StdErr!=NULL)
  115.            {
  116.             char LF=0x0A;
  117.  
  118.             /*Print the first line*/
  119.             if(first!=NULL)
  120.                 {
  121.                 Write(StdErr,first,strlen(first));
  122.                 Write(StdErr," ",1);
  123.                 }
  124.  
  125.             /*Print the second line*/
  126.             if(second!=NULL)
  127.                 {
  128.                 Write(StdErr,second,strlen(second));
  129.                 Write(StdErr," ",1);
  130.                 }
  131.  
  132.             /*Print the third line*/
  133.             if(third!=NULL)
  134.                 {
  135.                 Write(StdErr,third,strlen(third));
  136.                 Write(StdErr," ",1);
  137.                 }
  138.  
  139.             /*Print the terminating carriage return*/
  140.             Write(StdErr,&LF,1);
  141.             }
  142.         }
  143.    else  /*Otherwise, were running from Workbench, so put up the requestor*/
  144.         {
  145.       /*Three lines*/
  146.       if(third!=NULL)
  147.             {
  148.             args[2]=third;
  149.             args[1]=second;
  150.             args[0]=first;
  151.             errorReq.es_TextFormat=threeLine;
  152.             }
  153.         else if(second!=NULL)   /*Two lines*/
  154.             {
  155.             args[1]=second;
  156.             args[0]=first;
  157.             errorReq.es_TextFormat=twoLine;
  158.             }
  159.         else if(first!=NULL)    /*One line*/
  160.             {
  161.             args[0]=first;
  162.             errorReq.es_TextFormat=oneLine;
  163.             }
  164.       /*Put up the requestor*/
  165.       EasyRequestArgs(NULL,&errorReq,NULL,args);
  166.         }
  167.     return;
  168.     }
  169.  
  170. /*Get the name of a volume, given a lock to that volume*/
  171. void getVolumeName(char *name,struct WBArg *argList,UWORD disk)
  172.     {
  173.    /*Get the name*/
  174.    if(NameFromLock(argList[disk].wa_Lock,name,256)==DOSFALSE)
  175.       /*Or return <unknown> if the name couldnt be determined*/
  176.         strcpy(name,"<unknown>");
  177.  
  178.    return;
  179.     }
  180.  
  181.