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

📄 unitfiles.pas

📁 不错的远程控制程序
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                ListItem := Files.ListView1.Items.Add;
                ListItem.Caption := string(FindData.cFileName);
                ListItem.SubItems.Add(FileSize(FindData.nFileSizeLow));
                Attributes := '';
                if ((FindData.dwFileAttributes and faArchive) <> 0) then Attributes := Attributes + 'A';
                if ((FindData.dwFileAttributes and faHidden) <> 0) then Attributes := Attributes + 'H';
                if ((FindData.dwFileAttributes and faReadOnly) <> 0) then Attributes := Attributes + 'R';
                if ((FindData.dwFileAttributes and faSysFile) <> 0) then Attributes := Attributes + 'S';
                ListItem.SubItems.Add(Attributes);
                ListItem.SubItems.Add(FileTimeToDateTimeStr(FindData.ftLastWriteTime));
              end;
            end;
            for I := 0 to Files.ListView1.Items.Count - 1 do begin
              Temp := Files.ListView1.Items.Item[I].Caption;
              flex := Copy(Temp, Pos('.', Temp) + 1, Length(Temp));
              flex := LowerCase(flex); //添加此句,将字符串全部转换成小写的,可省去许多不必要的大小写代码
              if (flex = 'exe') or (flex = 'com') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 11;
              end;
              if flex = 'asp' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 25;
              end;
              if (flex = 'bat') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 6;
              end;
              if (flex = 'txt') or (flex = 'log') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 20;
              end;
              if (flex = 'swf') or (flex = 'fla') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 22;
              end;
              if (flex = 'htm') or (flex = 'html') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 13;
              end;
              if flex = 'bmp' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 7;
              end;
              if (flex = 'chm') or (flex = 'hlp') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 8;
              end;
              if flex = 'doc' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 9;
              end;
              if (flex = 'ini') or (flex = 'inf') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 14;
              end;
              if (flex = 'jpg') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 15;
              end;
              if (flex = 'dll') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 16;
              end;
              if (flex = 'wav') or (flex = 'avi') or (flex = 'mp3') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 17;
              end;
              if (flex = 'rar') or (flex = 'zip') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 19;
              end;
              if (flex = 'rm') or (flex = 'rmvb') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 24;
              end;
              if flex = 'reg' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 26;
              end;
              if flex = 'mdb' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 21;
              end;
              if flex = 'bak' then begin
                Files.ListView1.Items.Item[I].ImageIndex := 0;
              end;
              if (flex = 'sys') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 0;
              end;
              if (flex = 'xls') then begin
                Files.ListView1.Items.Item[I].ImageIndex := 18;
              end;
            end;
            Files.ListView2.Items.EndUpdate;
            Files.ListView1.Items.EndUpdate;

          end;
        F_UPLOAD:
          begin
            Files.ComboBox1.Enabled := True;
            Files.Downloading := False;
          end;
        F_DOWNLOAD:
          begin
            Stream.ReadBuffer(BufferSize, 4);
            SetLength(FileName, BufferSize);
            Stream.ReadBuffer(Pointer(FileName)^, BufferSize);
            Save := TSaveDialog.Create(nil);
            Save.FileName := ExtractFileName(FileName);
            Save.DefaultExt := '*.*';
            Save.Title := '保存下载文件';
            SetLength(FilePath, MAX_PATH);
            GetCurrentDirectory(MAX_PATH, @FilePath[1]);
            Save.InitialDir := FilePath;
            if Save.Execute then
            begin
              SetCurrentDirectory(PChar(ExtractFilePath(Save.FileName)));
              FileStream := TFileStream.Create(Save.FileName, fmCreate);
              FileStream.CopyFrom(Stream, Stream.Size - Stream.Position);
              FileStream.Free;
            end;
            Save.Free;
            Files.ComboBox1.Enabled := True;
            Files.Downloading := False;
          end;
        F_SEARCH:
          begin
            Files.SearchWindow.ListView1.Clear;
            if Stream.Size = 0 then
            begin
              Files.SearchWindow.Button1.Enabled := True;
              Files.SearchWindow.Button2.Enabled := True;
              Exit;
            end;
            Files.SearchWindow.ListView1.Items.BeginUpdate;
            while Stream.Position < Stream.Size do
            begin
              Stream.Read(FindData, SizeOf(TWIN32FindData));
              ListItem := Files.SearchWindow.ListView1.Items.Add;
              ListItem.Caption := string(FindData.cFileName);
              ListItem.SubItems.Add(FileSize(FindData.nFileSizeLow));
              Attributes := '';
              if ((FindData.dwFileAttributes and faArchive) <> 0) then Attributes := Attributes + 'A';
              if ((FindData.dwFileAttributes and faDirectory) <> 0) then Attributes := Attributes + 'D';
              if ((FindData.dwFileAttributes and faHidden) <> 0) then Attributes := Attributes + 'H';
              if ((FindData.dwFileAttributes and faReadOnly) <> 0) then Attributes := Attributes + 'R';
              if ((FindData.dwFileAttributes and faSysFile) <> 0) then Attributes := Attributes + 'S';
              ListItem.SubItems.Add(Attributes);
              ListItem.SubItems.Add(FileTimeToDateTimeStr(FindData.ftLastWriteTime));
            end;
            Files.SearchWindow.ListView1.Items.EndUpdate;
            Files.SearchWindow.Button1.Enabled := True;
            Files.SearchWindow.Button2.Enabled := True;
          end;
      end;
    finally
      Socket := nil;
    end;
  end;
end;

procedure TFiles.Disconnect(var Socket: TCustomWinSocket; Data: Pointer);
var
  Files: TFiles;
