Properly view files with comments now
This commit is contained in:
parent
9aa572c41c
commit
e6df923fe6
|
@ -2,30 +2,6 @@ Unit AViewRAR;
|
||||||
|
|
||||||
{$I M_OPS.PAS}
|
{$I M_OPS.PAS}
|
||||||
|
|
||||||
(* DOES NOT WORK IF FILE HAS COMMENTS... NEED TO READ SKIP ADDSIZE IF NOT $74
|
|
||||||
|
|
||||||
1. Read and check marker block
|
|
||||||
2. Read archive header
|
|
||||||
3. Read or skip HEAD_SIZE-sizeof(MAIN_HEAD) bytes
|
|
||||||
4. If end of archive encountered then terminate archive processing,
|
|
||||||
else read 7 bytes into fields HEAD_CRC, HEAD_TYPE, HEAD_FLAGS,
|
|
||||||
HEAD_SIZE.
|
|
||||||
5. Check HEAD_TYPE.
|
|
||||||
if HEAD_TYPE==0x74
|
|
||||||
read file header ( first 7 bytes already read )
|
|
||||||
read or skip HEAD_SIZE-sizeof(FILE_HEAD) bytes
|
|
||||||
if (HEAD_FLAGS & 0x100)
|
|
||||||
read or skip HIGH_PACK_SIZE*0x100000000+PACK_SIZE bytes
|
|
||||||
else
|
|
||||||
read or skip PACK_SIZE bytes
|
|
||||||
else
|
|
||||||
read corresponding HEAD_TYPE block:
|
|
||||||
read HEAD_SIZE-7 bytes
|
|
||||||
if (HEAD_FLAGS & 0x8000)
|
|
||||||
read ADD_SIZE bytes
|
|
||||||
6. go to 4.
|
|
||||||
*)
|
|
||||||
|
|
||||||
Interface
|
Interface
|
||||||
|
|
||||||
Uses
|
Uses
|
||||||
|
@ -34,6 +10,13 @@ Uses
|
||||||
|
|
||||||
Type
|
Type
|
||||||
RarHeaderRec = Record
|
RarHeaderRec = Record
|
||||||
|
CRC : Word;
|
||||||
|
HdrType : Byte;
|
||||||
|
Flags : Word;
|
||||||
|
Size : Word;
|
||||||
|
End;
|
||||||
|
|
||||||
|
RarFileRec = Record
|
||||||
PackSize : LongInt;
|
PackSize : LongInt;
|
||||||
Size : LongInt;
|
Size : LongInt;
|
||||||
HostOS : Byte;
|
HostOS : Byte;
|
||||||
|
@ -48,12 +31,14 @@ Type
|
||||||
PRarArchive = ^TRarArchive;
|
PRarArchive = ^TRarArchive;
|
||||||
TRarArchive = Object(TGeneralArchive)
|
TRarArchive = Object(TGeneralArchive)
|
||||||
Constructor Init;
|
Constructor Init;
|
||||||
Procedure FindFirst (Var SR : ArcSearchRec); Virtual;
|
Procedure FindFirst (Var SR: ArcSearchRec); Virtual;
|
||||||
Procedure FindNext (Var SR : ArcSearchRec); Virtual;
|
Procedure FindNext (Var SR: ArcSearchRec); Virtual;
|
||||||
Private
|
Private
|
||||||
RAR : RarHeaderRec;
|
RAR : RarFileRec;
|
||||||
Buf : Array[1..12] of Byte;
|
Hdr : RarHeaderRec;
|
||||||
Offset : Word;
|
ArcHdr : Array[1..7] of Byte;
|
||||||
|
NextPos : LongInt;
|
||||||
|
Offset : LongInt;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
|
@ -66,37 +51,49 @@ Procedure TRarArchive.FindFirst (Var SR : ArcSearchRec);
|
||||||
Begin
|
Begin
|
||||||
If Eof(ArcFile) Then Exit;
|
If Eof(ArcFile) Then Exit;
|
||||||
|
|
||||||
BlockRead (ArcFile, Buf[1], 12);
|
BlockRead (ArcFile, ArcHdr[1], 7); // marker header
|
||||||
|
BlockRead (ArcFile, Hdr, SizeOf(Hdr)); // archive header
|
||||||
|
|
||||||
If Buf[10] <> $73 Then Exit;
|
If Hdr.HdrType <> $73 Then Exit;
|
||||||
|
|
||||||
BlockRead (ArcFile, offset, 2);
|
NextPos := FilePos(ArcFile) + Hdr.Size - 7;
|
||||||
BlockRead (ArcFile, Buf[1], 6);
|
|
||||||
|
|
||||||
Seek (ArcFile, FilePos(ArcFile) + (offset - 13));
|
|
||||||
FindNext (SR);
|
FindNext (SR);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Procedure TRarArchive.FindNext (Var SR: ArcSearchRec);
|
Procedure TRarArchive.FindNext (Var SR: ArcSearchRec);
|
||||||
Begin
|
Begin
|
||||||
|
Repeat
|
||||||
|
Seek (ArcFile, NextPos);
|
||||||
|
|
||||||
If Eof(ArcFile) Then Exit;
|
If Eof(ArcFile) Then Exit;
|
||||||
|
|
||||||
BlockRead (ArcFile, Buf[1], 5);
|
BlockRead (ArcFile, Hdr, SizeOf(Hdr));
|
||||||
|
|
||||||
If Buf[3] <> $74 Then Exit;
|
If (Hdr.HdrType = $74) Then Begin
|
||||||
|
|
||||||
BlockRead (ArcFile, Offset, 2);
|
|
||||||
BlockRead (ArcFile, RAR, SizeOf(RAR));
|
BlockRead (ArcFile, RAR, SizeOf(RAR));
|
||||||
BlockRead (ArcFile, SR.Name[1], RAR.FNSize);
|
BlockRead (ArcFile, SR.Name[1], RAR.FNSize);
|
||||||
|
|
||||||
SR.Name[0] := Chr(RAR.FNSize);
|
SR.Name[0] := Chr(RAR.FNSize);
|
||||||
|
|
||||||
|
If RAR.Attr = 16 Then SR.Attr := $10;
|
||||||
|
|
||||||
SR.Time := RAR.Time;
|
SR.Time := RAR.Time;
|
||||||
SR.Size := RAR.Size;
|
SR.Size := RAR.Size;
|
||||||
|
|
||||||
If RAR.Attr = 16 Then SR.Attr := $10;
|
NextPos := NextPos + Hdr.Size + RAR.PackSize;
|
||||||
|
|
||||||
Seek(ArcFile, FilePos(ArcFile) + (Offset - (SizeOf(RAR) + 7 + Length(SR.Name))) + RAR.PackSize);
|
Break;
|
||||||
|
End Else Begin
|
||||||
|
If (Hdr.Flags And $8000) = 0 Then
|
||||||
|
NextPos := NextPos + Hdr.Size
|
||||||
|
Else Begin
|
||||||
|
BlockRead (ArcFile, Offset , 4);
|
||||||
|
|
||||||
|
NextPos := NextPos + Hdr.Size + Offset;
|
||||||
|
End;
|
||||||
|
End;
|
||||||
|
Until Eof(ArcFile);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
End.
|
End.
|
Loading…
Reference in New Issue