bmasterc@126: unit UnitFunctions; bmasterc@126: bmasterc@126: interface bmasterc@126: bmasterc@126: uses SysUtils, Classes, Windows, IdFTPList, Math; bmasterc@126: bmasterc@126: function CalcSpeed(eOld, eNew: Integer): String; bmasterc@126: // local bmasterc@126: function GetAllFiles(Mask: String; Attr: Integer; Recursive: Boolean; ShowDirs: Boolean; ShowPath: Boolean = True): TStringList; bmasterc@126: // ftp bmasterc@126: function GetAllDirs: TStringList; bmasterc@126: bmasterc@126: implementation bmasterc@126: bmasterc@126: uses UnitfrmMain; bmasterc@126: bmasterc@126: function CalcSpeed(eOld, eNew: Integer): String; bmasterc@126: begin bmasterc@126: Result := frmMain.Caption; bmasterc@126: if (eOld < eNew) and (eOld <> 0) then begin bmasterc@126: eOld := eNew - eOld; bmasterc@126: //eOld := eOld *2; // this is only used for faster updates... bmasterc@126: Result := 'Metamod:Source - Uploading with ' + FloatToStr(RoundTo(eOld / 1024, -2)) + ' kb/s'; bmasterc@126: end; bmasterc@126: end; bmasterc@126: bmasterc@126: function GetAllFiles(Mask: String; Attr: Integer; Recursive: Boolean; ShowDirs: Boolean; ShowPath: Boolean = True): TStringList; bmasterc@126: var eSearch: TSearchRec; bmasterc@126: begin bmasterc@126: Result := TStringList.Create; bmasterc@126: bmasterc@126: // Find all files bmasterc@126: if FindFirst(Mask, Attr, eSearch) = 0 then bmasterc@126: begin bmasterc@126: repeat bmasterc@126: if eSearch.Name[1] <> '.' then begin bmasterc@126: if ShowPath then begin bmasterc@126: if ((eSearch.Attr and Attr) = eSearch.Attr) and ((eSearch.Attr and faDirectory) <> eSearch.Attr) then bmasterc@126: Result.Add(ExtractFilePath(Mask) + eSearch.Name) bmasterc@126: else if (ShowDirs) and ((eSearch.Attr and faDirectory) = eSearch.Attr) then bmasterc@126: Result.Add(ExtractFilePath(Mask) + eSearch.Name); bmasterc@126: end bmasterc@126: else begin bmasterc@126: if ((eSearch.Attr and Attr) = eSearch.Attr) and ((eSearch.Attr and faDirectory) <> eSearch.Attr) then bmasterc@126: Result.Add(eSearch.Name) bmasterc@126: else if (ShowDirs) and ((eSearch.Attr and faDirectory) = eSearch.Attr) then bmasterc@126: Result.Add(eSearch.Name); bmasterc@126: end; bmasterc@126: bmasterc@126: if ((eSearch.Attr and faDirectory) = eSearch.Attr) and (Recursive) then begin bmasterc@126: with GetAllFiles(ExtractFilePath(Mask) + eSearch.Name + '\' + ExtractFileName(Mask), Attr, True, ShowDirs, ShowPath) do begin bmasterc@126: Result.Text := Result.Text + Text; bmasterc@126: Free; bmasterc@126: end; bmasterc@126: end; bmasterc@126: end; bmasterc@126: until FindNext(eSearch) <> 0; bmasterc@126: end; bmasterc@126: end; bmasterc@126: bmasterc@126: function GetAllDirs: TStringList; bmasterc@126: var eList: TStringList; bmasterc@126: i: integer; bmasterc@126: begin bmasterc@126: eList := TStringList.Create; bmasterc@126: frmMain.IdFTP.List(eList); bmasterc@126: frmMain.IdFTP.DirectoryListing.LoadList(eList); bmasterc@126: eList.Clear; bmasterc@126: for i := 0 to frmMain.IdFTP.DirectoryListing.Count -1 do begin bmasterc@126: if frmMain.IdFTP.DirectoryListing.Items[i].ItemType = ditDirectory then bmasterc@126: eList.Add(frmMain.IdFTP.DirectoryListing.Items[i].FileName); bmasterc@126: end; bmasterc@126: Result := eList; bmasterc@126: end; bmasterc@126: bmasterc@126: { This is another possibility I coded because I couldn't find another bug... bmasterc@126: bmasterc@126: function GetAllDirs: TStringList; bmasterc@126: var eList: TStringList; bmasterc@126: i, eStart: integer; bmasterc@126: begin bmasterc@126: eList := TStringList.Create; bmasterc@126: frmMain.IdFTP.List(eList, '', True); bmasterc@126: eStart := 0; bmasterc@126: bmasterc@126: bmasterc@126: // +----------------------------------------------------------------+ bmasterc@126: // | drwxr-xr-x 5 web3 ftponly 2048 Jun 25 19:43 files | bmasterc@126: // | drwxr-xr-x 2 web3 ftponly 2048 Jun 25 19:57 html | bmasterc@126: // | drwxr-xr-x 3 root root 2048 Jun 20 05:03 log | bmasterc@126: // | drwxrwxrwx 2 web3 ftponly 2048 Jun 19 2004 phptmp | bmasterc@126: // +----------------------------------------------------------------+ bmasterc@126: bmasterc@126: bmasterc@126: // at first remove all non-directories from the list bmasterc@126: for i := eList.Count -1 downto 0 do begin bmasterc@126: if Pos('d', eList[i]) <> 1 then bmasterc@126: eList.Delete(i); bmasterc@126: end; bmasterc@126: // then we have to find the position where ALL filenames start... bmasterc@126: for i := 0 to eList.Count -1 do begin bmasterc@126: if (eStart = 0) and (Pos(':', eList[i]) <> 0) then bmasterc@126: eStart := Pos(':', eList[i]); bmasterc@126: end; bmasterc@126: bmasterc@126: if eStart = 0 then bmasterc@126: eList.Clear bmasterc@126: else begin bmasterc@126: // find the position bmasterc@126: for i := 0 to eList.Count -1 do begin bmasterc@126: if Pos(':', eList[i]) <> 0 then begin bmasterc@126: while (eStart <> Length(eList[i])) and (eList[i][eStart] <> #32) do bmasterc@126: Inc(eStart, 1); bmasterc@126: end; bmasterc@126: end; bmasterc@126: // remove the detail stuff... bmasterc@126: for i := 0 to eList.Count -1 do bmasterc@126: eList[i] := Copy(eList[i], eStart +1, Length(eList[i])); bmasterc@126: end; bmasterc@126: bmasterc@126: Result := eList; bmasterc@126: end; } bmasterc@126: bmasterc@126: end. bmasterc@126: bmasterc@126: