home *** CD-ROM | disk | FTP | other *** search
- unit main;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ImgList, FTPSock, Ftp, ComCtrls, FtpListView, FtpTreeView, ToolWin, ClipBrd,
- StdCtrls, FtpMsg, FtpCache, ExtCtrls, Menus;
-
- type
- TfrmMain = class(TForm)
- ToolBar1: TToolBar;
- ToolButton1: TToolButton;
- ToolButton2: TToolButton;
- MFtpTreeView1: TMFtpTreeView;
- MFtp1: TMFtp;
- ImageList1: TImageList;
- ToolButton3: TToolButton;
- ToolButton4: TToolButton;
- ToolButton5: TToolButton;
- ToolButton6: TToolButton;
- ToolButton7: TToolButton;
- ToolButton8: TToolButton;
- ToolButton9: TToolButton;
- ToolButton10: TToolButton;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- ToolButton11: TToolButton;
- ToolButton13: TToolButton;
- Splitter1: TSplitter;
- Notebook1: TNotebook;
- MFtpListView1: TMFtpListView;
- Splitter2: TSplitter;
- MFtpMessenger1: TMFtpMessenger;
- ProgressBar1: TProgressBar;
- StatusBar1: TStatusBar;
- PopupMenu1: TPopupMenu;
- LargeIcons1: TMenuItem;
- SmallIcons1: TMenuItem;
- List1: TMenuItem;
- Details1: TMenuItem;
- N1: TMenuItem;
- CopyLocation1: TMenuItem;
- procedure ToolButton10Click(Sender: TObject);
- procedure ToolButton8Click(Sender: TObject);
- procedure ToolButton1Click(Sender: TObject);
- procedure ToolButton2Click(Sender: TObject);
- procedure MFtp1FtpBusy(Sender: TObject);
- procedure MFtp1FtpReady(Sender: TObject);
- procedure MFtp1LoggedIn(Sender: TObject);
- procedure MFtp1DirectoryChanged(Sender: TObject);
- procedure MFtp1ContentChanged(Sender: TObject);
- procedure ToolButton6Click(Sender: TObject);
- procedure MFtpListView1DblClick(Sender: TObject);
- procedure MFtpListView1Edited(Sender: TObject; Item: TListItem;
- var S: String);
- procedure ToolButton11Click(Sender: TObject);
- procedure ToolButton4Click(Sender: TObject);
- procedure ToolButton5Click(Sender: TObject);
- procedure MFtp1FtpInfo(Sender: TObject; info: FtpInfo;
- addinfo: String);
- procedure MFtp1FtpQuit(Sender: TObject);
- procedure MFtpListView1FileDropped(Sender: TObject);
- procedure MFtp1FtpError(Sender: TObject; error: FtpError;
- addinfo: String);
- procedure ViewmenuClick(Sender: TObject);
- procedure MFtpListView1InfoTip(Sender: TObject; Item: TListItem;
- var InfoTip: String);
- procedure FormCreate(Sender: TObject);
- procedure CopyLocation1Click(Sender: TObject);
- procedure PopupMenu1Popup(Sender: TObject);
- procedure MFtp1FtpNeedInfo(Sender: TObject; need: TMFtpInfoNeeded;
- var Value: String);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- frmMain: TfrmMain;
-
- function Strip(S: String): String;
-
- implementation
-
- {$define DISPLAY_PARENT_DIRECTORY}
-
- uses connect, confirm, banner;
-
- {$R *.DFM}
-
- procedure TfrmMain.ToolButton10Click(Sender: TObject);
- begin
- MFtp1.Abort;
- end;
-
- procedure TfrmMain.ToolButton8Click(Sender: TObject);
- begin
- MFtp1.ChangeToParentDirectory;
- end;
-
- procedure TfrmMain.ToolButton1Click(Sender: TObject);
- begin
- if MFtp1.Connected then Exit;
- frmConnect.ShowModal;
- end;
-
- procedure TfrmMain.ToolButton2Click(Sender: TObject);
- begin
- MFtp1.Disconnect;
- end;
-
- procedure TfrmMain.MFtp1FtpBusy(Sender: TObject);
- begin
- Cursor := crDefault;
- MFtpListView1.Accept := False;
- end;
-
- procedure TfrmMain.MFtp1FtpReady(Sender: TObject);
- begin
- Cursor := crDefault;
- ProgressBar1.Visible := False;
- StatusBar1.Visible := True;
- MFtpListView1.Accept := True;
- end;
-
- procedure TfrmMain.MFtp1LoggedIn(Sender: TObject);
- begin
- MFtp1.Refresh;
- end;
-
- procedure TfrmMain.MFtp1DirectoryChanged(Sender: TObject);
- begin
- MFtp1.Refresh;
- end;
-
- procedure TfrmMain.MFtp1ContentChanged(Sender: TObject);
- begin
- {we want to refresh cache}
- if not MFtp1.Connected then Exit;
- with MFtp1 do
- begin
- Cache := False;
- Refresh;
- Cache := True;
- end;
- end;
-
- procedure TfrmMain.ToolButton6Click(Sender: TObject);
- begin
- if MFtpListview1.SelectedFiles.Count > 0 then
- MFtp1.DeleteFile(MFtpListview1.SelectedFiles[0]);
-
- if MFtpListview1.SelectedDirectories.Count > 0 then
- MFtp1.DeleteDirectory(MFtpListview1.SelectedDirectories[0]);
- end;
-
- procedure TfrmMain.MFtpListView1DblClick(Sender: TObject);
- begin
- if MFtpListview1.SelectedDirectories.Count > 0 then
- {$ifdef DISPLAY_PARENT_DIRECTORY}
- if (MFtpListview1.Items[0].Caption = 'Parent Directory') and
- (MFtpListview1.SelectedDirectories[0] = 'Parent Directory') then
- MFtp1.ChangeToParentDirectory
- else
- MFtp1.ChangeDirectory(MFtpListview1.SelectedDirectories[0]);
- {$else}
- MFtp1.ChangeDirectory(MFtpListview1.SelectedDirectories[0]);
- {$endif}
- end;
-
- procedure TfrmMain.MFtpListView1Edited(Sender: TObject; Item: TListItem;
- var S: String);
- begin
- MFtp1.RenameFile(Item.Caption, S);
- end;
-
- procedure TfrmMain.ToolButton11Click(Sender: TObject);
- var S: String;
- begin
- if InputQuery('FTP Panel', 'What name is the new directory?', S) then
- MFtp1.CreateDirectory(S);
- end;
-
- procedure TfrmMain.ToolButton4Click(Sender: TObject);
- begin
- if MFtpListview1.SelectedFiles.Count > 0 then
- begin
- with SaveDialog1 do
- begin
- Filename := MFtpListview1.SelectedFiles[0];
- if Execute then MFtp1.GetFile(MFtpListview1.SelectedFiles[0], Filename);
- ProgressBar1.Visible := True;
- StatusBar1.Visible := False;
- end;
- end;
- end;
-
- procedure TfrmMain.ToolButton5Click(Sender: TObject);
- begin
- with OpenDialog1 do
- begin
- if Execute then
- begin
- MFtp1.PutFile(Filename, Strip(Filename));
- ProgressBar1.Visible := True;
- StatusBar1.Visible := False;
- end;
- end;
- end;
-
- procedure TfrmMain.MFtp1FtpInfo(Sender: TObject; info: FtpInfo;
- addinfo: String);
- begin
- case info of
- ftpBannerAvailable:
- begin
- frmBanner.Banner.Lines.Assign(MFtp1.Banner);
- frmBanner.Show;
- end;
- ftpDataTrace:
- if ProgressBar1.Visible then
- ProgressBar1.Position := MFtp1.BytesTransferred;
- ftpFileSize:
- ProgressBar1.Max := StrToInt(addinfo);
- end;
- end;
-
- procedure TfrmMain.MFtp1FtpError(Sender: TObject; error: FtpError;
- addinfo: String);
- begin
- ProgressBar1.Visible := False;
- StatusBar1.Visible := True;
- end;
-
- procedure TfrmMain.MFtp1FtpQuit(Sender: TObject);
- begin
- MFtpTreeView1.Sites.Clear;
- MFtpListView1.Items.Clear;
- end;
-
- procedure TfrmMain.MFtpListView1FileDropped(Sender: TObject);
- var i: Integer;
- R: TStringList;
- begin
- R := TStringList.Create;
- with R do
- try
- for i := 0 to MFtpListView1.FileDropped.Count - 1 do
- Add(Strip(MFtpListView1.FileDropped[i]));
-
- MFtp1.PutFile(MFtpListView1.FileDropped, R);
- ProgressBar1.Visible := True;
- StatusBar1.Visible := False;
- finally
- Free;
- end;
- end;
-
- procedure TfrmMain.ViewmenuClick(Sender: TObject);
- begin
- MFtpListview1.ViewStyle := TViewStyle(TMenuItem(Sender).Tag);
- TMenuItem(Sender).Checked := True;
- end;
-
- procedure TfrmMain.MFtpListView1InfoTip(Sender: TObject; Item: TListItem;
- var InfoTip: String);
- begin
- InfoTip := Item.Caption;
- end;
-
- procedure TfrmMain.FormCreate(Sender: TObject);
- begin
- // clear outdated cache
- CleanCache(True, True, 7);
- end;
-
- procedure TfrmMain.CopyLocation1Click(Sender: TObject);
- begin
- with TClipBoard.Create do
- try
- if MFtpListView1.SelectedDirectories.Count = 1 then
- SetTextBuf(PChar(MFtp1.URL + MFtpListView1.SelectedDirectories[0] + '/'))
- else
- SetTextBuf(PChar(MFtp1.URL + MFtpListView1.SelectedFiles[0]));
- finally
- Free;
- end;
- end;
-
- procedure TfrmMain.PopupMenu1Popup(Sender: TObject);
- begin
- CopyLocation1.Enabled := (MFtpListView1.SelCount > 0);
- end;
-
- function Strip;
- var i: Integer;
- begin
- if Pos('\', S) > 0 then
- begin
- for i := Length(S) downto 1 do
- if S[i] = '\' then Break;
-
- Result := Copy(S, i + 1, 999);
- end
- else
- Result := S;
- end;
-
- procedure TfrmMain.MFtp1FtpNeedInfo(Sender: TObject; need: TMFtpInfoNeeded;
- var Value: String);
- begin
- if need = niOverwrite then
- begin
- frmConfirm.Button1.Enabled := MFtp1.SupportResume;
- frmConfirm.Label1.Caption := MFtpListView1.SelectedFiles[0] + ' already exists.';
- frmConfirm.ShowModal;
- case Tag of
- 0: Value := 'Resume';
- 1: Value := 'Overwrite';
- 2: Value := 'Cancel';
- end;
- end;
- end;
-
- end.
-