unit ucomparaTodos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Clipbrd;

type
  Tform_comparaTodos = class(TForm)
    Label1: TLabel;
    e_pastaWeb: TEdit;
    b_comparar: TButton;
    lb_arquivos: TListBox;
    Button1: TButton;
    procedure FormActivate(Sender: TObject);
    procedure b_compararClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  form_comparaTodos: Tform_comparaTodos;

implementation

{$R *.dfm}
uses intercapPrinc, uvars, udownload;

procedure Tform_comparaTodos.FormActivate(Sender: TObject);
begin
   e_pastaWeb.Text := dirRemoto;
end;

procedure Tform_comparaTodos.b_compararClick(Sender: TObject);
var sl, sl_arqlocal: TStringList;
    i: integer;
    msg: string;
    ext: string;
    saveCursor: TCursor;
begin
    dirRemoto := e_pastaWeb.Text + '/';
    if copy (dirRemoto, length(dirRemoto)-1, 2) = '//' then
        delete (dirRemoto, length(dirRemoto), 1);
    e_pastaWeb.Text := dirRemoto;
    writePrivateProfileString ('INTERCAP', 'dirRemoto', pchar(dirRemoto), 'intercap.ini');

    sl := TStringList.create;
    sl_arqlocal := TStringList.create;
    lb_arquivos.clear;

    saveCursor := screen.Cursor;
    screen.Cursor := crHourGlass;
    with intercapPrinc.Form1 do
        for i := 0 to lb_arqPag.count-1 do
            begin
                sl.clear;
                lb_arquivos.Items.Add (dirRemoto+lb_arqpag.items[i]);
                ext := uppercase(ExtractFileExt(lb_arqpag.items[i]));
                if (ext = '.EXE') or (ext = '.PHP') or
                   (ext = '.PNG') or (ext = '.JPG') or (ext = '.JPEG') then
                          msg := 'PROIBIDO - ' + lb_arqpag.items[i]
                else
                if not download (dirRemoto+lb_arqpag.items[i], sl) then
                           msg := 'FALTA - ' + lb_arqpag.items[i]
                else
                    begin
                        sl_arqlocal.LoadFromFile(lb_arqpag.items[i]);
                        if trim(sl.Text) = trim (sl_arqlocal.text) then
                            msg := 'OK - ' + lb_arqpag.items[i]
                        else
                            msg := 'DIFERENTE - ' + lb_arqpag.items[i]
                    end;
                lb_arquivos.Items[lb_arquivos.Count-1] := msg;
                application.processMessages;
            end;

    screen.Cursor := saveCursor;
    sl.Free;
    sl_arqlocal.Free;
end;

procedure Tform_comparaTodos.Button1Click(Sender: TObject);
begin
    Clipboard.AsText := lb_arquivos.Items.GetText;
    showMessage ('Lista copiada para a área de transferência');
end;

end.
