home *** CD-ROM | disk | FTP | other *** search
/ PC Interdit / pc-interdit.iso / sound / gusmod / fselect.pas < prev    next >
Pascal/Delphi Source File  |  1994-10-26  |  11KB  |  436 lines

  1. unit fselect;
  2.  
  3. interface
  4.  
  5. type
  6.   t = record
  7.        c : char;
  8.        a : byte;
  9.      end;
  10.  
  11.   Pfileselect_struct = ^Tfileselect_struct;
  12.   Tfileselect_struct = record
  13.      sx,sy   : integer;
  14.      Path    : string;
  15.      Mask    : string;
  16.      Titre   : string[25];
  17.      fn      : array[1..30] of string [80];
  18.      nofiles : integer;
  19.    end;
  20.  
  21.    Pfilelist = ^TFilelist;
  22.    TFilelist = array[0..511] of string[12];
  23.  
  24.    Ppfadliste = ^Tpfadliste;
  25.    TPfadliste = array[0..511] of string[80];
  26.  
  27.    Psizeliste = ^Tsizeliste;
  28.    Tsizeliste = array[0..511] of longint;
  29.  
  30.    Pselectliste = ^Tselectliste;
  31.    Tselectliste = array[0..511] of boolean;
  32.  
  33.    PAttribliste = ^TAttribliste;
  34.    Tattribliste = array[0..511] of byte;
  35.  
  36.  
  37. procedure select_packfichiers(fs : Pfileselect_struct);
  38. procedure display_ansi(p :pointer; mode : word);
  39.  
  40. var screen : array[1..50,1..80] of t absolute $B800:$0000;
  41.  
  42. implementation
  43.  
  44. uses dos,design,crt;
  45.  
  46. var fnames         : PFilelist;
  47.     fpfad          : PPfadliste;
  48.     fsize          : PSizeliste;
  49.     fselected      : PSelectliste;
  50.     fattrib        : PAttribliste;
  51.  
  52.     dnames         : PFilelist;
  53.     dsize          : PSizeliste;
  54.     dselected      : PSelectliste;
  55.     dattrib        : PAttribliste;
  56.  
  57.     Start_Indication  : integer;
  58.     Ligne_Curseur   : integer;
  59.     selectcount    : word;
  60.     bytes_selected : longint;
  61.  
  62. var DirInfo: SearchRec;
  63.     li : integer;
  64.     count,
  65.     fcount,
  66.     dcount: integer;
  67.     Nullpos : byte;
  68.     ch : char;
  69.     fscount : integer;
  70.     curdir : string;
  71.     savepath : string;
  72.     marker : pointer;
  73.  
  74.  
  75. {$L c:\edition\prog\fr\asm\Fsel }
  76. procedure fsel; external;
  77.  
  78. procedure waitretrace;
  79. begin;
  80.   asm
  81.     MOV   DX,03dAh
  82. @WD_R:
  83.     IN    AL,DX
  84.     TEST  AL,8d
  85.     JZ    @WD_R
  86. @WD_D:
  87.     IN    AL,DX
  88.     TEST  AL,8d
  89.     JNZ   @WD_D
  90.   end;
  91. end;
  92.  
  93. procedure display_ansi(p :pointer; mode : word);
  94. begin;
  95.   textmode(mode);
  96.   move(p^,ptr($b800,0)^,8000);
  97. end;
  98.  
  99.  
  100. procedure sort_filenames(start,fin : integer);
  101. {
  102.  Pour un fichier plus grand, utiliser Quick-Sort !
  103. }
  104. var Aide  : string;
  105.     hsize : longint;
  106.     l1,l2 : integer;
  107. begin;
  108.   for l1 := start to fin-1 do begin;
  109.     for l2 := start to Fin-1 do begin;
  110.       if fnames^[l2] > fnames^[l2+1] then begin;
  111.           Aide := fnames^[l2];
  112.           fnames^[l2] := fnames^[l2+1];
  113.           fnames^[l2+1] := aide;
  114.  
  115.           hsize        := fsize^[l2];
  116.           fsize^[l2]   := fsize^[l2+1];
  117.           fsize^[l2+1] := hsize;
  118.  
  119.           hsize           := fattrib^[l2];
  120.           fattrib^[l2]    := fattrib^[l2+1];
  121.           fattrib^[l2+1]  := hsize;
  122.         end;
  123.       end;
  124.     end;
  125. end;
  126.  
  127.  
  128. procedure sort_dirnames(start,fin : integer);
  129. var aide : string;
  130.     hsize : longint;
  131.     l1,l2 : integer;
  132. begin;
  133.   for l1 := start to fin-1 do begin;
  134.     for l2 := start to fin-1 do begin;
  135.       if dnames^[l2] > dnames^[l2+1] then begin;
  136.           Aide := dnames^[l2];
  137.           dnames^[l2] := dnames^[l2+1];
  138.           dnames^[l2+1] := Aide;
  139.  
  140.           hsize        := dsize^[l2];
  141.           dsize^[l2]   := dsize^[l2+1];
  142.           dsize^[l2+1] := hsize;
  143.  
  144.           hsize           := dattrib^[l2];
  145.           dattrib^[l2]    := dattrib^[l2+1];
  146.           dattrib^[l2+1]  := hsize;
  147.         end;
  148.       end;
  149.     end;
  150. end;
  151.  
  152.  
  153. procedure draw_files(sx,sy : integer; fs : Pfileselect_struct);
  154. var li : integer;
  155. begin;
  156.    waitretrace;
  157.  
  158.    textcolor(7);
  159.    textbackground(black);
  160.    for li := 1 to 11 do begin;
  161.      fillchar(screen[sy+li,20].c,100,0);
  162.      gotoxy(sx+2,sy+li);
  163.      if fselected^[Start_Indication+li] then begin;
  164.        write('√ ');
  165.      end else begin;
  166.        write('  ');
  167.      end;
  168.      write(fnames^[Start_Indication+li]);
  169.      while wherex < sx+2+16 do write(' ');
  170.      if (fattrib^[Start_Indication+li] and $10) = $10 then begin;
  171.        write('        DIR  ');
  172.      end else begin;
  173.        write(fsize^[Start_Indication+li]:7,' Octets');
  174.      end;
  175.    end;
  176.  
  177.    move(marker^,screen[sy+Ligne_Curseur,20].c,100);
  178.  
  179.    textcolor(5); textbackground(black);
  180.    gotoxy(sx+2,sy+Ligne_Curseur);
  181.    if fselected^[Start_Indication+Ligne_Curseur] then begin;
  182.      write('√ ');
  183.    end else begin;
  184.      write('  ');
  185.    end;
  186.    write(fnames^[Start_Indication+Ligne_Curseur]);
  187.    while wherex < sx+2+16 do write(' ');
  188.    if (fattrib^[Start_Indication+Ligne_Curseur] and $10) = $10 then begin;
  189.      write('        DIR  ');
  190.    end else begin;
  191.      write(fsize^[Start_Indication+Ligne_Curseur]:7,' Bytes');
  192.    end;
  193. end;
  194.  
  195. procedure append_dirnames(Quantite : word);
  196. var li : integer;
  197. begin;
  198.   for li := 1 to Quantite do begin;
  199.     fnames^[fcount+li-1] := dnames^[li];
  200.     fsize^[fcount+li-1] := dsize^[li];
  201.     fattrib^[fcount+li-1] := dattrib^[li];
  202.   end;
  203. end;
  204.  
  205.  
  206. procedure read_directory(fs : Pfileselect_struct);
  207. var curpath : string;
  208. begin;
  209.   {$I+}
  210.   for li := 0 to 511 do fnames^[li]  := ' - - -';
  211.   for li := 0 to 511 do fsize^[li]   := 0;
  212.   for li := 0 to 511 do fattrib^[li] := 0;
  213.   for li := 0 to 511 do dattrib^[li] := 0;
  214.   for li := 0 to 511 do dnames^[li]  := ' - - -';
  215.   for li := 0 to 511 do dsize^[li]   := 0;
  216.  
  217.   fcount := 1;
  218.   dcount := 1;
  219.  
  220.   FindFirst(fs^.mask,255, DirInfo);
  221.   while DosError = 0 do
  222.   begin
  223.     if ((DirInfo.attr and $10) = $10) then begin;
  224.       dattrib^[dcount] := DirInfo.attr;
  225.       dnames^[dcount]  := DirInfo.Name;
  226.       dsize^[dcount]   := DirInfo.size;
  227.       Nullpos := pos(#0,dnames^[dcount]);
  228.       if Nullpos <> 0 then
  229.         dnames^[dcount] := copy(dnames^[dcount],0,Nullpos-1);
  230.       inc(dcount);
  231.     end else begin;
  232.       fattrib^[fcount] := DirInfo.attr;
  233.       fnames^[fcount]  := DirInfo.Name;
  234.       fsize^[fcount]   := DirInfo.size;
  235.       Nullpos := pos(#0,fnames^[fcount]);
  236.       if Nullpos <> 0 then
  237.         fnames^[fcount] := copy(fnames^[fcount],0,Nullpos-1);
  238.       inc(fcount);
  239.     end;
  240.     FindNext(DirInfo);
  241.   end;
  242.   {$I-}
  243.   sort_filenames(1,fcount-1);
  244.   sort_dirnames(1,dcount-1);
  245.   append_dirnames(dcount);
  246.  
  247.   getdir(0,curpath);
  248.   count := fcount + dcount - 1;
  249.  
  250.   for li := 0 to 511 do fselected^[li] := false;
  251.   for li := 0 to 511 do dselected^[li] := false;
  252.   for li := 0 to 511 do fpfad^[li] := curpath;
  253.  
  254.  Start_Indication := 0;
  255.  Ligne_Curseur  := 1;
  256. end;
  257.  
  258. procedure Nouv_Fam(fs : Pfileselect_struct);
  259. begin;
  260.   read_directory(fs);
  261.   draw_files(fs^.sx,fs^.sy,fs);
  262.   selectcount := 0;
  263. end;
  264.  
  265. procedure shorten_direntry(fs : Pfileselect_struct);
  266. var last_slashpos : integer;
  267.     hs : string;
  268. begin;
  269.   hs := '';
  270.   while pos('\',fs^.path) <> 0 do begin;
  271.     last_slashpos := pos('\',fs^.path);
  272.     hs := hs+copy(fs^.path,1,last_slashpos);
  273.     delete(fs^.path,1,last_slashpos);
  274.  
  275.    gotoxy(1,23);
  276.    write('                                                            ');
  277.    gotoxy(1,23);
  278.    write(fs^.path);
  279.  
  280.   end;
  281.   if hs[length(hs)] = '\' then hs := copy(hs,1,length(hs)-1);
  282.   fs^.path := hs;
  283.   gotoxy(1,23);
  284.   write('                                                            ');
  285.   gotoxy(1,23);
  286.   write(hs);
  287. end;
  288.  
  289. procedure get_liner;
  290. begin;
  291.   getmem(marker,100);
  292.   move(screen[13,20].c,marker^,100);
  293. end;
  294.  
  295. procedure select_packfichiers(fs : Pfileselect_struct);
  296. var Choix_quitter : boolean;
  297.     nextpath : string;
  298. begin;
  299.   new(fnames);
  300.   new(fsize);
  301.   new(fselected);
  302.   new(fpfad);
  303.   new(fattrib);
  304.  
  305.   new(dnames);
  306.   new(dsize);
  307.   new(dselected);
  308.   new(dattrib);
  309.  
  310.   getdir(0,savepath);
  311.   chdir(fs^.path);
  312.  
  313.   display_ansi(@fsel,co80);
  314.   get_liner;
  315.   cursor_off;
  316.  
  317.   inc(fs^.sy,2);
  318.  
  319.   read_directory(fs);
  320.  
  321.  ch := #0;
  322.  draw_files(fs^.sx,fs^.sy,fs);
  323.  Choix_quitter := false;
  324.  while not Choix_quitter do begin;
  325.    ch := readkey;
  326.    if ch = #0 then ch := readkey;
  327.    case ch of
  328.      #13,
  329.      #27 : begin;
  330.              if (fattrib^[Start_Indication+Ligne_Curseur] and $10 = 10)
  331.              then begin;
  332.                nextpath := fnames^[Start_Indication+Ligne_Curseur];
  333.                if nextpath = '..' then begin;
  334.                  chdir('..');
  335.                  shorten_direntry(fs);
  336.                  Nouv_Fam(fs);
  337.                end else begin;
  338.                  if fs^.path[length(fs^.path)] <> '\' then
  339.                  fs^.path := fs^.path + '\';
  340.                  fs^.path :=  fs^.path+nextpath;
  341.                  chdir(fs^.path);
  342.                  nouv_fam(fs);
  343.                end;
  344.              end else begin;
  345.                Choix_quitter := true;
  346.              end;
  347.            end;
  348.      #72 : begin;
  349.              if Ligne_Curseur > 1 then begin;
  350.                dec(Ligne_Curseur);
  351.              end else begin;
  352.                if Start_Indication > 0 then dec(Start_Indication);
  353.              end;
  354.            end;
  355.  
  356.      #73 : begin; { Page up }
  357.              if Start_Indication > 11+Ligne_Curseur then begin;
  358.                dec(Start_Indication,11);
  359.              end else begin;
  360.                if Start_Indication > 11 then begin;
  361.                  dec(Start_Indication,11);
  362.                  Ligne_Curseur := Start_Indication+0;
  363.                end else begin;
  364.                  Start_Indication := 0;
  365.                  Ligne_Curseur := 1;
  366.                end;
  367.              end;
  368.            end;
  369.  
  370.      #80 : begin;
  371.              if Ligne_Curseur < 11 then begin;
  372.                inc(Ligne_Curseur);
  373.              end else begin;
  374.                if Start_Indication < count-12 then inc(Start_Indication);
  375.              end;
  376.            end;
  377.  
  378.      #81 : begin; { Page down }
  379.              if Start_Indication+25 < count then begin;
  380.                inc(Start_Indication,11);
  381.              end else begin;
  382.                  Start_Indication := count-12;
  383.                  Ligne_Curseur := 11;
  384.              end;
  385.            end;
  386.  
  387.      #71 : begin;
  388.              Start_Indication := 0;
  389.              Ligne_Curseur  := 1;
  390.            end;
  391.  
  392.      #79 : begin;
  393.              Start_Indication := count - 12;
  394.              Ligne_Curseur  := 11;
  395.            end;
  396.  
  397.  
  398.      #32 : begin; { Space }
  399.              if fselected^[Start_Indication+Ligne_Curseur] then begin;
  400.                fselected^[Start_Indication+Ligne_Curseur] := false;
  401.                dec(selectcount);
  402.                dec(bytes_selected,fsize^[Start_Indication+Ligne_Curseur]);
  403.               end else begin;
  404.                fselected^[Start_Indication+Ligne_Curseur] := true;
  405.                inc(selectcount);
  406.                inc(bytes_selected,fsize^[Start_Indication+Ligne_Curseur]);
  407.                getdir(0,fpfad^[Start_Indication+Ligne_Curseur]);
  408.              end;
  409.            end;
  410.    end;
  411.    draw_files(fs^.sx,fs^.sy,fs);
  412.  end;
  413.  
  414.  fs^.nofiles := 0;
  415.  for li := 0 to 511 do begin;
  416.    if fselected^[li] then begin;
  417.      inc(fs^.nofiles);
  418.      fs^.fn[fs^.nofiles] := fpfad^[li]+'\'+fnames^[li];
  419.    end;
  420.  end;
  421.  
  422.   chdir(savepath);
  423.   dispose(fnames);
  424.   dispose(fsize);
  425.   dispose(fselected);
  426.   dispose(fpfad);
  427.   dispose(fattrib);
  428.  
  429.   dispose(dnames);
  430.   dispose(dsize);
  431.   dispose(dselected);
  432.   dispose(dattrib);
  433. end;
  434.  
  435. begin;
  436. end.