⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copyto.pas

📁 最好的局域网搜索软件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
procedure TCopyToForm.CopyListViewDblClick(Sender: TObject);
var
  CopyThread            : TCopyFile;
  SrcFile, DestFile     : string;
  DirName               : string;
  {
  FtpGetThread: TFtpGetThread;
  s: string;
  }
  FtpDown: TFtpDownloadThread;
begin

  if CopyListview.SelCount <> 0 then
  begin
    Caption:='正在复制...';
    Label4.Caption := '多线程复制文件......';

    DirName := ComboBox1.Text;
    if DirName[length(DirName)] <> '\' then DirName := DirName + '\';
    //if not DirectoryExists(DirName) then ForceDirectories(DirName);

    if (CopyListview.selected.ImageIndex in copy_img_set) then
    begin
      SrcFile := CopyListview.Selected.Caption;
      DestFile := CopyListview.Selected.SubItems[2];

      if (CopyListview.Selected.ImageIndex = 22) then// 05.10.7
      begin
        CopyListview.Selected.SubItems[2] := DirName + DestFile;
      end;

      DestFile := CopyListview.Selected.SubItems[2];

      CopyListview.Selected.ImageIndex := 23;

      if pos('ftp://', SrcFile) <> 1 then
      begin
        CopyThread:=TCopyFile.Create(SrcFile, DestFile);
        CopyThread.ListIndex:= CopyListview.Selected.Index;
        CopyListview.Selected.Data := CopyThread;
        CopyThread.Resume;
      end
      else // FTP
      begin
        {
        s := SrcFile;
        delete(s, 1, 6);
        delete(s, 1, pos('/', s)-1);
        FtpGetThread := TFtpGetThread.Create(true);
        FtpGetThread.SrcFile := s;
        FtpGetThread.DestFile := DestFile;
        FtpGetThread.MyListItem := CopyListview.Selected;
        FtpGetThread.FreeOnTerminate := true;
        CopyListview.Selected.Data := FtpGetThread;
        FtpGetThread.Resume;
        }

        FtpDown := TFtpDownloadThread.Create(true);
        FtpDown.FtpUrl := CopyListview.Selected.Caption;
        FtpDown.LocalFile := DestFile;
        FtpDown.MyListItem := CopyListview.Selected;
        CopyListview.Selected.Data := FtpDown;
        FtpDown.OnStatusEvent := AboutForm.FtpDownDebug;
        FtpDown.Resume;
      end
    end
    else if CopyListview.Selected.ImageIndex = 111 then
    begin
      TThread(CopyListview.Selected.Data).Resume;
      CopyListview.Selected.ImageIndex := 23;
    end
  end;

end;

procedure TCopyToForm.CopyListViewDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  if Source=MainForm.CurListView then accept :=true;
end;

procedure TCopyToForm.CopyListViewDragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
  CopyItem,TemItem      : TListItem;
  i                     : integer;

  SearchFileThread    : TSearchFileThread;
  DirName             : string;
  FileSize            : DWORD;

  FtpDir: string;

  SearchFtpFileThread: TSearchFtpFileThread;
  RItem: TListItem;
  FtpHandle: HINTERNET;