begin
  Files := TFiles(Data);
  if Files.DataSocket = Socket then
  begin
    Files.Connected := False;
    Files.Label1.Caption := ' 断开连接';
    Socket := nil;
    Files.DataSocket := nil;
  end;
end;

procedure TFiles.FormCreate(Sender: TObject);
begin
  DataSocket := nil;
  ConnectNotifyInfo := TNotifyInfo.Create;
  ConnectNotifyInfo.Data := Self;
  ConnectNotifyInfo.Callback := @TFiles.Connect;
  Main.NotifyConnectList.Add(ConnectNotifyInfo);
  ReadNotifyInfo := TNotifyInfo.Create;
  ReadNotifyInfo.Data := Self;
  ReadNotifyInfo.Callback := @TFiles.Read;
  Main.NotifyReadList.Add(ReadNotifyInfo);
  DisconnectNotifyInfo := TNotifyInfo.Create;
  DisconnectNotifyInfo.Data := Self;
  DisconnectNotifyInfo.Callback := @TFiles.Disconnect;
  Main.NotifyDisconnectList.Add(DisconnectNotifyInfo);
  SearchWindow := TSearch.Create(Application);
  Downloading := False;
  OldWindowProc := ListView1.WindowProc;
  ListView1.WindowProc := WindowProc;
  DragAcceptFiles(ListView1.Handle, True);
end;

procedure TFiles.FormClose(Sender: TObject; var Action: TCloseAction);
var
  Socket: TCustomWinSocket;
begin
  Main.NotifyConnectList.Delete(Main.NotifyConnectList.IndexOf(ConnectNotifyInfo));
  Main.NotifyReadList.Delete(Main.NotifyReadList.IndexOf(ReadNotifyInfo));
  Main.NotifyDisconnectList.Delete(Main.NotifyDisconnectList.IndexOf(DisconnectNotifyInfo));
  WindowItem.Delete;
  SearchWindow.Free;
  if DataSocket <> nil then
  begin
    if not SocketConnected then
    begin
      Socket := DataSocket;
      DataSocket := nil;
      Connected := False;
      Socket.Close;
    end;
  end;
end;

procedure TFiles.FormDeactivate(Sender: TObject);
begin
  if WindowState = wsMinimized then Hide;
end;

procedure TFiles.Refresh1Click(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
begin
  if not SocketConnected then Exit;
  ComboBox1.Items.Clear;
  CommandFrame.len := 0;
  CommandFrame.Command := F_DRIVES;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TFiles.ComboBox1Change(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
  DataEnd: Integer;
begin
  if not SocketConnected then Exit;
  Data := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
  DataEnd := Pos('(', Data) - 2;
  Data := Copy(Data, 1, DataEnd);
  CurrentDirectory := Data;
  Data := Data + '*';
  Label1.Caption := '目录: ' + CurrentDirectory;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := F_LIST;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ComboBox1.Enabled := False;
  ListView2.Clear;
  ListView1.Clear;
end;

procedure TFiles.ListView2DblClick(Sender: TObject);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not Assigned(ListView2.Selected) then Exit;
  if not SocketConnected then Exit;
  if Downloading then
  begin
    Exit;
  end;
  if SearchWindow.Searching then
  begin
    Exit;
  end;
  if ListView2.Selected.Caption = '.' then
    Data := ExtractFileDrive(CurrentDirectory) + '\'
  else if ListView2.Selected.Caption = '..' then
    Data := ExtractFilePath(ExtractFileDir(CurrentDirectory))
  else
    Data := CurrentDirectory + ListView2.Selected.Caption + '\';
  CurrentDirectory := Data;
  Data := Data + '*';
  Label1.Caption := '目录: ' + CurrentDirectory;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := F_LIST;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ComboBox1.Enabled := False;
  ListView2.Clear;
  ListView1.Clear;
end;

procedure TFiles.ListView2Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
var
  dwItem1: dword;
  dwItem2: dword;
begin
  dwItem1 := 0;
  dwItem2 := 0;
  if lstrcmpi(PChar(Item1.Caption), '.') = 0 then dwItem1 := 2;
  if lstrcmpi(PChar(Item1.Caption), '..') = 0 then dwItem1 := 1;
  if lstrcmpi(PChar(Item2.Caption), '.') = 0 then dwItem2 := 2;
  if lstrcmpi(PChar(Item2.Caption), '..') = 0 then dwItem2 := 1;
  if ((dwItem1 <> 0) and (dwItem2 <> 0)) then
  begin
    Compare := dwItem2 - dwItem1;
    Exit;
  end;
  if dwItem1 <> 0 then
  begin
    Compare := -1;
    Exit;
  end;
  if dwItem2 <> 0 then
  begin
    Compare := 1;
    Exit;
  end;
  Compare := lstrcmpi(PChar(Item1.Caption), PChar(Item2.Caption));
end;

procedure TFiles.ListView2Edited(Sender: TObject; Item: TListItem; var S: string);
var
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not SocketConnected then Exit;
  if Item.Caption = '.' then
  begin
    S := Item.Caption;
    Exit;
  end;
  if Item.Caption = '..' then
  begin
    S := Item.Caption;
    Exit;
  end;
  if Downloading then
  begin
    S := Item.Caption;
    Exit;
  end;
  if SearchWindow.Searching then
  begin
    S := Item.Caption;
    Exit;
  end;
  Data := CurrentDirectory + Item.Caption + '|' + CurrentDirectory + S;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := F_RENAMEDIR;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TFiles.Rename1Click(Sender: TObject);
begin
  if Assigned(ListView2.Selected) then ListView2.Selected.EditCaption;
end;

⌨️ 快捷键说明

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