unit SaveAttach;

interface

uses
  commctrl,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls,FileUtil,ShellAPI,FileCtrl,RxCombos;

type
  TfrmSaveAttach = class(TForm)
    Label1: TLabel;
    ListView3: TListView;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    Bevel1: TBevel;
    Edit1: TEdit;
    Button4: TButton;
    procedure Button4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ListView3Change(Sender: TObject; Item: TListItem;
      Change: TItemChange);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSaveAttach: TfrmSaveAttach;

implementation

uses PXStuff, Main, FMMailOptions;

var
 NilVariant : OleVariant;

{$R *.DFM}

procedure TfrmSaveAttach.Button4Click(Sender: TObject);
var
  tmp:string;
begin
  tmp := '';
  if BrowseDirectory(tmp, '选择用以保存附件的文件夹:', Self.HelpContext) then
    Edit1.Text:= tmp;

end;

procedure TfrmSaveAttach.FormShow(Sender: TObject);
var
  Found: Integer;
  SearchRec: TSearchRec;
  Item: TListItem;
  SHFileInfo: TSHFileInfo;
  i:integer;
begin
    ListView3.Items.Clear;
    Found := FindFirst(sTemporaryFolder + '*.*', faReadOnly + faHidden + faArchive
      + faSysFile, SearchRec);
    while Found = 0 do begin
      if sTemporaryFolder + SearchRec.Name <> sTempMessageFile then begin
        Item := ListView3.Items.Add;
        Item.Caption := SearchRec.Name;
        SHGetFileInfo(PChar(sTemporaryFolder + SearchRec.Name), 0, SHFileInfo,SizeOf(SHFileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
        Item.ImageIndex := SHFileInfo.iIcon;
      end;
      Found := FindNext(SearchRec);
    end;
    FindClose(SearchRec);


    for I := 0 to ListView3.Items.Count - 1 do
      ListView3.Items[I].Selected := True;

  edit1.Text:= ExtractFileDir(application.ExeName);
end;

procedure TfrmSaveAttach.Button3Click(Sender: TObject);
var
  i:integer;
begin
  for I := 0 to ListView3.Items.Count - 1 do
    ListView3.Items[I].Selected := True;
end;

procedure TfrmSaveAttach.Button1Click(Sender: TObject);
var
  i:integer;
  cc:boolean;
begin
    for I := 0 to ListView3.Items.Count - 1 do
    begin
      if ListView3.Items[I].Selected = True then
      begin
        sLastAttSaveDir := MakeValidDirname(edit1.Text);
        SetFileAttr(sTemporaryFolder + ListView3.Items[i].Caption, False, True,
          False, False);
         windows.CopyFile(PChar(sTemporaryFolder + ListView3.Items[i].Caption),PChar(edit1.Text + ListView3.Items[i].Caption),False);
      end;
    end;
    close;
end;

procedure TfrmSaveAttach.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TfrmSaveAttach.ListView3Change(Sender: TObject; Item: TListItem;
  Change: TItemChange);
begin
  if ListView3.Selected=nil then Button1.Enabled:=false else Button1.Enabled:=true;

end;

procedure TfrmSaveAttach.FormCreate(Sender: TObject);
var
    FAutoCompleteList : TStringList;
  si: TSHFILEINFO;
  ImageListHandle: THandle;

begin
  ImageListHandle := SHGetFileInfo('C:\',
                           0,
                           SI,
                           SizeOf(SI),
                           SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  SendMessage(ListView3.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);


end;

initialization
  NilVariant  := 0;
end.
