installer/UnitFunctions.pas
author Christian Hammacher <bmasterc@gmail.com>
Fri Oct 21 20:50:01 2005 +0000 (2005-10-21)
changeset 146 7b81c8f8ee1f
parent 126 b072ae770357
permissions -rw-r--r--
Changed version number to 1.1
bmasterc@126
     1
unit UnitFunctions;
bmasterc@126
     2
bmasterc@126
     3
interface
bmasterc@126
     4
bmasterc@126
     5
uses SysUtils, Classes, Windows, IdFTPList, Math;
bmasterc@126
     6
bmasterc@126
     7
function CalcSpeed(eOld, eNew: Integer): String;
bmasterc@126
     8
// local
bmasterc@126
     9
function GetAllFiles(Mask: String; Attr: Integer; Recursive: Boolean; ShowDirs: Boolean; ShowPath: Boolean = True): TStringList;
bmasterc@126
    10
// ftp
bmasterc@126
    11
function GetAllDirs: TStringList;
bmasterc@126
    12
bmasterc@126
    13
implementation
bmasterc@126
    14
bmasterc@126
    15
uses UnitfrmMain;
bmasterc@126
    16
bmasterc@126
    17
function CalcSpeed(eOld, eNew: Integer): String;
bmasterc@126
    18
begin
bmasterc@126
    19
  Result := frmMain.Caption;
bmasterc@126
    20
  if (eOld < eNew) and (eOld <> 0) then begin
bmasterc@126
    21
    eOld := eNew - eOld;
bmasterc@126
    22
    //eOld := eOld *2; // this is only used for faster updates...
bmasterc@126
    23
    Result := 'Metamod:Source - Uploading with ' + FloatToStr(RoundTo(eOld / 1024, -2)) + ' kb/s';
bmasterc@126
    24
  end;
bmasterc@126
    25
end;
bmasterc@126
    26
bmasterc@126
    27
function GetAllFiles(Mask: String; Attr: Integer; Recursive: Boolean; ShowDirs: Boolean; ShowPath: Boolean = True): TStringList;
bmasterc@126
    28
var eSearch: TSearchRec;
bmasterc@126
    29
begin
bmasterc@126
    30
  Result := TStringList.Create;
bmasterc@126
    31
bmasterc@126
    32
  // Find all files
bmasterc@126
    33
  if FindFirst(Mask, Attr, eSearch) = 0 then
bmasterc@126
    34
  begin
bmasterc@126
    35
    repeat
bmasterc@126
    36
      if eSearch.Name[1] <> '.' then begin
bmasterc@126
    37
        if ShowPath then begin
bmasterc@126
    38
          if ((eSearch.Attr and Attr) = eSearch.Attr) and ((eSearch.Attr and faDirectory) <> eSearch.Attr) then
bmasterc@126
    39
            Result.Add(ExtractFilePath(Mask) + eSearch.Name)
bmasterc@126
    40
          else if (ShowDirs) and ((eSearch.Attr and faDirectory) = eSearch.Attr) then
bmasterc@126
    41
            Result.Add(ExtractFilePath(Mask) + eSearch.Name);
bmasterc@126
    42
        end
bmasterc@126
    43
        else begin
bmasterc@126
    44
          if ((eSearch.Attr and Attr) = eSearch.Attr) and ((eSearch.Attr and faDirectory) <> eSearch.Attr) then
bmasterc@126
    45
            Result.Add(eSearch.Name)
bmasterc@126
    46
          else if (ShowDirs) and ((eSearch.Attr and faDirectory) = eSearch.Attr) then
bmasterc@126
    47
            Result.Add(eSearch.Name);
bmasterc@126
    48
        end;
bmasterc@126
    49
bmasterc@126
    50
        if ((eSearch.Attr and faDirectory) = eSearch.Attr) and (Recursive) then begin
