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

  1. #ifndef XADMASTER_XDISK_C
  2. #define XADMASTER_XDISK_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xDisk.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: xDisk.c 1.3 (29.06.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    xDisk disk archiver client
  12.  
  13.  1.0   05.09.98 : first version
  14.  1.1   04.02.99 : new InfoText system
  15.  1.2   20.06.99 : removed exec.library calls
  16.  1.3   29.06.99 : now uses master free stuff
  17. */
  18.  
  19. #include <proto/xadmaster.h>
  20. #include <dos/dos.h>
  21. #include "SDI_compiler.h"
  22. #include "xpkstuff.c"
  23.  
  24. #ifndef XADMASTERFILE
  25. #define xDisk_Client        FirstClient
  26. #define NEXTCLIENT        0
  27. UBYTE version[] = "$VER: xDisk 1.3 (29.06.1999)";
  28. #endif
  29. #define XDISK_VERSION        1
  30. #define XDISK_REVISION        3
  31.  
  32. struct xDisk {
  33.   ULONG            xd_Header;    /* equals 'XDS0' */
  34.   struct DateStamp    xd_Date;    /* date of creation */
  35.   ULONG            xd_PackTime;    /* in seconds */
  36.   UWORD            xd_AttnFlags;    /* ExecBase->AttnFlags */
  37.   UWORD            xd_SoftVer;    /* ExecBase->SoftVer */
  38.   ULONG            xd_CylinderSize; /* Size of one cylinder */
  39.   ULONG            xd_NumCylinders; /* Number of cylinders */
  40.   ULONG            xd_InfoTextSize; /* no text == 0 */
  41.   ULONG            xd_LowCyl;    /* lowest crunched cylinder */
  42.   ULONG            xd_HighCyl;    /* highest crunched Cylinder */
  43. };
  44.  
  45. /* After tha xDisk structure the packed data follows. First the
  46.    XPK-Crunched info-text (when available) and the each cylinder as a
  47.    XPKF-block.
  48.    NOTE: It seems that sometimes xDisk adds xd_InfoTextSize, also when no
  49.    text was added!
  50. */
  51.  
  52. ASM(BOOL) xDisk_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  53. REG(a6, struct xadMasterBase *xadMasterBase))
  54. {
  55.   if(((ULONG *) data)[0] == 0x58445330)
  56.     return 1;
  57.   else
  58.     return 0;
  59. }
  60.  
  61. ASM(LONG) xDisk_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  62. REG(a6, struct xadMasterBase *xadMasterBase))
  63. {
  64.   LONG err;
  65.   ULONG dat[9];
  66.   ULONG num = 0;
  67.   struct xDisk xd;
  68.   struct xadDiskInfo *xdi;
  69.  
  70.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  71.     return XADERR_NOMEMORY;
  72.   ai->xai_DiskInfo = xdi;
  73.  
  74.   if((err = xadHookAccess(XADAC_READ, sizeof(struct xDisk), &xd, ai)))
  75.     return err;
  76.   xdi->xdi_EntryNumber = 1;
  77.   xdi->xdi_Cylinders = xd.xd_NumCylinders;
  78.   xdi->xdi_LowCyl = xd.xd_LowCyl;
  79.   xdi->xdi_HighCyl = xd.xd_HighCyl;
  80.   xdi->xdi_SectorSize = 512; /* most devices should use 512 as blocksize */
  81.   xdi->xdi_CylSectors = xd.xd_CylinderSize>>9;
  82.   xdi->xdi_TotalSectors = xd.xd_NumCylinders*xdi->xdi_CylSectors;
  83.   xdi->xdi_Flags = XADDIF_GUESSHEADS|XADDIF_GUESSTRACKSECTORS;
  84.   if(xdi->xdi_CylSectors & 1)
  85.   {
  86.     xdi->xdi_Heads = 1;
  87.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors;
  88.   }
  89.   else
  90.   {
  91.     xdi->xdi_Heads = 2;
  92.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors>>1;
  93.   }
  94.  
  95.   while(ai->xai_InPos < ai->xai_InSize)
  96.   {
  97.     if((err = xadHookAccess(XADAC_READ, 36, dat, ai)))
  98.       return err;
  99.     if((err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  100.       return err;
  101.     ++num;
  102.     if(dat[8] & (1<<25)) /* check for password flag in every entry */
  103.     {
  104.       ai->xai_Flags |= XADAIF_CRYPTED;
  105.       xdi->xdi_Flags |= XADDIF_CRYPTED;
  106.     }
  107.   }
  108.   if((err = xadHookAccess(XADAC_INPUTSEEK, sizeof(struct xDisk) -
  109.   ai->xai_InPos, 0, ai)))
  110.     return err;
  111.   dat[0] = xdi->xdi_HighCyl+1-xdi->xdi_LowCyl;
  112.   if(num == dat[0]+1) /* decrunch infotext and store pointer */
  113.   {
  114.     struct xadTextInfo *ti;
  115.     if((ti = (struct xadTextInfo *) xadAllocObjectA(XADOBJ_TEXTINFO, 0)))
  116.     {
  117.       LONG err;
  118.  
  119.       if((err = xpkDecrunch(&ti->xti_Text, &ti->xti_Size, ai,
  120.       xadMasterBase)))
  121.         xadFreeObjectA(ti, 0);
  122.       else
  123.         xdi->xdi_TextInfo = ti;
  124.       return err;
  125.     }
  126.     else
  127.       return XADERR_NOMEMORY;
  128.   }
  129.   else if(num != dat[0])
  130.     return XADERR_ILLEGALDATA;
  131.  
  132.   return 0;
  133. }
  134.  
  135. ASM(LONG) xDisk_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  136. REG(a6, struct xadMasterBase *xadMasterBase))
  137. {
  138.   LONG i, err = 0, u;
  139.   struct {
  140.     STRPTR a;
  141.     ULONG  s;
  142.   } dat;
  143.  
  144.   u = ai->xai_InPos;
  145.  
  146.   /* skip entries */
  147.   for(i = ai->xai_CurDisk->xdi_LowCyl; !err && i < ai->xai_LowCyl; ++i)
  148.   {
  149.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  150.       err = xadHookAccess(XADAC_INPUTSEEK, dat.s, 0, ai);
  151.   }
  152.  
  153.   for(; !err && i <= ai->xai_HighCyl; ++i)
  154.   {
  155.     if(!(err = xpkDecrunch(&dat.a, &dat.s, ai, xadMasterBase)))
  156.     {
  157.       err = xadHookAccess(XADAC_WRITE, dat.s, dat.a, ai);
  158.       xadFreeObjectA(dat.a, 0);
  159.     }
  160.   }
  161.  
  162.   /* seek back to start */
  163.   if(!err)
  164.     err = xadHookAccess(XADAC_INPUTSEEK, u-ai->xai_InPos, 0, ai);
  165.  
  166.   return err;
  167. }
  168.  
  169. struct xadClient xDisk_Client = {
  170. NEXTCLIENT, XADCLIENT_VERSION, 2, XDISK_VERSION, XDISK_REVISION, 4,
  171. XADCF_DISKARCHIVER|XADCF_FREEDISKINFO|XADCF_FREETEXTINFO|XADCF_FREETEXTINFOTEXT,
  172. XADCID_XDISK, "xDisk", (BOOL (*)()) xDisk_RecogData,
  173. (LONG (*)()) xDisk_GetInfo, (LONG (*)()) xDisk_UnArchive, 0};
  174.  
  175. #endif /* XADASTER_XDISK_C */
  176.