begin

  for i:=1 to MainForm.CurListView.Items.Count  do
  if MainForm.CurListView.Items[i-1].Selected then
  begin
    With Source as TListView do TemItem := MainForm.CurListView.Items[i-1];

    if TemItem.ImageIndex <> 0 then // File
    begin
      CopyItem:=CopyListView.Items.Add;
      CopyItem.ImageIndex := 22;
      if (not MainForm.IsFtp) then
      begin
        CopyItem.Caption := MainForm.CurDirName + TemItem.Caption;
      end
      else
      begin  // FTP file
        FtpDir := MainForm.CurFtpSvr + MainForm.CurFtpDir;
        if FtpDir[length(FtpDir)] <> '/' then FtpDir := FtpDir + '/';
        CopyItem.Caption := 'ftp://' +  FtpDir + TemItem.Caption;
      end;
      FileSize := pFileItem(TemItem.Data)^.size;
      if FileSize < 1024 then CopyItem.SubItems.Add(inttostr(FileSize)+'B')
      else CopyItem.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024));
      CopyItem.SubItems.Add('-');
      CopyItem.SubItems.Add(TemItem.Caption);
    end
    else
    begin
      if (not MainForm.IsFtp) then
      begin
        DirName := MainForm.CurDirName + MainForm.CurListView.Items[i-1].Caption;
        {if DirName[length(DirName)] <> '\' then }DirName := DirName + '\';

        SearchFileThread := TSearchFileThread.Create(true);
        SearchFileThread.MyDirName := DirName;
        SearchFileThread.DirLen := Length(MainForm.CurDirName);
        SearchFileThread.Resume;
      end
      else
      begin // FTP dir
        RItem := pTabData(MainForm.ClientPageCtrl.ActivePage.Tag)^.MyRListItem;
        FtpHandle := PListItem(RItem.Data)^.FtpHandle;

        FtpDir := MainForm.CurFtpDir;
        if FtpDir[length(FtpDir)] <> '/' then FtpDir := FtpDir + '/';
        FtpDir := FtpDir + MainForm.CurListView.Items[i-1].Caption;

        SearchFtpFileThread := TSearchFtpFileThread.Create(true);
        SearchFtpFileThread.FtpHandle := FtpHandle;
        SearchFtpFileThread.MyDir := FtpDir;
        SearchFtpFileThread.MyHost := MainForm.CurFtpSvr;
        SearchFtpFileThread.Resume;
      end;
    end
  end;

end;

procedure TCopyToForm.SaveCopyRecord;
var
  CopyRecFile   : TextFile;
  i             : integer;
begin

  if CopyListView.Items.Count <> 0 then
  begin
    AssignFile(CopyRecFile, AppDir + '\CopyRec.txt');
    ReWrite(CopyRecFile);

    for i:=0 to CopyListView.Items.Count-1 do
    if CopyListView.Items[i].ImageIndex <> 24 then
    begin
      writeln(CopyRecFile, CopyListView.Items[i].Caption);
      writeln(CopyRecFile, CopyListView.Items[i].SubItems[1]);

      if CopyListview.Items[i].ImageIndex=23 then // 05.10.7
        TThread(CopyListview.Items[i].Data).Suspend;
    end;

    CloseFile(CopyRecFile);
  end;

end;

procedure TCopyToForm.FormDestroy(Sender: TObject);
var
  i             : integer;
  b             : boolean;
begin

  if cbSave.Checked then
  begin
    SaveCopyRecord;
  end
  else
  begin
    if CopyListView.Items.Count <> 0 then
    begin

      b := false;
      for i:=0 to CopyListView.Items.Count-1 do
      if CopyListView.Items[i].ImageIndex <> 24 then
      begin
        b := true;
        break;
      end;

      if b then
      begin
        if Application.MessageBox(
        '尚有一些文件没有拷贝完,是否保存这些记录?',
        'LAN Explorer',
        MB_YESNO + MB_DEFBUTTON1) = IDYES then  SaveCopyRecord;
      end;

    end;
  end;

end;

procedure TCopyToForm.N_CP_PauseClick(Sender: TObject);
var
  i: integer;
begin

    for i:=CopyListview.Items.Count downto 1 do
    if (CopyListview.Items[i-1].Selected)and(CopyListview.Items[i-1].ImageIndex=23) then
    begin
      TThread(CopyListview.Items[i-1].Data).Suspend;
      CopyListview.Items[i-1].ImageIndex := 111;
    end;

end;

procedure TCopyToForm.N_CP_ResumeClick(Sender: TObject);
var
  i: integer;
begin

    for i:=CopyListview.Items.Count downto 1 do
    if (CopyListview.Items[i-1].Selected)and(CopyListview.Items[i-1].ImageIndex=111) then
    begin
      TThread(CopyListview.Items[i-1].Data).Resume;
      CopyListview.Items[i-1].ImageIndex := 23;
    end;

end;

procedure TCopyToForm.LoadCopyRecord;
var
  CopyRecFile      : TextFile;
  //i             : integer;
  s1, s2        : string;
  Item          : TListItem;
begin

  if FileExists('CopyRec.txt') then
  begin
    AssignFile(CopyRecFile, 'CopyRec.txt');
    Reset(CopyRecFile);

    while not eof(CopyRecFile) do
    begin
      readln(CopyRecFile, s1);
      readln(CopyRecFile, s2);
      Item := CopyListview.Items.Add;
      Item.Caption := s1;
      Item.ImageIndex := 25;
      Item.SubItems.Add('-');
      Item.SubItems.Add(s2);
      //if eoln(AddrFile) then readln(AddrFile);
    end;

    CloseFile(CopyRecFile);
    cbSave.Checked := true;
  end;

  if CopyListview.Items.Count <> 0 then
  begin
    Label2.Caption := '上次未完成的拷贝';
    cbSave.Tag := 1;
    Show;
  end;

end;

procedure TCopyToForm.cbSaveClick(Sender: TObject);
begin

  if (not cbSave.Checked)and(cbSave.Tag = 1) then
  begin
    cbSave.Tag := 2;
    if Application.MessageBox(
        '是否清空这些文件?',
        'LAN Explorer',
        MB_YESNO + MB_DEFBUTTON1) = IDYES then
    begin
      CopyListview.Items.Clear;
      DeleteFile(AppDir + '\CopyRec.txt');
    end;
    //else exit;
  end;

end;

procedure TCopyToForm.AddToListView(FileName: String; DirLen: integer; FileSize: DWORD);
var
  Item  : TListItem;
  bExist: boolean;
  j     : integer;
begin

  bExist := false;
  for j:=1 to CopyListview.Items.Count do
    if FileName = CopyListview.Items[j-1].Caption then bExist:=true;

  if not bExist then
  begin
    Item := CopyListview.Items.Add;
    Item.Caption := FileName;
    Item.ImageIndex := 22;

    if FileSize < 1024 then Item.SubItems.Add(inttostr(FileSize)+'B')
    else Item.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024));

    Item.SubItems.Add('-');
    Item.SubItems.Add(pchar(@FileName[DirLen+1]));
    Label4.Caption := '正在加入:' + FileName;
  end;

