home *** CD-ROM | disk | FTP | other *** search
- #define NAME "xadUnDisk"
- #define DISTRIBUTION "(Freeware) "
- #define REVISION "4"
-
- /* Programmheader
-
- Name: xadUnDisk
- Author: SDI
- Distribution: Freeware
- Description: dearchives disk archives
- Compileropts: -
- Linkeropts: -gsi -l amiga
-
- 1.0 18.11.98 : first version
- 1.1 23.12.98 : added support for FILEDESCRIPT
- 1.2 04.02.99 : added file corrupt message, new InfoText system and SAVETEXTS
- 1.3 16.02.99 : bug fix in report hook
- 1.4 28.02.99 : little bug fix in chunk hook
- */
-
- #include <proto/xadmaster.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <exec/memory.h>
- #include <dos/dosasl.h>
- #include <utility/hooks.h>
- #include "SDI_defines.h"
- #include "SDI_compiler.h"
- #define SDI_TO_ANSI
- #include "SDI_ASM_STD_protos.h"
-
- #ifdef __SASC
- #define xadmasterbase xadMasterBase
- #define ASSIGN_XAD
- #else
- struct xadMasterBase * xadMasterBase = 0;
- #define ASSIGN_XAD xadMasterBase = xadmasterbase;
- #endif
- struct DosLibrary * DOSBase = 0;
- struct ExecBase * SysBase = 0;
-
- #define PARAM "FROM/A,TO,LOWCYL/N,HIGHCYL/N,ENTRY/N,PASSWORD,SAVETEXTS/K," \
- "NE=NOEXTERN/S,INFO=LIST/S,SHOWTEXTS/S,OW=OVERWRITE/S," \
- "IG=IGNOREGEOMETRY/S"
-
- struct Args {
- STRPTR from;
- STRPTR to;
- LONG * lowcyl;
- LONG * highcyl;
- LONG * entry;
- STRPTR password;
- STRPTR savetexts;
- ULONG noextern;
- ULONG info;
- ULONG showtexts;
- ULONG overwrite;
- ULONG ignoregeometry;
- };
-
- ASM(ULONG) SAVEDS progrhook(REG(a0, struct Hook *),
- REG(a1, struct xadProgressInfo *));
- struct Hook prhook = {{0,0},(ULONG (*)()) progrhook, 0, 0};
- void ShowTexts(struct xadTextInfo *ti);
- void SaveTexts(struct xadTextInfo *ti, STRPTR name);
-
- ULONG start(void)
- {
- ULONG ret = RETURN_FAIL;
- struct DosLibrary *dosbase;
-
- SysBase = (*((struct ExecBase **) 4));
- { /* test for WB and reply startup-message */
- struct Process *task;
- if(!(task = (struct Process *) FindTask(0))->pr_CLI)
- {
- WaitPort(&task->pr_MsgPort);
- Forbid();
- ReplyMsg(GetMsg(&task->pr_MsgPort));
- return RETURN_FAIL;
- }
- }
-
- if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
- {
- LONG err = 0;
- struct xadMasterBase *xadmasterbase;
-
- DOSBase = dosbase;
- if((xadmasterbase = (struct xadMasterBase *)
- OpenLibrary("xadmaster.library", 1)))
- {
- LONG def = 1;
- struct Args args;
- struct RDArgs *rda;
-
- memset(&args, 0 , sizeof(struct Args));
- args.entry = &def;
-
- ASSIGN_XAD
- if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
- {
- if(args.to || args.info)
- {
- struct xadArchiveInfo *ai;
-
- if((ai = (struct xadArchiveInfo *)
- xadAllocObjectA(XADOBJ_ARCHIVEINFO, 0)))
- {
- if(!(err = xadGetInfo(ai, XAD_INFILENAME, args.from,
- XAD_NOEXTERN, args.noextern, args.password ? XAD_PASSWORD :
- TAG_IGNORE, args.password, TAG_DONE)))
- {
- if(ai->xai_Flags & XADAIF_FILECORRUPT)
- Printf("!!! The archive file has some corrupt data. !!!\n");
- if(args.info)
- {
- struct xadDiskInfo *xdi;
- Printf("ArchiverName: %s\n", ai->xai_Client->xc_ArchiverName);
- #ifdef DEBUG
- Printf("Password: %s\n", ai->xai_Password ? ai->xai_Password : "<none>");
- Printf("InSize: %ld\n", ai->xai_InSize);
- Printf("InPos: %ld\n", ai->xai_InPos);
- #endif
-
- xdi = ai->xai_DiskInfo;
- while(xdi)
- {
- if(xdi->xdi_EntryNumber != 1 || xdi->xdi_Next)
- Printf("\nEntry: %ld\n", xdi->xdi_EntryNumber);
- Printf("EntryInfo: %s\n", xdi->xdi_EntryInfo ? xdi->xdi_EntryInfo : "<none>");
- #ifdef DEBUG
- Printf("Flags: ");
- if(xdi->xdi_Flags & XADDIF_CRYPTED)
- Printf("XADDIF_CRYPTED ");
- Printf(xdi->xdi_Flags ? "\n" : "<none>\n");
- #endif
- Printf("SectorSize: %ld\n", xdi->xdi_SectorSize);
- Printf("Sectors: %ld\n", xdi->xdi_TotalSectors);
- Printf("Cylinders: %ld\n", xdi->xdi_Cylinders);
- Printf("CylSectors: %ld\n", xdi->xdi_CylSectors);
- Printf("Heads: %ld\n", xdi->xdi_Heads);
- Printf("TrackSectors: %ld\n", xdi->xdi_TrackSectors);
- Printf("LowCyl: %ld\n", xdi->xdi_LowCyl);
- Printf("HighCyl: %ld\n", xdi->xdi_HighCyl);
- if(xdi->xdi_Flags & XADDIF_CRYPTED)
- Printf("The entry is encrypted\n");
- if(xdi->xdi_TextInfo)
- {
- STRPTR a;
- struct xadTextInfo *ti;
-
- for(ti = xdi->xdi_TextInfo; ti; ti = ti->xti_Next)
- {
- a = "TextInfo";
- if(ti->xti_Flags & XADTIF_BANNER)
- a = "Banner";
- else if(ti->xti_Flags & XADTIF_FILEDIZ)
- a = "DIZ-Text";
-
- if(ti->xti_Size && ti->xti_Text)
- Printf("There is a %s with size %ld.\n", a, ti->xti_Size);
- else if(ti->xti_Flags & XADTIF_CRYPTED)
- Printf("There is a crypted %s.\n", a);
- else
- Printf("There is an empty %s.\n", a);
- }
- if(args.showtexts)
- ShowTexts(xdi->xdi_TextInfo);
- if(args.savetexts)
- SaveTexts(xdi->xdi_TextInfo, args.savetexts);
- }
- xdi = xdi->xdi_Next;
- }
- ret = 0;
- }
- else
- {
- struct xadDeviceInfo *dvi = 0;
-
- if(args.to[strlen(args.to)-1] == ':' && stricmp(args.to, "NIL:"))
- {
- if((dvi = (struct xadDeviceInfo *)
- xadAllocObjectA(XADOBJ_DEVICEINFO, 0)))
- {
- args.to[strlen(args.to)-1] = 0; /* strip ':' */
- dvi->xdi_DOSName = args.to;
- }
- else
- err = XADERR_NOMEMORY;
- }
- if(args.showtexts || args.savetexts)
- {
- struct xadDiskInfo *xdi = ai->xai_DiskInfo;
-
- while(xdi && xdi->xdi_EntryNumber < *args.entry)
- xdi = xdi->xdi_Next;
- if(xdi && xdi->xdi_TextInfo)
- {
- if(args.showtexts)
- ShowTexts(xdi->xdi_TextInfo);
- if(args.savetexts)
- SaveTexts(xdi->xdi_TextInfo, args.savetexts);
- }
- }
- if(!err && !(err = xadDiskUnArc(ai, dvi ? XAD_OUTDEVICE :
- XAD_OUTFILENAME, dvi ? (ULONG) dvi : (ULONG) args.to,
- XAD_ENTRYNUMBER, *args.entry, args.lowcyl ?
- XAD_LOWCYLINDER : TAG_IGNORE, args.lowcyl ? *args.lowcyl :
- 0, args.highcyl ? XAD_HIGHCYLINDER : TAG_IGNORE,
- args.highcyl ? *args.highcyl : 0, XAD_OVERWRITE,
- args.overwrite, XAD_IGNOREGEOMETRY, args.ignoregeometry,
- XAD_VERIFY, TRUE, XAD_PROGRESSHOOK, &prhook, TAG_DONE)))
- ret = 0;
- if(dvi)
- xadFreeObjectA(dvi, 0);
- }
- xadFreeInfo(ai);
- } /* xadGetInfo */
-
- xadFreeObjectA(ai, 0);
- } /* xadAllocObject */
- }
- else
- SetIoErr(ERROR_REQUIRED_ARG_MISSING);
-
- FreeArgs(rda);
- } /* ReadArgs */
-
- if(CTRL_C)
- SetIoErr(ERROR_BREAK);
-
- if(err)
- Printf("An error occured: %s\n", xadGetErrorText(err));
- else if(ret)
- PrintFault(IoErr(), 0);
-
- CloseLibrary((struct Library *) xadmasterbase);
- } /* OpenLibrary xadmaster */
- else
- Printf("Could not open xadmaster.library\n");
- CloseLibrary((struct Library *) dosbase);
- } /* OpenLibrary dos */
- return ret;
- }
-
- ASM(ULONG) SAVEDS progrhook(REG(a0, struct Hook *hook),
- REG(a1, struct xadProgressInfo *pi))
- {
- ULONG ret = 0;
-
- switch(pi->xpi_Mode)
- {
- case XADPMODE_ASK:
- {
- UBYTE r;
- if(pi->xpi_Status & XADPIF_OVERWRITE)
- {
- Printf("File already exists, overwrite? (Y|S|\033[1mN\033[0m): ");
- Flush(Output());
- SetMode(Input(), TRUE);
- r = FGetC(Input());
- if(r == 'Y' || r == 'y')
- ret |= XADPIF_OVERWRITE;
- else if(r == 'S' || r == 's')
- ret |= XADPIF_SKIP;
- SetMode(Input(), FALSE);
- }
- if(pi->xpi_Status & XADPIF_IGNOREGEOMETRY)
- {
- Printf("Drive geometry not correct, ignore? (Y|S|\033[1mN\033[0m): ");
- Flush(Output());
- SetMode(Input(), TRUE);
- r = FGetC(Input());
- if(r == 'Y' || r == 'y')
- ret |= XADPIF_IGNOREGEOMETRY;
- else if(r == 'S' || r == 's')
- ret |= XADPIF_SKIP;
- SetMode(Input(), FALSE);
- }
- }
- break;
- case XADPMODE_PROGRESS:
- {
- if(pi->xpi_DiskInfo->xdi_Flags & (XADDIF_NOCYLINDERS|XADDIF_NOCYLSECTORS))
- {
- Printf("\r\033[KWrote %ld of %ld bytes (%ld/%ld sectors)",
- pi->xpi_CurrentSize, pi->xpi_DiskInfo->xdi_TotalSectors*
- pi->xpi_DiskInfo->xdi_SectorSize, pi->xpi_CurrentSize/
- pi->xpi_DiskInfo->xdi_SectorSize, pi->xpi_DiskInfo->xdi_TotalSectors);
- }
- else
- {
- ULONG numcyl, fullsize, curcyl, i;
-
- i = pi->xpi_DiskInfo->xdi_CylSectors *
- pi->xpi_DiskInfo->xdi_SectorSize;
- numcyl = pi->xpi_HighCyl+1-pi->xpi_LowCyl;
- fullsize = numcyl * i;
- curcyl = pi->xpi_CurrentSize/i;
-
- Printf("\r\033[KWrote %ld of %ld bytes (%ld/%ld cylinders)",
- pi->xpi_CurrentSize, fullsize, curcyl, numcyl);
- }
- Flush(Output());
- }
- break;
- case XADPMODE_END:
- if(pi->xpi_DiskInfo->xdi_Flags & (XADDIF_NOCYLINDERS|XADDIF_NOCYLSECTORS))
- Printf("\r\033[KWrote %ld bytes (%ld sectors)\n",
- pi->xpi_CurrentSize, pi->xpi_DiskInfo->xdi_TotalSectors);
- else
- Printf("\r\033[KWrote %ld bytes (%ld cylinders)\n",
- pi->xpi_CurrentSize, pi->xpi_HighCyl+1-pi->xpi_LowCyl);
- break;
- case XADPMODE_ERROR: Printf("\r\033[K");
- break;
- }
-
- if(!CTRL_C) /* clear ok flag */
- ret |= XADPIF_OK;
-
- return ret;
- }
-
- void ShowTexts(struct xadTextInfo *ti)
- {
- ULONG i = 1, j;
- BPTR fh;
- STRPTR a;
-
- fh = Output();
-
- while(!CTRL_C && ti)
- {
- if(ti->xti_Size && ti->xti_Text)
- {
- Printf("»»»» TEXTINFO %ld ««««\n", i);
- a = ti->xti_Text;
- for(j = 0; !CTRL_C && j < ti->xti_Size; ++j)
- {
- if(isprint(*a) || *a == '\n' || *a == '\t' || *a == '\033')
- FPutC(fh, *a);
- else
- FPutC(fh, '.');
- ++a;
- }
- if(*(--a) != '\n')
- FPutC(fh, '\n');
- }
- ti = ti->xti_Next;
- ++i;
- }
- }
-
- void SaveTexts(struct xadTextInfo *ti, STRPTR name)
- {
- UBYTE namebuf[256];
- ULONG i = 1;
- BPTR fh;
- LONG err = 0;
-
- while(!CTRL_C && ti && !err)
- {
- if(ti->xti_Size && ti->xti_Text)
- {
- sprintf(namebuf, "%s.%ld", name, i);
- if((fh = Open(namebuf, MODE_NEWFILE)))
- {
- if(Write(fh, ti->xti_Text, ti->xti_Size) != ti->xti_Size)
- ++err;
- Close(fh);
- }
- else
- ++err;
- }
- ti = ti->xti_Next;
- ++i;
- }
- if(err)
- Printf("Failed to save information texts.\n");
- }
-