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