TIP: Click on subject to list as thread! ANSI
echo: maximus
to: DON GUY
from: GREG MACLELLAN
date: 1997-09-08 16:22:00
subject: RAR

 DG> Is it possible to add RAR support into the View Archive 
 DG> Contents option of the file menu?
there's a mex file to do that:
/////////////////////////////////////////////////////////////////////////////
//
// File: viewrar.mex
//
// Desc: Displays the contents of an RAR style archive
// Written by: Herman Freeman 1:308/90
// derivative from the freeware source for UNRAR by Eugene Roshal
/////////////////////////////////////////////////////////////////////////////
//This command does not support wildcards
#include 
#include 
#define ARCH_SIGN              "\x52\x61\x72\x21\x1a\x07"
#define ARCH_WHICH             "Display the contents of which archive? "
#define ARCH_TITLE             " Name                Size   Packed   Date   T
ime"
#define ARCH_LINE              "---------------------------------------------
----"
  unsigned int:   HeadCRC;
  unsigned char:  HeadType;
  unsigned int:   Flags;
  unsigned int:   HeadSize;
  unsigned long:  PackSize;
  unsigned long:  UnpSize;
  unsigned char:  HostOS;
  unsigned long:  FileCRC;
  unsigned int:   FYear;
  unsigned int:   FMonth;
  unsigned int:   FDay;
  unsigned int:   FHour;
  unsigned int:   FMin;
  unsigned int:   FSec;
  unsigned char:  UnpVer;
  unsigned char:  Method;
  unsigned int:   NameSize;
  unsigned long:  FileAttr;
  unsigned long:  NBPos,nblock;
  string:         Afname;
unsigned long hextoul(string: strinp, int: ofst)
{
  unsigned long: wlong;
  wlong := (unsigned char)strinp[ofst+3];
  wlong := (wlong shl 8)+(unsigned char)strinp[ofst+2];
  wlong := (wlong shl 8)+(unsigned char)strinp[ofst+1];
  return (wlong shl 8)+(unsigned char)strinp[ofst];
}
int hextoi(string: strinp, int: ofst)
{
  int: wint;
  wint := (int)strinp[ofst+1];
  return (wint shl 8) + (int)strinp[ofst];
}
unsigned int hextoui(string: strinp, int: ofst)
{
  unsigned int: wint;
  wint := (unsigned char)strinp[ofst+1];
  return (wint shl 8) + (unsigned char)strinp[ofst];
}
unsigned long get_fblk(int: fh)
{
  unsigned long: rc;
  string: gtmp;
    rc := read(fh,gtmp,31);  
    HeadType := gtmp[2];
    Flags    := hextoui(gtmp,3);
    HeadSize := hextoui(gtmp,5);
    PackSize := hextoul(gtmp,7);
    UnpSize  := hextoul(gtmp,11);
    HostOS   := gtmp[15];
    FileCRC  := hextoul(gtmp,16);
    FHour    := (hextoui(gtmp,20) shr 11);
    if (FHour < 0) FHour := FHour - 65504;
    FMin     := ((hextoui(gtmp,20) & 0x07e0) shr 5);
    FSec     := (hextoui(gtmp,20) & 0x002f);
    FYear    := (hextoui(gtmp,22) shr 9)+80;
    FMonth   := ((hextoui(gtmp,22) & 0x01e0) shr 5);
    FDay     := (hextoui(gtmp,22) & 0x001f);
    UnpVer   := gtmp[24];
    Method   := gtmp[25];
    NameSize := hextoui(gtmp,26);
    FileAttr := hextoul(gtmp,28);
    NBPos := tell(fh) - rc + HeadSize;
    if (Flags & 0x8000) NBPos := NBPos + PackSize;
    if (rc = 0 or HeadType  0x74)
    {
      seek(fh,NBPos,SEEK_SET);
    }
  if (rc > 0 and HeadType = 0x74)
  {
    read(fh,Afname,NameSize);  
    seek(fh,NBPos,SEEK_SET);
    rc := rc + NameSize;
    if (HeadType = 0) return(0);
  }
  return(rc);
}
unsigned int get_arch(int: fh)
{
  int:    rc;
  string: ftmp;
  seek(fh,8,SEEK_SET);
  rc := read(fh,ftmp,13);
  seek(fh,hextoui(ftmp,5)+8,SEEK_SET);
  return hextoui(ftmp,5);
}
void main()
{
  int: Afs, I, fd, rc;
  long: fsize;
  string: filespec, tmp;
  // Get filespec from user (from stacked commands buffer is ok too)
  if (input_str(filespec,INPUT_WORD,0,0,COL_WHITE ARCH_WHICH)=0)
  {
   // No Input, Quit
    menu_cmd(MNU_PRESS_ENTER,"");
    return;
  }
  fd := open(farea.downpath+filespec,IOPEN_READ|IOPEN_BINARY);
  if (fd = -1)
  {
    print(COL_WHITE,"Can't find Archive ",farea.downpath+filespec,"\n");
    return;
  }
  rc := read(fd,tmp,6);
  if (tmp  ARCH_SIGN)
  {
    close(fd);
    input := input + filespec ;
    menu_cmd(MNU_FILE_CONTENTS,"");
    return;
  }
  fsize := filesize(farea.downpath+filespec);
  print("\n");
  print("Contents of Archive ",filespec,"\n\n");
  print(ARCH_TITLE,"\n");
  print(ARCH_LINE,"\n");
  nblock := get_arch(fd);               // position to read first file block
  if (nblock = 0)
  {
    print ("exit");
    return;
  }
  while(get_fblk(fd) > 0)
  {
    if (nblock >= fsize) return;
    if (HeadType = 0x74)
    {
    Afs := 0;
    for ( I := 1 ; I  strlen(Afname) ; I := I + 1 )
      {
        if (substr(Afname,I,1) = "\\" or substr(Afname,I,1) = "/") Afs := I;
      }
      Afname := substr(Afname,Afs+1,strlen(Afname)-Afs+1);
      print(strpad(Afname,13,' '),strpadleft(ultostr(UnpSize),12,' '));
      print(strpadleft(ultostr(PackSize),9,' ')," ");
      print(FYear,"/",strpadleft(ultostr(FMonth),2,'0'),"/");
      print(strpadleft(ultostr(FDay),2,'0')," ");
      print(strpadleft(ultostr(FHour),2,'0'),":");
      print(strpadleft(ultostr(FMin),2,'0'));
      print("\n");
    }
  }
  close(fd);
  print("\n");
}
-------
ttyl, greg
--- Maximus/2 3.01
---------------
* Origin: * Chaos BBS * 6i3.389.O8i6 * Kingston, ON! (1:249/174)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.