home *** CD-ROM | disk | FTP | other *** search
- #pragma pack(2)
-
- #include <Common.h>
- #include <System/SysAll.h>
- #include <UI/UIAll.h>
- #include <ExgMgr.h>
- #include <System/FileStream.h>
- #include <System/SysEvtMgr.h>
- #include "boxer.h"
-
- #include <Unix/sys_types.h>
-
- #include "stringil.h"
- #include "stdio2.h"
-
- /* this is the callback stuff from Callback.h by ian in O'Reilly's book */
- register void *reg_a4 asm("%a4");
-
- #define CALLBACK_PROLOGUE \
- void *save_a4 = reg_a4; asm("move.l %%a5,%%a4; sub.l #edata,%%a4" : :)
-
- #define CALLBACK_EPILOGUE reg_a4 = save_a4
-
- static int toprow = 0;
- static int maxrow = 0;
- static int selection = -1;
-
-
- static char *filelist;
- static char *filecard;
- static long int *filedisp;
- FileHand archfd;
-
-
- /* **************************************************************************** */
-
- static void TableDrawCell(VoidPtr tableP, Word row, Word column,
- RectanglePtr bounds)
- {
- char *c;
- c = (char *) TblGetRowData(tableP, row);
- WinDrawChars(c, strlen(c), bounds->topLeft.x, bounds->topLeft.y);
- }
-
- /* **************************************************************************** */
-
- int unzipdir(FileHand infile, char *dir, long int *loc);
- int untardir(FileHand fd, char *dir, long int *loc);
-
- static void scandbs()
- {
- LocalID lid;
- UInt16 cardno, attr;
- UInt32 type, crea, disp, i;
- char tp[40];
-
- maxrow = 0;
-
- disp = 0;
- DmSet(filelist, 0, 2, 0);
-
- maxrow = 0;
- for (cardno = 0; cardno < MemNumCards(); cardno++) {
- for (i = 0; i < DmNumDatabases(cardno); i++) {
- lid = DmGetDatabase(cardno, i);
- DmDatabaseInfo(cardno, lid, tp, &attr, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, &type, &crea);
- if (!(attr & dmHdrAttrStream) || type != 'DATA')
- continue;
- if (crea != 'NZIP' && crea != 'BRWS' && crea != 'ATCH' && crea != 'BOXR')
- continue;
-
- DmWrite(filelist, disp, tp, strlen(tp) + 1);
- disp += strlen(tp) + 1;
- DmWrite(filedisp, maxrow * 4, &i, 4);
- DmWrite(filecard, maxrow * 2, &cardno, 2);
- maxrow++;
- }
- }
- DmSet(filelist, disp, 2, 0);
- selection = -1;
- }
-
- /* **************************************************************************** */
-
- int unzip(FileHand infile, long int loc);
- int untar(FileHand fd, long int loc);
- int MakeDoc(char *name, FileHand fd, int destruct);
- int MakeDatabase(FileHand fd, int destruct);
-
- void settable()
- {
- TablePtr tptr;
- Word n;
- FormPtr frm;
- UInt top;
- Word row, numRows;
- char *c;
- ScrollBarPtr bar;
-
-
- WinEraseWindow();
- frm = FrmGetActiveForm();
- tptr = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, maintable));
- top = toprow;
- numRows = TblGetNumberOfRows(tptr);
- c = filelist;
- n = top;
- while (n-- && *c)
- c += strlen(c) + 1;
-
- for (n = 0; n < 1; n++)
- TblSetColumnUsable(tptr, n, true);
-
- for (row = 0; row < numRows; row++, top++) {
-
- if (*c) {
- TblSetRowData(tptr, row, (ULong) c);
- c += strlen(c) + 1;
- }
-
- if (top < maxrow) {
- TblSetRowSelectable(tptr, row, true);
-
- for (n = 0; n < 1; n++) {
- TblSetItemStyle(tptr, row, n, customTableItem);
- TblSetCustomDrawProcedure(tptr, n, TableDrawCell);
- }
- TblMarkRowInvalid(tptr, row);
- } else
- TblSetRowUsable(tptr, row, false);
- }
- // selection = -1; //Until I can get highlighting to work
-
- // TblHasScrollBar (tptr, true);
-
- bar = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, scrl));
-
- if (maxrow <= numRows)
- SclSetScrollBar(bar, 0, 0, 0, 10);
- else
- SclSetScrollBar(bar, toprow, 0, maxrow - numRows, numRows);
-
- FrmDrawForm(frm);
-
- if( selection != -1 )
- TblSelectItem (tptr, selection - toprow, 0);
-
- }
-
- /* **************************************************************************** */
-
- void dopage(int down)
- {
- TablePtr tptr;
- Word n;
- FormPtr frm;
-
- frm = FrmGetActiveForm();
- tptr = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, maintable));
- n = TblGetNumberOfRows(tptr);
- toprow += n * (((down) << 1) - 1);
- if ((toprow + n) >= maxrow)
- toprow = maxrow - n;
- if (toprow < 0)
- toprow = 0;
-
- FrmGotoForm(FrmGetActiveFormID());
- }
-
- /* **************************************************************************** */
-
- void doscroll()
- {
- TablePtr tptr;
- Word n;
- FormPtr frm;
- ScrollBarPtr bar;
- Word v, mn, mx, ps;
-
- frm = FrmGetActiveForm();
- bar = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, scrl));
- SclGetScrollBar(bar, &v, &mn, &mx, &ps);
- tptr = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, maintable));
- n = TblGetNumberOfRows(tptr);
- toprow = v;
- if ((toprow + n) >= maxrow)
- toprow = maxrow - n;
- if (toprow < 0)
- toprow = 0;
-
- FrmGotoForm(FrmGetActiveFormID());
- }
-
- /* **************************************************************************** */
-
- /* HANDLERS */
-
- int basehand(EventPtr event)
- {
- switch (event->eType) {
-
- case frmOpenEvent:
- settable();
- return 1;
-
- case sclExitEvent:
- doscroll();
- return 1;
-
- case keyDownEvent:
- if (event->data.keyDown.chr != pageUpChr &&
- event->data.keyDown.chr != pageDownChr) return 0;
-
- dopage(event->data.keyDown.chr == pageDownChr);
- return 1;
- default:
- return 0;
- }
-
- }
-
- /* **************************************************************************** */
-
- static Boolean UnzipH(EventPtr event)
- {
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
- eid = event->data.ctlEnter.controlID;
- switch (eid) {
- case bunzip:
- if (selection == -1)
- break;
- WinEraseWindow();
- unzip(archfd, filedisp[selection]);
- FrmGotoForm(unzipform);
- return 1;
- case bexit:
- FileClose(archfd);
- scandbs();
- FrmGotoForm(decomform);
- return 1;
- }
- return 0;
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- break;
- default:
- return 0;
- }
-
- }
-
- /* **************************************************************************** */
-
- static Boolean UntarH(EventPtr event)
- {
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
- eid = event->data.ctlEnter.controlID;
-
- switch (eid) {
- case buntar:
- if (selection == -1)
- return 1;
-
- WinEraseWindow();
- untar(archfd, filedisp[selection]);
- FrmGotoForm(untarform);
- return 1;
-
- case bexit:
- FileClose(archfd);
- scandbs();
- FrmGotoForm(decomform);
- return 1;
- }
-
- return 0;
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- default:
- return 0;
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean MainH(EventPtr event)
- {
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
- eid = event->data.ctlEnter.controlID;
-
- switch (eid) {
- case bfile:
- FrmGotoForm(fileform);
- return 1;
- case bdecom:
- FrmGotoForm(decomform);
- return 1;
- case binst:
- FrmGotoForm(instform);
- return 1;
- default:
- return 0;
- }
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- default:
- return 0;
-
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean DecomH(EventPtr event)
- {
- Word n;
- LocalID lid;
- FileHand fd;
- char name[256];
- UInt32 type, crea;
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
-
- eid = event->data.ctlEnter.controlID;
- if (eid == bexit) {
- FrmGotoForm(mainform);
- return 1;
- }
- if (selection == -1)
- return 1;
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeUpdate | fileModeAnyTypeCreator, NULL);
- WinEraseWindow();
-
- switch (eid) {
- case bunzip:
- archfd = fd;
- n = unzipdir(archfd, filelist, filedisp);
- if (n) {
- maxrow = n;
- FrmGotoForm(unzipform);
- } else {
- FrmAlert(4000);
- FileClose(archfd);
- scandbs();
- FrmGotoForm(decomform);
- }
- return 1;
-
- case buntar:
- archfd = fd;
- n = untardir(archfd, filelist, filedisp);
- if (n) {
- maxrow = n;
- FrmGotoForm(untarform);
- } else {
- FrmAlert(4000);
- FileClose(archfd);
- scandbs();
- FrmGotoForm(decomform);
- }
- return 1;
-
- case bgunzip:
- n = unzip(fd, 0);
- FileClose(fd);
- scandbs();
- FrmGotoForm(decomform);
- return 1;
-
- case bgzip:
- FrmGotoForm(gzipform);
- return 1;
-
- case bripunzip:
-
- WinEraseWindow();
-
- n = unzipdir(fd, filelist, filedisp);
- if( n ) {
- n = unzip(fd, -1);
-
- FileClose(fd);
- if (n != -1)
- FileDelete(filecard[selection], name);
-
- // Now install the files in filelist.
-
- }
- else {
- WinEraseWindow();
- n = untardir(fd, filelist, filedisp);
- if (n)
- n = untar(fd, -1);
-
- FileClose(fd);
- if (n != -1)
- FileDelete(filecard[selection], name);
-
- // Now install the files in filelist.
-
- }
-
- scandbs();
- FrmGotoForm(decomform);
- return 1;
-
- default:
- return 0;
- }
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- default:
- return 0;
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean CopyH(EventPtr event)
- {
- FormPtr frm;
- FieldPtr textf;
- VoidHand thand;
- VoidPtr tptr;
- UInt32 type, crea, tlen, xlen;
- Word attr;
- FileHand fd, ofd;
- int eid;
- LocalID lid;
- char name[32];
-
- switch (event->eType) {
- case frmOpenEvent:
-
- WinEraseWindow();
- frm = FrmGetActiveForm();
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- thand = MemHandleNew(32);
- DmDatabaseInfo(filecard[selection], lid, tptr =
- MemHandleLock(thand), &attr, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, &type, &crea);
-
- fd = FileOpen(filecard[selection], tptr, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
-
- FileTell(fd, &tlen, NULL);
- FileClose(fd);
-
- strcat(tptr, "-Cpy");
-
- MemHandleUnlock(thand);
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- FldSetTextHandle(textf, (Handle) thand);
- FrmSetFocus(frm, FrmGetObjectIndex(frm, namefld));
- FrmDrawForm(frm);
-
- StrIToA(name, tlen);
- strcat(name, " Bytes in box");
- WinDrawChars(name, strlen(name), 5, 45);
- return 1;
-
- case ctlSelectEvent:
-
- eid = event->data.ctlEnter.controlID;
-
- switch (eid) {
- case bok:
-
- // COPY PREVENT?
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
- FileTell(fd, &tlen, NULL);
-
- frm = FrmGetActiveForm();
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- thand = (VoidHand) FldGetTextHandle(textf);
- ofd = FileOpen(filecard[selection], MemHandleLock(thand), 'DATA', 'BOXR',
- fileModeReadWrite, NULL);
- MemHandleUnlock(thand);
-
- WinEraseWindow();
-
- tptr = MemPtrNew(4096);
-
- crea = tlen;
- WinDrawChars("Copying:", 8, 0, 15);
- while (tlen) {
- RectangleType r = { {0, 30}
- , {0, 15}
- };
-
- type = tlen > 4096 ? 4096 : tlen;
- xlen = FileRead(fd, tptr, 1, type, NULL);
- if (type != xlen)
- break; // ERROR MESSAGE
- FileWrite(ofd, tptr, 1, xlen, NULL);
- tlen -= xlen;
-
- r.extent.x = 160 - (160 * tlen / crea);
- WinDrawRectangle(&r, 0);
-
- }
- FileClose(fd);
- FileClose(ofd);
- MemPtrFree(tptr);
-
- // FALLTHROUGH
-
- case bexit:
- scandbs();
- FrmGotoForm(fileform);
- return 1;
-
- default:
- return 0;
- }
-
- default:
- return 0;
-
- }
- }
-
- /* **************************************************************************** */
-
- extern void gzip( FileHand fd, FileHand ofd);
-
- static Boolean GzipH(EventPtr event)
- {
- FormPtr frm;
- FieldPtr textf;
- VoidHand thand;
- VoidPtr tptr;
- UInt32 type, crea, tlen;
- Word attr;
- FileHand fd, ofd;
- int eid, n;
- LocalID lid;
- char name[32];
-
- switch (event->eType) {
- case frmOpenEvent:
-
- WinEraseWindow();
- frm = FrmGetActiveForm();
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- thand = MemHandleNew(32);
- DmDatabaseInfo(filecard[selection], lid, tptr =
- MemHandleLock(thand), &attr, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, &type, &crea);
-
- fd = FileOpen(filecard[selection], tptr, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
-
- FileTell(fd, &tlen, NULL);
- FileClose(fd);
-
- strcat(tptr, ".gz");
-
- MemHandleUnlock(thand);
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- FldSetTextHandle(textf, (Handle) thand);
- FrmSetFocus(frm, FrmGetObjectIndex(frm, namefld));
- FrmDrawForm(frm);
-
- StrIToA(name, tlen);
- strcat(name, " Bytes in box");
- WinDrawChars(name, strlen(name), 5, 45);
- return 1;
-
- case ctlSelectEvent:
-
- eid = event->data.ctlEnter.controlID;
-
- switch (eid) {
- case bok:
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
- FileTell(fd, &tlen, NULL);
-
- frm = FrmGetActiveForm();
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- thand = (VoidHand) FldGetTextHandle(textf);
- ofd = FileOpen(filecard[selection], MemHandleLock(thand), 'DATA', 'BOXR',
- fileModeReadWrite, NULL);
- MemHandleUnlock(thand);
-
- n = FrmAlert(3000);
-
- if( n )
- FileControl(fileOpDestructiveReadMode, fd, NULL, NULL);
-
- WinEraseWindow();
-
- gzip(fd,ofd);
-
- FileClose(fd);
- FileClose(ofd);
-
- if (n)
- FileDelete(filecard[selection], name);
-
- // FALLTHROUGH
-
- case bexit:
- scandbs();
- FrmGotoForm(fileform);
- return 1;
-
- default:
- return 0;
- }
-
- default:
- return 0;
-
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean InfoH(EventPtr event)
- {
- FormPtr frm;
- FieldPtr textf;
- VoidHand thand;
- VoidPtr tptr;
- UInt32 type, crea, tlen;
- Word attr;
- FileHand fd;
- int eid;
- LocalID lid;
- char name[32];
-
- switch (event->eType) {
- case frmOpenEvent:
-
- WinEraseWindow();
- frm = FrmGetActiveForm();
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- thand = MemHandleNew(32);
- DmDatabaseInfo(filecard[selection], lid, tptr =
- MemHandleLock(thand), &attr, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, &type, &crea);
-
- fd = FileOpen(filecard[selection], tptr, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
-
- FileTell(fd, &tlen, NULL);
- FileClose(fd);
- MemHandleUnlock(thand);
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- FldSetTextHandle(textf, (Handle) thand);
- FrmSetFocus(frm, FrmGetObjectIndex(frm, namefld));
-
- CtlSetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, bbackup)),
- attr & dmHdrAttrBackup);
- CtlSetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, bcopypr)),
- attr & dmHdrAttrCopyPrevention);
- CtlSetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, breadon)),
- attr & dmHdrAttrReadOnly);
-
- FrmDrawForm(frm);
-
- StrIToA(name, tlen);
- strcat(name, " Bytes in box, Type: ");
- name[strlen(name)+4]=0;
- strncat(name, (char *) &crea, 4);
- WinDrawChars(name, strlen(name), 5, 45);
-
- return 1;
-
- case ctlSelectEvent:
-
- eid = event->data.ctlEnter.controlID;
-
- switch (eid) {
-
- case bok:
- frm = FrmGetActiveForm();
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- thand = (VoidHand) FldGetTextHandle(textf);
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
-
- DmDatabaseInfo(filecard[selection], lid, NULL, &attr, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL);
-
- attr &= ~(dmHdrAttrCopyPrevention | dmHdrAttrBackup | dmHdrAttrReadOnly);
-
- if (CtlGetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, bbackup))))
- attr |= dmHdrAttrBackup;
- if (CtlGetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, bcopypr))))
- attr |= dmHdrAttrCopyPrevention;
- if (CtlGetValue(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, breadon))))
- attr |= dmHdrAttrReadOnly;
-
- // will fail if not renamed , or if new name would collide - need to
- // display error msg in latter case.
-
- DmSetDatabaseInfo(filecard[selection], lid, MemHandleLock(thand), NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-
- DmSetDatabaseInfo(filecard[selection], lid, NULL, &attr,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-
- MemHandleUnlock(thand);
-
- // Fallthrough
- case bexit:
- scandbs();
- FrmGotoForm(fileform);
- return 1;
-
-
- case bboxr:
- frm = FrmGetActiveForm();
- textf = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, namefld));
- thand = (VoidHand) FldGetTextHandle(textf);
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- crea = 'BOXR';
- DmSetDatabaseInfo(filecard[selection], lid, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, &crea);
-
- MemHandleUnlock(thand);
- FrmGotoForm(infoform);
- return 1;
-
- default:
- return 0;
- }
-
- default:
- return 0;
-
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean FileH(EventPtr event)
- {
- Word n;
- LocalID lid;
- FileHand fd;
- UInt32 len, type, crea;
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
- eid = event->data.ctlEnter.controlID;
-
- if (eid == bexit) {
- FrmGotoForm(mainform);
- return 1;
- }
-
- if (selection == -1)
- return 1;
-
- switch (eid) {
- case bcpy:
- {
- Word attr;
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, NULL, &attr, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL);
-
- if (attr & dmHdrAttrCopyPrevention) {
- FrmAlert(2100);
- return 1;
- }
- }
- FrmGotoForm(copyform);
- return 1;
-
- case binfo:
- FrmGotoForm(infoform);
- return 1;
-
- case bdelete:
-
- if (FrmAlert(2000))
- return 1;
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- n = DmDeleteDatabase(filecard[selection], lid);
-
- scandbs();
- FrmGotoForm(fileform);
- return 1;
-
- case bbeam:
- {
- VoidPtr px;
- Word err;
- long unsigned int xcnt, outhis, tlen;
- ExgSocketType exgSocket;
- char name[36], buf[256];
- Word attr;
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, &attr, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
-
- if (attr & dmHdrAttrCopyPrevention) {
- FrmAlert(2100);
- return 1;
- }
-
- WinDrawChars(name, strlen(name), 80, 0);
-
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeReadOnly | fileModeAnyTypeCreator, NULL);
- FileTell(fd, &len, NULL);
-
- MemSet(&exgSocket, sizeof(exgSocket), 0);
- exgSocket.description = name;
- exgSocket.name = name;
- exgSocket.length = len;
- exgSocket.target = 'BOXR';
-
- err = ExgPut(&exgSocket);
-
- if (!err) {
- xcnt = 0;
- while (xcnt < len) {
-
- tlen = FileRead(fd, buf, 1, 256, NULL);
- xcnt += tlen;
- px = buf;
- while (tlen) {
- outhis = ExgSend(&exgSocket, px, tlen, &err);
- if (err)
- break;
- tlen -= outhis;
- px += outhis;
- }
-
- }
- FileClose(fd);
- EvtResetAutoOffTimer();
-
- ExgDisconnect(&exgSocket, err);
- }
- default:
- return 0;
- }
-
- }
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- default:
- return 0;
- }
- }
-
- /* **************************************************************************** */
-
- static Boolean InstH(EventPtr event)
- {
- Word n;
- LocalID lid;
- FileHand fd;
- char name[256];
- UInt32 type, crea;
- int eid;
-
- if (basehand(event))
- return 1;
-
- switch (event->eType) {
-
- case ctlSelectEvent:
-
- eid = event->data.ctlEnter.controlID;
-
- if (eid == bexit) {
- FrmGotoForm(mainform);
- return 1;
- }
-
- if (selection == -1)
- return 1;
-
- switch (eid) {
-
- case btodoc:
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeUpdate | fileModeAnyTypeCreator, NULL);
-
- strcat(name, ".box");
-
- n = FrmAlert(3000);
-
- WinEraseWindow();
-
- MakeDoc(name, fd, n);
- FileClose(fd);
- if (n) {
- name[strlen(name) - 4] = 0;
- FileDelete(filecard[selection], name);
- }
- scandbs();
- FrmGotoForm(instform);
-
- return 1;
-
- case binstall:
-
- lid = DmGetDatabase(filecard[selection], filedisp[selection]);
- DmDatabaseInfo(filecard[selection], lid, name, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, &type, &crea);
- fd = FileOpen(filecard[selection], name, type, crea,
- fileModeUpdate | fileModeAnyTypeCreator, NULL);
-
- n = FrmAlert(3000);
- WinEraseWindow();
- MakeDatabase(fd, n);
- FileClose(fd);
- if (n)
- FileDelete(filecard[selection], name);
-
- scandbs();
- FrmGotoForm(instform);
-
- return 1;
- default:
- return 0;
- }
-
- case tblSelectEvent:
- selection = toprow + event->data.tblSelect.row;
- return 1;
- default:
- return 0;
- }
-
- }
-
- /* **************************************************************************** */
-
- int dirtyp;
-
- DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- short err;
- int formID;
- FormPtr form = NULL;
- EventType event;
- LocalID lid;
- DmOpenRef scratch;
- Word dbrec;
- VoidHand hand;
-
- if (cmd == sysAppLaunchCmdExgAskUser) {
- ExgAskParamPtr exgP = (ExgAskParamPtr) cmdPBP;
- exgP->result = exgAskDialog; /* Dialog, Ok, Cancel */
- return 0;
- } else if (cmd == sysAppLaunchCmdExgReceiveData) {
- ExgSocketPtr exgSocketP = (ExgSocketPtr) cmdPBP;
- unsigned char buf[256];
- int inthis;
- FileHand fd;
-
- err = ExgAccept(exgSocketP);
- fd = FileOpen(0, exgSocketP->name, 'DATA', 'BOXR', fileModeReadWrite, NULL);
-
- if ((launchFlags & sysAppLaunchFlagSubCall)) {
- CALLBACK_PROLOGUE;
- dirtyp++;
- CALLBACK_EPILOGUE;
- }
-
- if (err)
- return err;
-
- inthis = 1;
- while (inthis) {
- inthis = ExgReceive(exgSocketP, buf, 256, &err);
- if (err)
- break;
- FileWrite(fd, buf, 1, inthis, NULL);
- }
- FileClose(fd);
- ExgDisconnect(exgSocketP, err);
- EvtResetAutoOffTimer();
- return 0;
- } else if (cmd != sysAppLaunchCmdNormalLaunch)
- return 0;
-
- toprow = 0;
- dirtyp = 1;
-
- //SCRATCHPAD
-
- lid = DmFindDatabase(0, "BOXERSCRATCHPAD");
- if (lid)
- DmDeleteDatabase(0, lid);
- DmCreateDatabase(0, "BOXERSCRATCHPAD", 'BOXR', 'DATA', false);
- lid = DmFindDatabase(0, "BOXERSCRATCHPAD");
- scratch = DmOpenDatabase(0, lid, dmModeReadWrite);
- if (!scratch)
- ErrDisplay("Could not create scratchpad");
- dbrec = 0;
- hand = DmNewRecord(scratch, &dbrec, 8192);
- filelist = MemHandleLock(hand);
- hand = DmNewRecord(scratch, &dbrec, 4096);
- filecard = MemHandleLock(hand);
- hand = DmNewRecord(scratch, &dbrec, 2048);
- filedisp = MemHandleLock(hand);
-
- do {
- if (dirtyp) {
- scandbs();
- FrmGotoForm(mainform);
- dirtyp = 0;
- }
-
- EvtGetEvent(&event, -1);
-
- if (selection < toprow || selection > maxrow || selection > toprow + 10)
- selection = -1;
-
- if (SysHandleEvent(&event))
- continue;
- if (MenuHandleEvent((void *) 0, &event, &err))
- continue;
- if (event.eType == frmLoadEvent) {
- formID = event.data.frmLoad.formID;
- form = FrmInitForm(formID);
- FrmSetActiveForm(form);
- switch (formID) {
-
- default:
-
- case mainform:
- FrmSetEventHandler(form, MainH);
- break;
- case fileform:
- FrmSetEventHandler(form, FileH);
- break;
- case decomform:
- FrmSetEventHandler(form, DecomH);
- break;
- case instform:
- FrmSetEventHandler(form, InstH);
- break;
- case unzipform:
- FrmSetEventHandler(form, UnzipH);
- break;
- case untarform:
- FrmSetEventHandler(form, UntarH);
- break;
- case copyform:
- FrmSetEventHandler(form, CopyH);
- break;
- case gzipform:
- FrmSetEventHandler(form, GzipH);
- break;
- case infoform:
- FrmSetEventHandler(form, InfoH);
- break;
- }
-
- }
- if (form)
- FrmDispatchEvent(&event);
- } while (event.eType != appStopEvent);
-
- MemPtrUnlock(filedisp);
- MemPtrUnlock(filecard);
- MemPtrUnlock(filelist);
- DmCloseDatabase(scratch);
- DmDeleteDatabase(0, lid);
- return 0;
- }
-