home *** CD-ROM | disk | FTP | other *** search
/ ANews 1 / AnewsCD01.iso / Indispensables / Compression / xad / Developer / Sources / clients / SuperDuper3.c < prev    next >
C/C++ Source or Header  |  1999-08-09  |  4KB  |  141 lines

  1. #ifndef XADMASTER_SUPERDUPER3_C
  2. #define XADMASTER_SUPERDUPER3_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        SuperDuper3.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: SuperDuper3.c 1.2 (29.06.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    SuperDuper3 disk image client
  12.  
  13.  1.0   07.09.98 : first version
  14.  1.1   20.06.99 : removed exec.library calls
  15.  1.2   29.06.99 : now uses master free stuff
  16. */
  17.  
  18. #include <proto/xadmaster.h>
  19. #include "SDI_compiler.h"
  20. #include "xpkstuff.c"
  21.  
  22. #ifndef XADMASTERFILE
  23. #define SuperDuper3_Client    FirstClient
  24. #define NEXTCLIENT        0
  25. UBYTE version[] = "$VER: SuperDuper3 1.2 (29.06.1999)";
  26. #endif
  27. #define SUPERDUPER3_VERSION    1
  28. #define SUPERDUPER3_REVISION    2
  29.  
  30. ASM(BOOL) SuperDuper3_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  31. REG(a6, struct xadMasterBase *xadMasterBase))
  32. {
  33.   if(((ULONG *) data)[0] == 0x464F524D &&
  34.   (((ULONG *) data)[2] == 0x53444444 ||
  35.   ((ULONG *) data)[2] == 0x53444844))
  36.     return 1;
  37.   else
  38.     return 0;
  39. }
  40.  
  41. ASM(LONG) SuperDuper3_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  42. REG(a6, struct xadMasterBase *xadMasterBase))
  43. {
  44.   LONG err;
  45.   ULONG dat[9], num = 0;
  46.   struct xadDiskInfo *xdi;
  47.  
  48.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  49.     return XADERR_NOMEMORY;
  50.   ai->xai_DiskInfo = xdi;
  51.  
  52.   if((err = xadHookAccess(XADAC_READ, 12, dat, ai)))
  53.     return err;
  54.  
  55.   xdi->xdi_EntryNumber = 1;
  56.   xdi->xdi_SectorSize = 512;
  57.   xdi->xdi_Cylinders = 80;
  58.   xdi->xdi_Heads = 2;
  59.   xdi->xdi_Flags = XADDIF_GUESSLOWCYL|XADDIF_GUESSHIGHCYL;
  60. /*xdi->xdi_LowCyl = 0; */
  61.   xdi->xdi_TrackSectors = dat[2] == 0x53444844 ? 22 : 11;
  62.   xdi->xdi_CylSectors = 2 * xdi->xdi_TrackSectors;
  63.   xdi->xdi_TotalSectors = 80 * xdi->xdi_CylSectors;
  64.  
  65.   while(ai->xai_InPos < ai->xai_InSize)
  66.   {
  67.     if((err = xadHookAccess(XADAC_READ, 36, dat, ai)))
  68.       return err;
  69.     if((err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  70.       return err;
  71.     ++num;
  72.     if(dat[0] == 0x58504B46 && (dat[8] & (1<<25)))
  73.     { /* check for password flag in every entry */
  74.       ai->xai_Flags |= XADAIF_CRYPTED;
  75.       xdi->xdi_Flags |= XADDIF_CRYPTED;
  76.     }
  77.   }
  78.   if((err = xadHookAccess(XADAC_INPUTSEEK, 12 - ai->xai_InPos, 0, ai)))
  79.     return err;
  80.  
  81.   if(num > 80)
  82.     return XADERR_ILLEGALDATA;
  83.  
  84.   xdi->xdi_HighCyl = num-1;
  85.  
  86.   return 0;
  87. }
  88.  
  89. ASM(LONG) SuperDuper3_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  90. REG(a6, struct xadMasterBase *xadMasterBase))
  91. {
  92.   LONG i, err = 0, u;
  93.   struct {
  94.     STRPTR a;
  95.     ULONG  s;
  96.   } dat;
  97.  
  98.   u = ai->xai_InPos;
  99.  
  100.   /* skip entries */
  101.   for(i = ai->xai_CurDisk->xdi_LowCyl; !err && i < ai->xai_LowCyl; ++i)
  102.   {
  103.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  104.       err = xadHookAccess(XADAC_INPUTSEEK, dat.s, 0, ai);
  105.   }
  106.  
  107.   for(; !err && i <= ai->xai_HighCyl; ++i)
  108.   {
  109.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  110.     {
  111.       if(dat.a == (STRPTR) 0x58504B46)
  112.       {
  113.         if(!(err = xadHookAccess(XADAC_INPUTSEEK, -8, 0, ai)))
  114.         {
  115.           if(!(err = xpkDecrunch(&dat.a, &dat.s, ai, xadMasterBase)))
  116.           {
  117.             err = xadHookAccess(XADAC_WRITE, dat.s, dat.a, ai);
  118.             xadFreeObjectA(dat.a, 0);
  119.           }
  120.         }
  121.       }
  122.       else /* normal BODY chunk */
  123.         err = xadHookAccess(XADAC_COPY, dat.s, 0, ai);
  124.     }
  125.   }
  126.  
  127.   /* seek back to start */
  128.   if(!err)
  129.     err = xadHookAccess(XADAC_INPUTSEEK, u-ai->xai_InPos, 0, ai);
  130.  
  131.   return err;
  132. }
  133.  
  134. struct xadClient SuperDuper3_Client = {
  135. NEXTCLIENT, XADCLIENT_VERSION, 2, SUPERDUPER3_VERSION, SUPERDUPER3_REVISION,
  136. 12, XADCF_DISKARCHIVER|XADCF_FREEDISKINFO, XADCID_SUPERDUPER3, "SuperDuper3",
  137. (BOOL (*)()) SuperDuper3_RecogData, (LONG (*)()) SuperDuper3_GetInfo,
  138. (LONG (*)()) SuperDuper3_UnArchive, 0};
  139.  
  140. #endif /* XADASTER_SUPERDUPER3_C */
  141.