home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / disk utilities / backup / backup_restore / backup_src_v3.20.lha / TapeUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-15  |  4.2 KB  |  177 lines

  1. /* TapeUtil.c */
  2. /* 14 Jan 1996 20:29:06 */
  3.  
  4. #ifndef    BACKUP_INCLUDE
  5. #include "IncludeAll.c"
  6. #endif
  7. #include "Backup.h"
  8. #include "Backup_proto.h"
  9. #include "BackupStrings.h"
  10.  
  11.  
  12. static BOOL BeginTapeInfo(struct Window *Parent, const char *InfoText, ...);
  13.  
  14.  
  15. /* aus Backup.c */
  16. extern struct TextFont *ScreenFont;
  17. extern struct DiskFlags __far *Disks;
  18.  
  19. /* aus FileSelect.c */
  20. extern struct Window *MenuWin;            /* an diesem Window hängt das Menu */
  21. extern struct Window *FSwin;            /* File Select Window */
  22.  
  23. /* aus Backup_Window.c */
  24. extern struct DrawInfo *myDrawInfo;
  25.  
  26.  
  27. static const TIBorder = 50;
  28. static struct Window *TIWindow;
  29.  
  30.  
  31. static BOOL BeginTapeInfo(struct Window *Parent, const char *InfoText, ...)
  32. {
  33.     struct NewWindow NewTIWindow;
  34.     struct TextExtent TiExt;
  35.     size_t Length;
  36.     char Line[512];
  37.     struct RastPort rpCopy;
  38.     va_list args;
  39.  
  40.     va_start(args, InfoText);
  41.  
  42.     ASSERT_VALID(Parent);
  43.     ASSERT_VALID(InfoText);
  44.  
  45.     vsprintf(Line, InfoText, args);
  46.  
  47.     Length = strlen(Line);
  48.  
  49.     rpCopy = *Parent->RPort;
  50.     if (ScreenFont)
  51.         SetFont(&rpCopy, ScreenFont);
  52.  
  53.     TextExtent(&rpCopy, (STRPTR) Line, Length, &TiExt);
  54.  
  55.     NewTIWindow.Width = TIBorder + TiExt.te_Width + Parent->BorderLeft + Parent->BorderRight;
  56.     NewTIWindow.Height = TIBorder + TiExt.te_Height + Parent->BorderTop + Parent->BorderBottom;
  57.  
  58.     CenterWindow(Parent, &NewTIWindow);
  59.  
  60.     TIWindow = OpenWindowTags(NULL,
  61.             WA_Left, NewTIWindow.LeftEdge,
  62.             WA_Top, NewTIWindow.TopEdge,
  63.             WA_Width, NewTIWindow.Width,
  64.             WA_Height, NewTIWindow.Height,
  65.             WA_AutoAdjust, TRUE,
  66.             WA_Flags, WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH
  67.                 | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE,
  68.             WA_IDCMP, 0l,
  69.             WA_Title, GetString(MSG_TAPEUTILWINDOW_TITLE),
  70.             WA_PubScreen, Parent->WScreen,
  71.             WA_NewLookMenus, TRUE,
  72.             TAG_END);
  73.     if (NULL == TIWindow)
  74.         {
  75.         alarm("%s: %s", __FUNC__, GetString(MSG_CANNOT_OPEN_WINDOW), "TIWindow");
  76.         return FALSE;
  77.         }
  78.  
  79.     if (ScreenFont)
  80.         SetFont(TIWindow->RPort, ScreenFont);
  81.     else
  82.         SetFont(TIWindow->RPort, Parent->RPort->Font);
  83.  
  84.     Move(TIWindow->RPort, TIWindow->BorderLeft + (TIWindow->Width - TiExt.te_Width)/2,
  85.         TIWindow->BorderTop +
  86.         (TIWindow->Height - TIWindow->BorderTop - TIWindow->BorderBottom
  87.             - TiExt.te_Height) / 2 + TiExt.te_Height );
  88.     SetDrMd(TIWindow->RPort, JAM1);
  89.     SetAPen(TIWindow->RPort, myDrawInfo->dri_Pens[TEXTPEN]);
  90.  
  91.     Text(TIWindow->RPort, (STRPTR) Line, Length);
  92.  
  93.     va_end(args);
  94.  
  95.     return TRUE;
  96. }
  97.  
  98.  
  99. void CleanupTapeInfo(void)
  100. {
  101.     if (TIWindow)
  102.         {
  103.         SafeCloseWindow(&TIWindow);
  104.  
  105.         if (FSwin)
  106.             WindowBusy(FSwin, FALSE);
  107.         }
  108. }
  109.  
  110.  
  111. void TapeFunction(short Unit, enum TapeFunc Function)
  112. {
  113.     short Error = 0;
  114.     long ErrorMsg;
  115.  
  116.     if (Unit == NO_DRIVE || Disks[Unit].TapeReq == NULL)
  117.         return;
  118.  
  119.     if (Function == TF_Erase &&
  120.             yesno(MenuWin, GetString(MSG_ERASETAPE_Q), Disks[Unit].DOSName)
  121.                  != *GetString(MSG_YES_SHORT))
  122.         {
  123.         return;
  124.         }
  125.  
  126.     if (FSwin)
  127.         WindowBusy(FSwin, TRUE);
  128.  
  129.     Disks[Unit].diskreq = OpenDisk(&Disks[Unit], TRUE);
  130.     if (Disks[Unit].diskreq)
  131.         {
  132.         Disks[Unit].TapeReq->Req = Disks[Unit].diskreq;
  133.  
  134.         TapeInitProperties(Disks[Unit].TapeReq);
  135.         TapeInitDrive(Disks[Unit].TapeReq, &Disks[Unit]);
  136.  
  137.         switch (Function)
  138.             {
  139.         case TF_Rewind:
  140.             BeginTapeInfo(MenuWin, GetString(MSG_REWINDING_TAPE), Disks[Unit].DOSName);
  141.             Error = TapeRewind(Disks[Unit].TapeReq);
  142.             ErrorMsg = MSG_TAPEREWIND_FAIL;
  143.             break;
  144.         case TF_Retension:
  145.             BeginTapeInfo(MenuWin, GetString(MSG_RETENSIONING_TAPE), Disks[Unit].DOSName);
  146.             Error = TapeRetension(Disks[Unit].TapeReq);
  147.             ErrorMsg = MSG_TAPERETENSION_FAIL;
  148.             break;
  149.         case TF_Erase:
  150.             BeginTapeInfo(MenuWin, GetString(MSG_ERASING_TAPE), Disks[Unit].DOSName);
  151.             Error = TapeErase(Disks[Unit].TapeReq);
  152.             ErrorMsg = MSG_TAPEERASE_FAIL;
  153.             break;
  154.         case TF_Unload:
  155.             BeginTapeInfo(MenuWin, GetString(MSG_UNLOADING_TAPE), Disks[Unit].DOSName);
  156.             Error = TapeTryLoadUnLoad(Disks[Unit].TapeReq, FALSE);
  157.             ErrorMsg = MSG_TAPEUNLOAD_FAIL;
  158.             break;
  159.         case TF_Load:
  160.             BeginTapeInfo(MenuWin, GetString(MSG_LOADING_TAPE), Disks[Unit].DOSName);
  161.             Error = TapeTryLoadUnLoad(Disks[Unit].TapeReq, TRUE);
  162.             ErrorMsg = MSG_TAPELOAD_FAIL;
  163.             break;
  164.             }
  165.  
  166.         if (Error)
  167.             TapeError(Disks[Unit].TapeReq, &Disks[Unit], GetString(ErrorMsg), Error, FALSE, FALSE);
  168.  
  169.         CloseDisk(&Disks[Unit], CDP_KeepTape);
  170.         CleanUpDisk(&Disks[Unit], 0);
  171.         }
  172.  
  173.     CleanupTapeInfo();
  174. }
  175.  
  176.  
  177.