(* Fileareas.  Alot needs to be finished here.  Downloading and batchlist *)
(* needs to finished, and lots of other stuff *)

unit filearea;
interface
uses dos,crt,io,genstr,records,linklist,pullbar,
     archive,filehandle,protcomm;

procedure addfilearea;
procedure upload;
procedure arealist;
procedure listfiles;
procedure fileareaedit;
procedure massupload(command:byte);
procedure batchlist;
procedure download;
implementation

var fnum:longint;


procedure fileareaedit;
var p:pullmoderec;
    x,y:byte;
    FA:FILE{ filearearec};
    FI:FILEAREAREC;
    FL:FILE;
    FR:FILELISTREC;
    ca:longint;
begin
ca:=0;

if nassign(fa,config.data_dir+'filearea.dat')=false then
                    begin
                    fillchar(fi,sizeof(fi),#0);
                    FI.NAME:='New File Area';
                    fi.path:='C:\MISC\';
                    nwrite(fa,fi,sizeof(fi));
                    nreset(fa);
                    END;

{nassign(fa,config.data_dir+'filearea.dat');}
printfile(config.textfile_dir+'fae.ans',basicmci,false);
p.onstring[1]:='|B1|15 A ';
p.onstring[2]:='|B1|15 B ';
p.onstring[3]:='|B1|15 C ';
p.onstring[4]:='|B1|15 D ';
p.onstring[5]:='|B1|15 E ';
p.onstring[6]:='|B1|15 ] ';
p.onstring[7]:='|B1|15 [ ';
p.onstring[8]:='|B1|15 ! ';
p.onstring[9]:='|B1|15 K ';
p.onstring[10]:='|B1|15 Q ';
p.offstring[1]:='|B0|15 A ';
p.offstring[2]:='|B0|15 B ';
p.offstring[3]:='|B0|15 C ';
p.offstring[4]:='|B0|15 D ';
p.offstring[5]:='|B0|15 E ';
p.offstring[6]:='|B0|15 ] ';
p.offstring[7]:='|B0|15 [ ';
p.offstring[8]:='|B0|15 ! ';
p.offstring[9]:='|B0|15 K ';
p.offstring[10]:='|B0|15 Q ';
for x:=1 to 10 do p.x[x]:=2;
for x:=1 to 10 do p.y[x]:=4+x;
ca:=1;
nread(fa,fi,sizeof(fi));
REPEAT
p.firstoption:=1;
p.choices:=10;
fillchar(fi,sizeof(fi),#0);
GOXY(25,5);
print(fi.name);
GOXY(25,6);
print(fi.path);
GOXY(25,7);
print(fi.filename);
GOXY(25,8);
print(fi.acs);
GOXY(25,9);
print(fi.password);
X:=pullbars(p);
print('|B0|15');
case x of
1:begin; goxy(25,5); editline(fi.name); end;
2:begin; goxy(25,6); editline(fi.path); end;
3:begin; goxy(25,7); editline(fi.filename); end;
4:begin; goxy(25,8); editline(fi.acs); end;
5:begin; goxy(25,9); editline(fi.password); end;
6:begin;
  nseek(Fa,FILEPOS(fa)-sizeof(fi));
  nWRITE(fa,fI,sizeof(fi));
  nread(fa,fi,sizeof(fi));
  if filepos(fa)=filesize(fa) then nseek(fa,0);
  nread(fa,fi,sizeof(fi));
  end;
7:BEGIN;
  nSEEK(Fa,FILEPOS(fa)-sizeof(fi));
  nWRITE(fa,fI,sizeof(fi));
  nread(fa,fi,sizeof(fi));
  if filepos(fa)=1 then nseek(fa,filesize(fa)+1);
  nseek(fa,filepos(fa)-2);
  nread(fa,fi,sizeof(fi));
  end;
8:begin;
  nseek(fa,filesize(fa));
  fillchar(fi,sizeof(Fi),#0);
  nwrite(fa,fi,sizeof(fi));
  end;

end;
UNTIL X=10;
nseek(fa,ca);
nwrite(fa,fi,sizeof(fi));
end;

function dszlogstr (s: string; var dsz: dszrec): boolean;
VAR G:STRING;
begin
  G:='';
  dszlogstr := true;
  fillchar (dsz, sizeof (dsz), 0);
  with dsz do begin
    stat := s [1];
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    size := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    connect := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    avcps := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    errcnt := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    flcnt := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    block := strtoint (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    name := uppercase (copy (s, 1, pred (pos (' ', s))));
    delete (s, 1, pred (pos (' ', s)));
    s := strip ('L', ' ', s);
    serno := strtoint (copy (s, 1, 255));
  end;
end;

function searchfile(var temp:filelistrec):boolean;
var fa:file;
    fi:file;
    i:filearearec;
    o:filelistrec;
    x,y:longint;
begin
nassign(fa,config.data_dir+'filearea.dat');

repeat
fillchar(i,sizeof(i),#0);
nread(fa,i,sizeof(i));
nassign(fi,config.data_dir+i.filename);
searchfile:=false;
repeat
fillchar(o,sizeof(o),#0);
if filesize(fi)<>0 then nread(fi,o,sizeof(o));

if o.filename=temp.filename then
                            begin
                            println('|B0|15');
                            PRINTLN('|01(|09Filefound|01) ');
                            searchfile:=true;
                            nclose(fi);
                            nclose(fa);
                            exit;
                            end;
until eof(fi);
nclose(fi);
until eof(fa);
nclose(fa);
searchfile:=false;
end;

FUNCTION TESTIT(var temp:filelistrec):BOOLEAN;
var x:integer;
BEGIN
findcomp(temp.path+temp.filename);
if ctype=0 then testit:=true;
x:=docompression(3,'',temp.path+temp.filename);
if x=comps[ctype].errorlevel then testit:=true
                             else testit:=false;

END;


FUNCTION getdiz(var temp:filelistrec):BOOLEAN;
var t:text;
    s:string;
    X:INTEGER;
    dizs:string;

begin
    getdiz:=false;
    ASSIGN(T,CONFIG.extract_dir+'FILE_ID.DIZ');
    IF fileexist(CONFIG.extract_dir+'FILE_ID.DIZ') THEN ERASE(T);
    findcomp(temp.path+temp.filename);
    if ctype=0 then begin
                    getdiz:=false;
                    exit;
                    end;
    x:=docompression(2,config.extract_dir+' file_id.diz',temp.path+temp.filename);
    getdiz:=false;
    IF fileEXIST(CONFIG.extract_dir+'FILE_ID.DIZ') THEN reset(t) ELSE EXIT;
    getdiz:=true;
    PRINTLN('|B0|15');
    for x:=1 to 10 do begin
    READLN(T,dizs);
    temp.description[x]:=dizs;
    end;
    ERASE(T);
    CLOSE(T);
end;

procedure getdesc(var a:filelistrec);
  var y:Byte;
  begin
  println('|B0|09');
      for y:=1 to 10 do begin
                        print('|B0|01(|09 Line '+strr(y)+'|01) ');
                        buflen:=50;
                        sreadln(a.description[y]);
                        end;
  end;
                 
function pickprot(a:byte):string;
VAR F:FILE;
    P:PROTOREC;
    PROT:MCIS;
    C:CHAR;
    CS:STRING[1];
begin
if nassign(f,config.data_dir+'protocol.dat')=FALSE then
                    begin
                    nclose(F);
                    pickprot:='ERROR';
                    EXIT;
                    end;
fillchar(prot,sizeof(prot),#0);
PROT[1].MCI:='%PK';
PROT[2].MCI:='%PT';
printfile(Config.Textfile_Dir+'prot.top',PROT,false);
nreset(f);
REPEAT
fillchar(p,sizeof(p),#0);
NREAD(F,P,SIZEOF(P));
PROT[1].STR:=P.KEY;
PROT[2].STR:=P.DESCRIPTION;
IF P.KEY<>'' THEN
printfile(Config.Textfile_Dir+'PROT.mid',PROT,false);
UNTIL EOF(F);
printfile(Config.Textfile_Dir+'PROT.bot',PROT,false);
PRINT('|B0|01(|09Pick Protocol|01) |09> ');
BUFLEN:=1;
sreadln(CS);
                         nreset(F);
                         REPEAT
                         nread(f,p,sizeof(p));
                         IF uppercase(P.KEY)=UPPERCASE(CS) THEN begin
                                                        if a=1 then pickprot:=p.ul;
                                                        if a=2 then pickprot:=p.dl;
                                                        nclose(F);
                                                        exit;
                                                        end;
                         UNTIL EOF(f);
print('|B0|15 protocol error');
nclose(f);
end;

procedure addfilearea;
var f:file;
    fr:filearearec;
begin
ansiclr;
buflen:=40;
println('|01(|09 File Area Adder');
println('');
print('|01(|09Area Name|01) ');
sreadln(fr.name);
if fr.name='' then exit;
print('|01(|09Path|01) ');
sreadln(fr.path);
if fr.path='' then exit;
print('|01(|09Datafile|01) ');
sreadln(fr.filename);
if fr.filename='' then exit;
if fr.path[length(fr.path)]<>'\' then fr.path:=fr.path+'\';
nassign(f,config.data_dir+'filearea.dat');
nseek(f,filesize(F));
nwrite(f,fr,sizeof(fr));
nclose(f);
end;

procedure arealist;
var area:mcis;
    f:file;
    i:filearearec;
    x:integer;
    fa:string[3];
    tx:byte;
    h:file;
    g:filelistrec;
begin
FILLCHAR(AREA,SIZEOF(AREA),#0);
area[1].mci:='%AN';
area[2].mci:='%AD';
area[3].mci:='%AF';
area[4].mci:='%AS';
nassign(f,config.data_dir+'filearea.dat');
x:=1;
printfile(Config.Textfile_Dir+'farea.top',area,false);
repeat
nread(f,i,sizeof(i));
nassign(h,config.data_dir+i.filename);
area[1].str:=strr(x);
area[2].str:=i.name;
area[3].str:=strr(filesize(h) div sizeof(g));
area[4].str:='none';
printfile(Config.Textfile_Dir+'farea.mid',area,false);
inc(X);
nclose(h);
until eof(f);
dec(x);
printfile(Config.Textfile_Dir+'farea.bot',area,false);
PRINT('|B0|12File Area ..-> ');
buflen:=3;
sreadln(fa);
buflen:=255;
if valu(fa) in [1..x] then fnum:=valu(fa);
nCLOSE(f);
end;

FUNCTION Translate(S:String;var temp:filelistrec):String;
VAR I:Byte;
    rate:string;
Begin
    replaceit(s,'%BR',strr(Config.lockbaud));
    replaceit(s,'%CP',strr(config.comport));
    replaceit(s,'%FN',config.work_dir);
    replaceit(s,'@BL','@'+CONFIG.extract_dir+'files.txt');
    Translate:=S;
End;

function MOVEFILE(SOURCE,PLACE,FILENAME:STRING):boolean;
var
  FromF, ToF: file;
  NumRead, NumWritten: Word;
  Buf: array[1..2048] of Char;
begin
  if direxist(place)=false then begin
                                movefile:=false;
                                exit;
                                end;
  movefile:=true;
  PLACE:=PLACE+FILENAME;
  nAssign(FromF, SOURCE); { Open input file }
  nAssign(ToF,PLACE); { Open output file }
  repeat
    system.BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
    system.BlockWrite(ToF, Buf, NumRead, NumWritten);
  until (NumRead = 0) or (NumWritten <> NumRead);
  nClose(FromF);
  nClose(ToF);
end;

function makebatchtext:boolean;
    var f: file;
    fn   : filelistrec;
    t    : text;

begin
nassign(f,config.data_dir+'batch.dat');
assign(t,config.extract_dir+'files.txt');
rewrite(t);
if filesize(F)=0 then begin
                      println('No Files Flagged');
                      makebatchtext:=false;
                      close(f);
                      close(t);
                      exit;
                      end;
makebatchtext:=true;
repeat
nread(f,fn,sizeof(fn));
writeln(fn.path+fn.filename);
writeln(t,fn.path+fn.filename);
until eof(f);
close(t);
close(f);
READKEY;
end;

procedure download;
var protstr:string;
    temp:filelistrec;
begin
 { do check time and credit check here }
 protstr:=pickprot(2);
 protstr:=translate(protstr,temp);
 println('|B0|09Starting Download Now....');
 makebatchtext;
 doexec(config.prot_dir+protstr+' ');
 FlushOut;
 FlushIn;
 if dataavailable then repeat
                       getchar;
                       until dataavailable=false;

end;

procedure upload;

var TEMP   : FILElistREC;
    TEMPF  : FILE;
    fa     : filelistrec;
    NUM    : 1..10;
    f      : file;
    i      : filearearec;
    x      : longint;
    p      : pullmoderec;
    fx     : longint;
    dir    : string;
    DirInfo: SearchRec;
    testr  : boolean;
    y      : byte;
    protstr: string;
    check  : boolean;
    hangupon : boolean;
begin
 check:=true;
 hangupon:=false;
 if localon=false then begin
 print('|B0|01(|09Input Descriptions After Upload|01) ');
 check:=ansiyn('|15|B1 Yes ','|B0|07 Yes ','|15|B1 No ','|B0|07 No ',false);
 println('|B0|15');
 print('|B0|01(|09Hangup After Upload|01) ');
 hangupon:=ansiyn('|15|B1 Yes ','|B0|07 Yes ','|15|B1 No ','|B0|07 No ',false);
 println('|B0|15');

 protstr:=pickprot(1);
 protstr:=translate(protstr,temp);
 clrdir        (config.work_dir);
 Make_Directory(config.work_dir);
 changedir     (config.work_dir);
 println('|B0|09Starting Upload Now....');
 doexec(config.prot_dir+protstr+' ');
 println('|B0|09Upload Done');
 FlushOut;
 FlushIn;
 if dataavailable then repeat
                       getchar;
                       until dataavailable=false;
 changedir(config.lucid_dir);
 NUM:=1;
 FILLCHAR(TEMP,SIZEOF(TEMP),#0);
 fillchar(p,sizeof(p),#0);
 nassign(f,config.data_dir+'filearea.dat');
 delay(400);

 for x:=1 to fnum do nread(F,i,SIZEOF(i));
 nclose(f);
 FindFirst(config.work_dir+'*.*', dos.Archive, DirInfo);
 while DosError = 0 do
 begin
    Println('|B0|01(|09'+dirinfo.name+' found |01)');
    Println('|B0|01(|09Processing '+dirinfo.name+'|01)');
    temp.filename:=dirinfo.name;
    temp.path:=config.work_dir;
    nassign(tempf,CONFIG.work_dir+temp.filename);
    temp.points:=filesize(tempf) div 1024;
    temp.size:=filesize(tempf);
    temp.uploader:=user.alias;
    temp.date:=date;
    temp.sendto:='';
    nclose(tempf);
    if searchfile(temp)=true then begin
                                println('');
                                println('|B0|01(|09Sorry. |15'+temp.filename+'|09 Existed|01)');
                                println('');
                                KILLFILE(CONFIG.work_dir+temp.filename);
                                end ELSE
                           BEGIN
                          println('|B0|01(|09Testing |15'+temp.filename+'|01)');
                          testr:=testit(temp);
                              if testr=false then
                                      begin
                                      println('');
                                      println('|B0|01(|09File Did NOT Pass Test|01)');
                                      println('');
                                      end else
                              println('|B0|01(|09Importing File_id.diz|01)');
                              if getdiz(temp)=false then
                                   begin
                                   println('|B0|15File_Id.diz Not Found');
                                   if check=true then getdesc(temp);
                                   end;
    nassign(f,CONFIG.data_DIR+i.filename);
    nseek(f,filesize(f));
    temp.path:=i.path;
    nwrite(f,temp,sizeof(temp));
    PRINTLN('|B0|15Moving '+temp.filename+' to correct file area.');
    if MOVEFILE(CONFIG.work_dir+temp.filename,temp.PATH,TEMP.FILENAME)=false then
    begin
    println('|B0|15File Moving Error');
    end;

    ERASE(TEMPF);
    NCLOSE(f);
    END;
    FindNext(DirInfo);
    end;
    end else
    begin
    println('|B0|15');
    println('');
    println('');
    println('');
    print('|B0|08Type of Upload ');
    p.choices:=4;
    p.onstring[1] := '|B1|09 Current ';
    p.onstring[2] := '|B1|09 Conference ';
    p.onstring[3] := '|B1|09 All ';
    p.onstring[4] := '|B1|09 Abort ';
    p.offstring[1] := '|B0|09 Current ';
    p.offstring[2] := '|B0|09 Conference ';
    p.offstring[3] := '|B0|09 All ';
    p.offstring[4] := '|B0|09 Abort ';
    p.choices:=4;
    p.firstoption:=1;
    p.x[1]:=16;    p.x[2]:=26;
    p.x[3]:=39;    p.x[4]:=46;
    p.y[1]:=wherey;
    p.y[2]:=wherey;
    p.y[3]:=wherey;
    p.y[4]:=wherey;
    x:=pullbars(p);
    print('|B0|15');
    case x of
    1:massupload(1);
    2:;
    3:begin
      nassign(f,config.data_dir+'filearea.dat');
      fx:=fnum;
      fnum:=0;
      repeat
       nread(f,i,sizeof(i));
       inc(fnum);
       massupload(2);
      until eof(f);
      fnum:=fx;
      nclose(F);
      end;
    4:exit;
    end;
    end;
if hangupon=true then begin
                      println('|B0');
                      println('|B0|09Hanging Up Now.');
                      delay(100);
                      hangup;
                      delay(100);
                      hangup;
                      delay(100);
                      Flushout;
                      FlushIn;
                      loggedoff:=true;
                      end;
Flushout;
FlushIn;
end;

procedure massupload(command:byte);
var turbo    : boolean;
    DirInfo  : SearchRec;
    f        : file;
    fr       : filearearec;
    fl       : filelistrec;
    p        : pullmoderec;
    Y        : integer;
    auto     : boolean;
    ut       : byte;
    typepull : byte;
    option   : byte;
    dummy    : integer;
    testr    : boolean;

begin
    auto:=false;

    if command=1 then begin     {if 1 then it prompts to select type }
                      println('|B0|15');
                      println('');
                      println('');
                      print('|01(|09upload|01) |09File process method: ');
                      fillchar(p,sizeof(p),#0);
                      p.onstring[1]  := '|B1|09 None ';
                      p.onstring[2]  := '|B1|09 Import ';
                      p.onstring[3]  := '|B1|09 Test ';
                      p.onstring[4]  := '|B1|09 Recompress ';
                      p.offstring[1] := '|B0|09 None ';
                      p.offstring[2] := '|B0|09 Import ';
                      p.offstring[3] := '|B0|09 Test ';
                      p.offstring[4] := '|B0|09 Recompress ';
                      p.firstoption:=1;
                      p.choices:=4;
                      p.x[1]:=35;
                      p.x[2]:=45;
                      p.x[3]:=55;
                      p.x[4]:=65;
                      p.y[1]:=wherey;
                      p.y[2]:=wherey;
                      p.y[3]:=wherey;
                      p.y[4]:=wherey;
                      typepull:=pullbars(p);
                      end else
                   begin { else it will test, auto }
                   typepull:=3;
                   auto:=true;
                   ut:=4;
                   end;
print('|B0|15');
nassign(f,config.data_dir+'filearea.dat');
println('');
for dummy:=1 to fnum do nread(f,fr,sizeof(fr));
nclose(F);
nassign(f,config.data_dir+fr.filename);
              PRINTLN('');
              println('');
              println('|B0|01(|09Lucid Mass Upload|01)');
              FindFirst(fr.path+'*.*', dos.Archive, DirInfo);
              print('|B0|07');
              ansiclr;
  while DosError = 0 do
  begin
                  fillchar(fl,sizeof(fl),#0);
                  fl.filename:=dirinfo.name;
                  fl.uploader:=user.alias;
                  fl.path:=fr.path;
                  fl.size:=thefilesize(fl.path+fl.filename);
    if searchfile(fl)=false then
      begin
      println('|B0|15');
      print('|01(|09upload|01) |09Filename|15: '+dirinfo.name);
      { ***** }
      if auto=false then begin { if auto is off then ask}
                         ut:=0;
                         fillchar(p,sizeof(p),#0);
                         p.onstring[1]  := '|B1|09 Add ';
                         p.onstring[2]  := '|B1|09 Skip ';
                         p.onstring[3]  := '|B1|09 Kill ';
                         p.onstring[4]  := '|B1|09 Auto ';
                         p.onstring[5]  := '|B1|09 Quit ';

                         p.offstring[1] := '|B0|09 Add ';
                         p.offstring[2] := '|B0|09 Skip ';
                         p.offstring[3] := '|B0|09 Kill ';
                         p.offstring[4] := '|B0|09 Auto ';
                         p.offstring[5] := '|B0|09 Quit ';
                         p.firstoption:=1;
                         p.choices:=5;
                         p.x[1]:=35;
                         p.x[2]:=45;
                         p.x[3]:=55;
                         p.x[4]:=65;
                         p.x[5]:=73;
                         p.y[1]:=wherey;
                         p.y[2]:=wherey;
                         p.y[3]:=wherey;
                         p.y[4]:=wherey;
                         p.y[5]:=wherey;
                         option:=pullbars(p);
                         print('|B0|15');

                         case option of
                              1: ut:=1;
                              2: ut:=2;
                              3: DeleteFile(fr.path+dirinfo.name);
                              4: BEGIN;
                                 Auto:=true;
                                 UT:=4;
                                 END;
                              5: begin
                                 println('');
                                 println('|B0|01(|09Abort|01) |15Uploading ');
                                 nclose(F);
                                 exit;
                                 end;
                         end;

                         end;
      { ***** }

                    testr:=true;

                    if ut in [1,4] then

                         begin   {if not skipped}

                           case typepull of

                           1: begin;   { none }
                              println('|B0|09');
                              for y:=1 to 10 do
                                  begin
                                  print('|B0|01(|09'+strr(y)+'|01) ');
                                  buflen:=50;
                                  sreadln(fl.description[y]);
                                  end;
                              end;
                           2:begin    { import }
                              testr:=testit(fl);
                              if testr=false then
                                      begin
                                      println('');
                                      println('|B0|01(|09File Did NOT Pass Test|01)');
                                      println('');
                                    end else
                              if getdiz(fl)=false then
                                if auto=false then getdesc(fl);
                             end;
                          3:begin    { test }
                              testr:=testit(fl);
                              if testr=false then
                                      begin
                                      println('');
                                      println('|B0|01(|09File Did NOT Pass Test|01)');
                                      println('');
                                      end else

                              if getdiz(fl)=false then
                              if auto=false then getdesc(fl);
                             end;

                          4: begin { recompress }
                             println('|B0|01(|09Recompressing|01)');
                              testr:=testit(fl);
                              if testr=false then
                                      begin
                                      println('');
                                      println('|B0|01(|09File Did NOT Pass Test|01)');
                                      println('');
                                      end else
                              begin

                   clrdir(config.extract_dir);
                   Make_Directory(config.extract_dir);
                   docompression(2,config.extract_dir,fl.path+fl.filename);
                   changedir(config.extract_dir);
                   docompression(1,'',fl.path+fl.filename);
                   changedir(config.lucid_dir);
                      if getdiz(fl)=false then
                                 if auto=false then getdesc(fl);
                                 end;
                             end;
                       end;
                    if testr=true then begin
                                       nseek(f,filesize(F));
                                       nwrite(f,fl,sizeof(fl));
                                       end;
                    end;
                    end else
                    println('|B0|01(|09File Already Existed|01)');
                    findnext(dirinfo);
                    end;
                    nclose(f);
println('');
println('|B0|01(|09Mass Uploading Finished|01)');
end;


procedure batchlist;
var f    : file;
    bl   : mcis;
    fn   : filelistrec;
    temp : longint;

begin
nassign(f,config.data_dir+'batch.dat');
fillchar(bl,sizeof(bl),#0);
bl[1].mci:='|BF';
bl[2].mci:='|BZ';
bl[3].mci:='|BP';
bl[4].mci:='|BT';
printfile(Config.Textfile_Dir+'batch.top',bl,false);
repeat
nread(f,fn,sizeof(fn));
bl[1].str:=fn.filename;
bl[2].str:=strr(fn.size);
bl[3].str:=strr(fn.points);
{temp:=fn.Size div (connectbaud div 8);}
bl[4].str:=strr(temp div 60)+'min';
if fn.filename<>'' then
printfile(Config.Textfile_Dir+'batch.mid',bl,false);
until eof(f);
printfile(Config.Textfile_Dir+'batch.bot',bl,false);
nclose(F);
end;

procedure addbatch(fn:filelistrec);
var f:file;
begin
nassign(f,config.data_dir+'batch.dat');
nseek(f,filesize(F));
nwrite(f,fn,sizeof(fn));
nclose(F);
end;

function removebatch(fn:filelistrec):boolean;
var f:file;
    temp:filelistrec;
    x:integer;
begin
nassign(f,config.work_dir+'batch.dat');
x:=0;
if filesize(F)=0 then begin
                      removebatch:=false;
                      nclose(F);
                      exit;
                      end;
repeat
nseek(f,x);
nread(f,temp,sizeof(temp));
if uppercase(temp.filename)=uppercase(fn.filename) then begin
                                     nseek(f,x);
                                     fillchar(temp,sizeof(temp),#0);
                                     nwrite(f,temp,sizeof(temp));
                                     nclose(F);
                                     removebatch:=true;
                                     exit;
                                     end;
inc(x);
until eof(f);
nclose(F);
removebatch:=false;
end;

procedure listfiles;

type prec=record  { this is the left,right,up, down pullbar rec }
     x       : array[1..25] of 1..80;
     y       : array[1..25] of 1..25;
     fore,
     back    : array[1..25] of Byte;
     on,
     off     : array[1..25] of string[20];
     max     : 0..25;
     cur     : byte;
     old     : byte;
     end;

    var flist    : mcis;        { File listings Mcis }
        h        : prec;        { horizontal pullbars }
        v        : prec;        { vertical pullbars }
        fl       : filelistrec; { file listing record }
        fa       : filearearec; { file area record }
        fcount   : pdllobj;     { file listing link list }
        saveptr  : pointer;     { pointer to save mem alloc }
        listdone : boolean;     { file listing done }
        filelist : file;        { file listings file }
        arealist : file;        { file area file }
        c        : char;        { key char }
        wy       : byte;        { where y counter for display }
        tempint  : integer;     { this is integer for any use }
        page     : integer;     { current listing page }
        fcc      : longint;     { Filelisting current fpos }
        getb     : boolean;     { get file booleaner       }
        fdx      : 0..15;       { file description counter }
        fdt      : 0..15;       { File descroption total   }
        store    : array[1..25] of longint; { this is bad but needed }
        storec   : 0..30;
        nonnp    : boolean;     { if not next or prev }
        tempbyte1: byte;        { temp byte }
        tempbyte2: byte;

procedure clearbox; { Clear the file list box }
    var i:byte;
    begin
    for i:=flist[18].y to flist[19].y do begin
                                         goxy(1,i);
                                         swrite('[0m[K');
                                         end;
    end;

 procedure fileinfo(f:filelistrec); { fileinfo of the file selected }
    var finfo:mcis;
    X:0..10;
    begin
     fillchar(finfo,sizeof(finfo),#0);
     finfo[1].mci:='%FN';     finfo[2].mci:='%SZ';
     finfo[3].mci:='%DT';     finfo[4].mci:='%FP';
     finfo[5].mci:='%UL';     finfo[6].mci:='%UD';
     finfo[7].mci:='%DL';     finfo[8].mci:='%DM';
     finfo[9].mci:='%D1';     finfo[10].mci:='%D2';
     finfo[11].mci:='%D3';    finfo[12].mci:='%D4';
     finfo[13].mci:='%D5';    finfo[14].mci:='%D6';
     finfo[15].mci:='%D7';    finfo[16].mci:='%D8';
     finfo[17].mci:='%D9';    finfo[18].mci:='%DA';
     finfo[1].str:=f.filename;     finfo[2].str:=strr(f.size);
     finfo[5].str:=f.uploader;     finfo[9].str:=f.description [1];
     finfo[10].str:=f.description[2];     finfo[11].str:=f.description[3];
     finfo[12].str:=f.description[4];     finfo[13].str:=f.description[5];
     finfo[14].str:=f.description[6];     finfo[15].str:=f.description[7];
     finfo[16].str:=f.description[8];     finfo[17].str:=f.description[9];
     finfo[18].str:=f.description[10];
     printfile(Config.Textfile_Dir+'fileinfo.ANS',finfo,false);
     for x:=1 to 10 do
      begin
      goxy(finfo[9].x,finfo[9].y);
      print(f.description[x]);
      end;
   end;

function filepullmenu:byte;
var vx,hx  : byte;
    c      : char;
begin
fillchar(h,sizeof(h),0);
printxy(v.x[v.cur],v.y[v.cur],v.on[v.cur],true);
fillchar(h,sizeof(h),#0);
h.on [1]:=foba(flist[11].fore,flist[11].back)+' NEXT ';
h.on [2]:=foba(flist[12].fore,flist[12].back)+' PREV ';
h.on [3]:=foba(flist[13].fore,flist[13].back)+' FLAG ';
h.on [4]:=foba(flist[14].fore,flist[14].back)+' INFO ';
h.on [5]:=foba(flist[15].fore,flist[15].back)+' QUIT ';
h.off[1]:=foba(flist[4] .fore,flist[4] .back)+' NEXT ';
h.off[2]:=foba(flist[5] .fore,flist[5] .back)+' PREV ';
h.off[3]:=foba(flist[6] .fore,flist[6] .back)+' FLAG ';
h.off[4]:=foba(flist[7] .fore,flist[7] .back)+' INFO ';
h.off[5]:=foba(flist[8] .fore,flist[8] .back)+' QUIT ';
h.x[1]:=flist[4].x;
h.x[2]:=flist[5].x;
h.x[3]:=flist[6].x;
h.x[4]:=flist[7].x;
h.x[5]:=flist[8].x;
h.y[1]:=flist[4].y;
h.y[2]:=flist[5].y;
h.y[3]:=flist[6].y;
h.y[4]:=flist[7].y;
h.y[5]:=flist[8].y;
h.max:=5;
h.old:=tempbyte2;
h.cur:=tempbyte2;
for hx:=1 to h.max do printxy(h.x[hx],h.y[hx],h.off[hx],true);
repeat
printxy(h.x[H.old]  ,h.y[H.old]  ,h.off[H.old],true);
printxy(h.x[h.cur],h.y[h.cur],h.on [h.cur],true);
printxy(v.x[V.old] ,v.y[v.old] ,v.off[v.old],true);
printxy(v.x[v.cur],v.y[v.cur],v.on [v.cur],true);
c:=sreadkey;
case c of
'A',#72:begin; v.old:=v.cur; dec(v.cur); if v.cur=0 then v.cur:=v.max; end;
'B',#80:begin; v.old:=v.cur; inc(v.cur); if v.cur=v.max+1 then v.cur:=1; end;
'C',#77:begin; h.old:=h.cur; inc(h.cur); if h.cur=h.max+1 then h.cur:=1; end;
'D',#75:begin; h.old:=h.cur; dec(h.cur); if h.cur=0 then h.cur:=h.max; end;
end;
until (c=#13) or ((not carrier) and (not localon)) or (loggedoff) or (hungup);;
filepullmenu:=h.cur;
end;


procedure initfilelist(a:boolean);
var x:longint;
    fr:filearearec;
begin
if a then begin
          fillit(flist,sizeof(flist));
          fillit(store,sizeof(store));
          fillit(h,sizeof(h));
          fillit(v,sizeof(v));
          fillit(fl,sizeof(fl));
          flist[1].mci:='%FN';          flist[2].mci:='%FZ';
          flist[3].mci:='%FD';          flist[4].mci:='%01';
          flist[5].mci:='%02';          flist[6].mci:='%03';
          flist[7].mci:='%04';          flist[8].mci:='%05';
          flist[9].mci:='%06';          flist[10].mci:='%07';
          flist[11].mci:='%0A';         flist[12].mci:='%0B';
          flist[13].mci:='%0C';         flist[14].mci:='%0D';
          flist[15].mci:='%0E';         flist[16].mci:='%0F';
          flist[17].mci:='%0G';         flist[18].mci:='%FT';
          flist[19].mci:='%FB';         flist[20].mci:='%FC';
          mark(saveptr);
          new(fcount,init);
          listdone:=false;
          nassign(arealist,config.data_dir+'filearea.dat');
          for x:=1 to fnum do nread(arealist,fa,sizeof(fa));
          nclose(arealist);
          nassign(filelist,config.data_dir+fa.filename);
          end else
              begin
              fcount^.done;
              release(saveptr);
              nclose(filelist)
              end;
end;

function getafile(var fit:filelistrec):boolean;
begin
fillit(fit,sizeof(fit));
if eof(filelist) then begin
                      getafile:=false;
                      exit;
                      end;
store[storec]:=filepos(filelist);
nread(filelist,fit,sizeof(fit));
end;

begin
initfilelist(true);
printfile(Config.Textfile_Dir+'listfile.ANS',flist,false);
fillit(v,sizeof(v));
tempint:=1;
wy:=0;
page:=1;
fcc:=0;
storec:=1;
nonnp:=false;
tempbyte1:=1;
tempbyte2:=1;
repeat
  fillit(v,sizeof(v));
  fillit(h,sizeof(h));
  v.cur:=tempbyte1;
  h.cur:=tempbyte2;

  fillchar(store,sizeof(store),#0);
  storec:=1;
  tempint:=1;
  wy:=0;
  fcc:=0;
  storec:=1;
  if nonnp=false then begin
                      fcc   :=filepos(filelist);
                      fcount^.Add(fcc,SizeOf(fcc));
                      end;
  nonnp:=false;
  if not eof(filelist) then begin
   repeat
    getb:=getafile(fl);
    if getb then begin
                 v.on [tempint]:=foba(flist[20] .fore,flist[20] .back)+fl.filename;
                 v.off[tempint]:=foba(flist[1]  .fore,flist[1]  .back)+fl.filename;
                 v.x  [tempint]:=flist[1].x;
                 v.y  [tempint]:=flist[2].y+wy;
                 inc(storec);
                 inc(v.max);
                 printxy(flist[1].x,flist[1].y+wy,foba(flist[1] .fore,flist[1] .back)+fl.filename,true);
                 printxy(flist[2].x,flist[2].y+wy,foba(flist[2] .fore,flist[2] .back)+strr(fl.size div 1024)+'k',true);

        fdt:=1;
        for fdx:=10 downto 1 do
        if fl.description[fdx]<>'' then begin
                                        fdt:=fdx;
                                        fdx:=1;
                                        end;

        for fdx:=1 to fdt do
        if crt.wherey<flist[19].y then
           begin
           printxy(flist[3].x,flist[3].y+wy,fl.description[fdx],true);
           inc(wy);
           end;
           if wherey=FLIST[19].y then fdx:=fdt;
           inc(tempint);
           end;

  until (wherey=flist[19].y) or (eof(filelist)) or (getb=false);
  end;

 case filepullmenu of

 1: if not eof(filelist) then begin
                              tempbyte1:=1;
                              tempbyte2:=1;
                              inc(page);
                              fillchar(store,sizeof(store),#0);
                              storec:=1;
                              end
                              else  { this incs the filelist page}
                       begin
                       tempbyte1:=1;
                       tempbyte2:=1;
                       fcount^.Getnodedata(fcount^.Nodeptr(page),fcc);
                       nreset(filelist);
                       nseek(filelist,fcc);
                       end;
 2: begin { this decs the file list page }
    dec(page);
    if page=0 then page:=1;
    fcount^.Getnodedata(fcount^.Nodeptr(page),fcc);
    nreset(filelist);
    nseek(filelist,fcc);
    fillit(h,sizeof(h));
    fillit(v,sizeof(v));
    fillit(fl,sizeof(fl));
    fillit(store,sizeof(store));
    storec:=1;
    nonnp:=true;
    gotoxy(1,24);
    write(page);
    end;
 3:begin
   tempbyte1:=v.cur;
   tempbyte2:=h.cur;
   nseek(filelist,store[v.cur]);
   nread(filelist,fl,sizeof(fl));
   if removebatch(fl)=false then addbatch(fl);
   fcount^.Getnodedata(fcount^.Nodeptr(page),fcc);
   nreset(filelist);
   nseek(filelist,fcc);
   nonnp:=true;
   fillchar(store,sizeof(store),#0);
   storec:=1;
{  printfile(Config.Textfile_Dir+'listfile.ANS',flist,false);}
   end;
 4:begin
   tempbyte1:=v.cur;
   tempbyte2:=h.cur;
   nseek(filelist,store[v.cur]);
   nread(filelist,fl,sizeof(fl));
   fileinfo(fl);
   fcount^.Getnodedata(fcount^.Nodeptr(page),fcc);
   nreset(filelist);
   nseek(filelist,fcc);
   nonnp:=true;
   fillchar(store,sizeof(store),#0);
   storec:=1;
   printfile(Config.Textfile_Dir+'listfile.ANS',flist,false);
   end;
 5:listdone:=true;
 end;
  clearbox;
until listdone;

initfilelist(false);
end;



begin
fnum:=1;
end.