bmasterc@126
    51
          with GetAllFiles(ExtractFilePath(Mask) + eSearch.Name + '\' + ExtractFileName(Mask), Attr, True, ShowDirs, ShowPath) do begin
bmasterc@126
    52
            Result.Text := Result.Text + Text;
bmasterc@126
    53
            Free;
bmasterc@126
    54
          end;
bmasterc@126
    55
        end;
bmasterc@126
    56
      end;
bmasterc@126
    57
    until FindNext(eSearch) <> 0;
bmasterc@126
    58
  end;
bmasterc@126
    59
end;
bmasterc@126
    60
bmasterc@126
    61
function GetAllDirs: TStringList;
bmasterc@126
    62
var eList: TStringList;
bmasterc@126
    63
    i: integer;
bmasterc@126
    64
begin
bmasterc@126
    65
  eList := TStringList.Create;
bmasterc@126
    66
  frmMain.IdFTP.List(eList);
bmasterc@126
    67
  frmMain.IdFTP.DirectoryListing.LoadList(eList);
bmasterc@126
    68
  eList.Clear;
bmasterc@126
    69
  for i := 0 to frmMain.IdFTP.DirectoryListing.Count -1 do begin
bmasterc@126
    70
    if frmMain.IdFTP.DirectoryListing.Items[i].ItemType = ditDirectory then
bmasterc@126
    71
      eList.Add(frmMain.IdFTP.DirectoryListing.Items[i].FileName);
bmasterc@126
    72
  end;
bmasterc@126
    73
  Result := eList;
bmasterc@126
    74
end;
bmasterc@126
    75
bmasterc@126
    76
{ This is another possibility I coded because I couldn't find another bug...
bmasterc@126
    77
bmasterc@126
    78
function GetAllDirs: TStringList;
bmasterc@126
    79
var eList: TStringList;
bmasterc@126
    80
    i, eStart: integer;
bmasterc@126
    81
begin
bmasterc@126
    82
  eList := TStringList.Create;
bmasterc@126
    83
  frmMain.IdFTP.List(eList, '', True);
bmasterc@126
    84
  eStart := 0;
bmasterc@126
    85
  
bmasterc@126
    86
bmasterc@126
    87
 //   +----------------------------------------------------------------+
bmasterc@126
    88
 //   | drwxr-xr-x   5 web3     ftponly      2048 Jun 25 19:43 files   |
bmasterc@126
    89
 //   | drwxr-xr-x   2 web3     ftponly      2048 Jun 25 19:57 html    |
bmasterc@126
    90
 //   | drwxr-xr-x   3 root     root         2048 Jun 20 05:03 log     |
bmasterc@126
    91
 //   | drwxrwxrwx   2 web3     ftponly      2048 Jun 19  2004 phptmp  |
bmasterc@126
    92
 //   +----------------------------------------------------------------+
bmasterc@126
    93
bmasterc@126
    94
bmasterc@126
    95
  // at first remove all non-directories from the list
bmasterc@126
    96
  for i := eList.Count -1 downto 0 do begin
bmasterc@126
    97
    if Pos('d', eList[i]) <> 1 then
bmasterc@126
    98
      eList.Delete(i);
bmasterc@126
    99
  end;
bmasterc@126
   100
  // then we have to find the position where ALL filenames start...
bmasterc@126
   101
  for i := 0 to eList.Count -1 do begin
bmasterc@126
   102
    if (eStart = 0) and (Pos(':', eList[i]) <> 0) then
bmasterc@126
   103
      eStart := Pos(':', eList[i]);
bmasterc@126
   104
  end;
bmasterc@126
   105
bmasterc@126
   106
  if eStart = 0 then
bmasterc@126
   107
    eList.Clear
bmasterc@126
   108
  else begin
bmasterc@126
   109
    // find the position
bmasterc@126
   110
    for i := 0 to eList.Count -1 do begin
bmasterc@126
   111
      if Pos(':', eList[i]) <> 0 then begin
bmasterc@126
   112
        while (eStart <> Length(eList[i])) and (eList[i][eStart] <> #32) do
bmasterc@126
   113
          Inc(eStart, 1);
bmasterc@126
   114
      end;
bmasterc@126
   115
    end;
bmasterc@126
   116
    // remove the detail stuff...
bmasterc@126
   117
    for i := 0 to eList.Count -1 do
bmasterc@126
   118
      eList[i] := Copy(eList[i], eStart +1, Length(eList[i]));
bmasterc@126
   119
  end;
bmasterc@126
   120
bmasterc@126
   121
  Result := eList;
bmasterc@126
   122
end;  }
bmasterc@126
   123
bmasterc@126
   124
end.
bmasterc@126
   125
bmasterc@126
   126