end;

procedure TCopyToForm.AddFtpToListView(FileName: String; DirLen: integer; FileSize: DWORD);
var
  Item  : TListItem;
  bExist: boolean;
  j     : integer;
  s: string;
begin

  bExist := false;
  for j:=1 to CopyListview.Items.Count do
    if FileName = CopyListview.Items[j-1].Caption then bExist:=true;

  if not bExist then
  begin
    Item := CopyListview.Items.Add;
    Item.Caption := FileName;
    Item.ImageIndex := 22;

    if FileSize < 1024 then Item.SubItems.Add(inttostr(FileSize)+'B')
    else Item.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024));

    Item.SubItems.Add('-');
    s := pchar(@FileName[DirLen+1]);
    for j := 1 to length(s) do if s[j]='/' then s[j] := '\';
    Item.SubItems.Add(s);
    Label4.Caption := '正在加入:' + FileName;
  end;

end;

procedure TCopyToForm.N_CP_OpenLocalClick(Sender: TObject);
var
  FileName, CmdStr: string;
begin
  if CopyListview.SelCount <> 1 then exit;
  if CopyListview.Selected.ImageIndex = 22 then exit;
  FileName := CopyListview.Selected.SubItems[1];
  CmdStr := 'explorer  /n,/e,/select,' + FileName;
  WinExec(pchar(CmdStr),SW_SHOW);
end;

procedure TCopyToForm.N_CP_OpenRemoteClick(Sender: TObject);
var
  FileName, CmdStr: string;
begin
  if CopyListview.SelCount <> 1 then exit;
  //if CopyListview.Selected.ImageIndex = 22 then exit;
  FileName := CopyListview.Selected.Caption;
  CmdStr := 'explorer  /n,/e,/select,' + FileName;
  WinExec(pchar(CmdStr),SW_SHOW);
end;

procedure TCopyToForm.ComboBox1Enter(Sender: TObject);
{var
  exist: boolean;
  i: integer;
  sc: string;}
begin
    {exist := false;

    sc := trim(ComboBox1.text);
    if sc[length(sc)]<>'\' then sc:=sc+'\';
    ComboBox1.text:=sc;

    for i:=0 to (ComboBox1.Items.Count-1) do
    begin
      if ComboBox1.Items[i] = ComboBox1.text then exist := true;
    end;
    if (not exist ) then ComboBox1.Items.Add(ComboBox1.text); }
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -