{$I-,F+,O+,X+}
unit FMInfo;

interface

uses FileMngr;

procedure ReadInfoPrim(FManager: PPanel);

implementation

uses Dos, Objects, Drivers, Views, PanelRec, FMAbort, ArcV, Archives,
  DirPrim, Disks, HeapUMB, LFN, DosTools, Keyboard, TPString, Commands,
  Defaults;

type
  PArcDirInfo =	^TArcDirInfo;
  TArcDirInfo =	record
    Name: PString;
    Dir: PString;
    Panel: PPanel;
  end;

procedure ArchiveLineInfo(ALine: FNameStr; Time, OrgSize, Size:	Longint);
begin
  if (KbdStatus	= 1) and FMAbortAction then ArcEnd := True;
  if (ALine = '') or (TPString.Upcase(ALine[1]) in ['D', 'U']) then Exit;
  if ALine[Length(ALine)] = '\'	then Dec(ALine[0]);
  ALine[1] := '\';
  with PArcDirInfo(ArchiveInfoPtr)^ do
    if JustPathName(Name^ + ALine) = Dir^ then
    begin
      Panel^.DirBytes := Panel^.DirBytes + Size;
      Inc(Panel^.NumFiles);
    end;
end;

procedure ArchiveReadInfoPrim(FManager:	PPanel;
  const	DosName, ArcName, Dir: FNameStr);
var
  Id, Status: Byte;
  P: PArcDirInfo;
  SR: SearchRec;
begin
  ArchiveLineProc := ArchiveLineInfo;
  ArchiveCommentList := FManager^.Dirinfo;
  GetMem(P, SizeOf(TArcDirInfo));
  P^.Name := @ArcName;
  P^.Dir := @Dir;
  P^.Panel := FManager;
  ArchiveInfoPtr := P;
  ReadArchive(DosName, Id, SR, Status);
  if (Status = arcNotIdentified) and FManager^.Opposite^.InArchive then
  begin
    TheArchiver	:= FManager^.Opposite^.Archiver;
    ReadUserArchive(DosName, Id, False,	True, Status);
  end;
  FreeMem(P, SizeOf(TArcDirInfo));
  Inc(FManager^.NumFiles);
end;

procedure ReadInfoPrim(FManager: PPanel);
var
  ClusterSize, I, L: Longint;
  F: lText;
  SR: lSearchRec;
  S, SS: String;
begin
  with FManager^ do
  begin
    Opposite^.GetListDir(S);
    FailSysErrors := True;
    TotalBytes := FDiskSize(Byte(S[1]) - $40);
    if TotalBytes < 0 then TotalBytes := 0;
    BytesFree := FDiskFree(Byte(S[1]) - $40);
    if BytesFree < 0 then BytesFree := 0;
    ClusterSize	:= GetClusterSize(Byte(S[1]) - $40);
    NumFiles :=	0;
    DirBytes :=	0;
    if Opposite^.InArchive then	ArchiveReadInfoPrim(FManager,
      Opposite^.Archiver^.DosName^, Opposite^.Archiver^.ArcName^, S)
    else
    begin
      lFindFirst(S + '\*.*', AnyFile and not VolumeID, SR);
      FailSysErrors := False;
      while DosError = 0 do
      begin
	if SR.SR.Attr and Directory = 0 then
	begin
	  I := SR.SR.Size div ClusterSize;
	  L := I * ClusterSize;
	  if L < SR.SR.Size then
	    DirBytes := DirBytes + L + ClusterSize
	  else DirBytes := DirBytes + L;
	  Inc(NumFiles);
	end
	else if	SR.SR.Name[1] <> '.' then Inc(NumFiles);
	lFindNext(SR);
      end;
      lFindClose(SR);
      if S[0] >	#2 then	Inc(NumFiles);
      Inc(S[0]);
      S[Length(S)] := '\';
      SetFirstFoundName(DirinfoNames, S);
      if S <> '' then
      begin
	lAssignText(F, S);
	FailSysErrors := True;
	Reset(F.T);
	FailSysErrors := False;
	if IOResult = 0 then
	begin
	  if not IsDevice(TextRec(F.T).Handle) then
	    while not Eof(F.T) and (Dirinfo^.Count < 255) do
	    begin
	      Readln(F.T, SS);
	      SS := Detab(SS, 8);
	      TrailTrim(SS);
{	      Dirinfo^.Insert(NewStr(SS));}
	      Dirinfo^.Insert(NewStrUMB(SS));
	    end;
	  Close(F.T);
	  InOutRes := 0;
	end;
      end;
    end;
    UpdateDirinfoRanges;
    PPanelWindow(Owner)^.GetCurrentPanel;
    if (State and (sfSelected +	sfActive) = (sfSelected	+ sfActive)) or
       (PPanelWindow(Owner)^.CurrentPanel = FManager) then
      Message(Owner, evBroadcast, cmNewPrompt, @S)
    else PWindow(Owner)^.Frame^.DrawView;
  end;
end;

end.
