installer/UnitfrmMain.pas
branchsourcemm-1.6.0
changeset 347 e82968c21606
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/installer/UnitfrmMain.pas	Tue Sep 18 20:03:47 2007 +0000
     1.3 @@ -0,0 +1,730 @@
     1.4 +unit UnitfrmMain;
     1.5 +
     1.6 +interface
     1.7 +
     1.8 +uses
     1.9 +  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    1.10 +  Dialogs, TFlatRadioButtonUnit, StdCtrls, ComCtrls, mxFlatControls, JvPageList,
    1.11 +  ExtCtrls, JvExControls, JvComponent, TFlatButtonUnit, jpeg, TFlatEditUnit,
    1.12 +  TFlatGaugeUnit, ImgList, FileCtrl, Registry, CheckLst, TFlatComboBoxUnit,
    1.13 +  TFlatCheckBoxUnit, IdBaseComponent, IdComponent, IdTCPConnection,
    1.14 +  IdTCPClient, IdFTP, IdException, IdAntiFreezeBase, IdAntiFreeze,
    1.15 +  IdIntercept, IdLogBase, IdLogFile, pngimage;
    1.16 +
    1.17 +type
    1.18 +  TfrmMain = class(TForm)
    1.19 +    jplWizard: TJvPageList;
    1.20 +    jspWelcome: TJvStandardPage;
    1.21 +    pnlButtons: TPanel;
    1.22 +    bvlSpace: TBevel;
    1.23 +    cmdNext: TFlatButton;
    1.24 +    cmdCancel: TFlatButton;
    1.25 +    imgInstall: TImage;
    1.26 +    lblWelcome: TLabel;
    1.27 +    lblInfo1: TLabel;
    1.28 +    lblInfo2: TLabel;
    1.29 +    lblInfo3: TLabel;
    1.30 +    jspLicense: TJvStandardPage;
    1.31 +    pnlLicense: TPanel;
    1.32 +    imgIcon1: TImage;
    1.33 +    lblTitle1: TLabel;
    1.34 +    lblSubTitle1: TLabel;
    1.35 +    freLicense: TmxFlatRichEdit;
    1.36 +    frbAgree: TFlatRadioButton;
    1.37 +    ftbDontAgree: TFlatRadioButton;
    1.38 +    jspInstallMethod: TJvStandardPage;
    1.39 +    pnlHeader2: TPanel;
    1.40 +    imgIcon2: TImage;
    1.41 +    lblTitle2: TLabel;
    1.42 +    lblSubTitle2: TLabel;
    1.43 +    lblInstallMethod: TLabel;
    1.44 +    pnlInstallMethod: TPanel;
    1.45 +    frbDedicatedServer: TFlatRadioButton;
    1.46 +    frbListenServer: TFlatRadioButton;
    1.47 +    frbSelectMod: TFlatRadioButton;
    1.48 +    frbFTP: TFlatRadioButton;
    1.49 +    cmdBack: TFlatButton;
    1.50 +    jspFTP: TJvStandardPage;
    1.51 +    pnlHeader3: TPanel;
    1.52 +    imgIcon3: TImage;
    1.53 +    lblTitle3: TLabel;
    1.54 +    lblSubTitle3: TLabel;
    1.55 +    lblStep1: TLabel;
    1.56 +    pnlFTPData: TPanel;
    1.57 +    lblHost: TLabel;
    1.58 +    txtHost: TFlatEdit;
    1.59 +    lblUserName: TLabel;
    1.60 +    txtUserName: TFlatEdit;
    1.61 +    txtPassword: TFlatEdit;
    1.62 +    lblPassword: TLabel;
    1.63 +    txtPort: TFlatEdit;
    1.64 +    lblPort: TLabel;
    1.65 +    lblStep2: TLabel;
    1.66 +    cmdConnect: TFlatButton;
    1.67 +    pnlDirectory: TPanel;
    1.68 +    trvDirectories: TTreeView;
    1.69 +    lblStep4: TLabel;
    1.70 +    jspInstallProgress: TJvStandardPage;
    1.71 +    pnlHeader5: TPanel;
    1.72 +    imgIcon4: TImage;
    1.73 +    lblTitle5: TLabel;
    1.74 +    lblSubTitle5: TLabel;
    1.75 +    ggeAll: TFlatGauge;
    1.76 +    lblProgress: TLabel;
    1.77 +    ggeItem: TFlatGauge;
    1.78 +    rtfDetails: TmxFlatRichEdit;
    1.79 +    lblDetails: TLabel;
    1.80 +    bvlSpace2: TBevel;
    1.81 +    ilImages: TImageList;
    1.82 +    bvlSpacer1: TBevel;
    1.83 +    bvlSpacer2: TBevel;
    1.84 +    bvlSpacer3: TBevel;
    1.85 +    bvlSpacer5: TBevel;
    1.86 +    jspSelectMod: TJvStandardPage;
    1.87 +    pnlSelectMod: TPanel;
    1.88 +    imgIcon5: TImage;
    1.89 +    lblSelectMod: TLabel;
    1.90 +    lblSelectModInfo: TLabel;
    1.91 +    bvlSelectMod: TBevel;
    1.92 +    lblInfo: TLabel;
    1.93 +    chkPassive: TFlatCheckBox;
    1.94 +    lblStep3: TLabel;
    1.95 +    pnlOS: TPanel;
    1.96 +    optWindows: TFlatRadioButton;
    1.97 +    optLinux: TFlatRadioButton;
    1.98 +    IdFTP: TIdFTP;
    1.99 +    cmdProxySettings: TFlatButton;
   1.100 +    IdAntiFreeze: TIdAntiFreeze;
   1.101 +    frbStandaloneServer: TFlatRadioButton;
   1.102 +    tmrSpeed: TTimer;
   1.103 +    IdLogFile: TIdLogFile;
   1.104 +    shpMods: TShape;
   1.105 +    trvMods: TTreeView;
   1.106 +    FlatRadioButton1: TFlatRadioButton;
   1.107 +    procedure jvwStepsCancelButtonClick(Sender: TObject);
   1.108 +    procedure cmdCancelClick(Sender: TObject);
   1.109 +    procedure cmdNextClick(Sender: TObject);
   1.110 +    procedure CheckNext(Sender: TObject);
   1.111 +    procedure cmdBackClick(Sender: TObject);
   1.112 +    procedure cmdConnectClick(Sender: TObject);
   1.113 +    procedure jplWizardChange(Sender: TObject);
   1.114 +    procedure FormCreate(Sender: TObject);
   1.115 +    procedure cmdProxySettingsClick(Sender: TObject);
   1.116 +    procedure txtPortChange(Sender: TObject);
   1.117 +    procedure trvDirectoriesExpanded(Sender: TObject; Node: TTreeNode);
   1.118 +    procedure trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
   1.119 +    procedure IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
   1.120 +      const AWorkCount: Integer);
   1.121 +    procedure FormClose(Sender: TObject; var Action: TCloseAction);
   1.122 +    procedure tmrSpeedTimer(Sender: TObject);
   1.123 +    procedure trvDirectoriesExpanding(Sender: TObject; Node: TTreeNode;
   1.124 +      var AllowExpansion: Boolean);
   1.125 +    procedure trvDirectoriesCollapsing(Sender: TObject; Node: TTreeNode;
   1.126 +      var AllowCollapse: Boolean);
   1.127 +    procedure trvModsClick(Sender: TObject);
   1.128 +    procedure trvDirectoriesMouseDown(Sender: TObject;
   1.129 +      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
   1.130 +  private
   1.131 +    OldProgress: Integer;
   1.132 +    CurrProgress: Integer;
   1.133 +  public
   1.134 +    procedure ExceptionHandler(Sender: TObject; E: Exception);
   1.135 +  end;
   1.136 +
   1.137 +var
   1.138 +  frmMain: TfrmMain;
   1.139 +
   1.140 +var VERSION: String = '<none>';
   1.141 +
   1.142 +implementation
   1.143 +
   1.144 +uses UnitFunctions, UnitfrmProxy, UnitInstall, UnitSelectModPath;
   1.145 +
   1.146 +{$R *.dfm}
   1.147 +
   1.148 +procedure TfrmMain.jvwStepsCancelButtonClick(Sender: TObject);
   1.149 +begin
   1.150 +  Close;
   1.151 +end;
   1.152 +
   1.153 +procedure TfrmMain.cmdCancelClick(Sender: TObject);
   1.154 +begin
   1.155 +  Close;
   1.156 +end;
   1.157 +
   1.158 +procedure TfrmMain.cmdNextClick(Sender: TObject);
   1.159 +var ePath: String;
   1.160 +    eRegistry: TRegistry;
   1.161 +    eStr: TStringList;
   1.162 +    CurNode: TTreeNode;
   1.163 +    eOS: TOS;
   1.164 +    i: integer;
   1.165 +begin
   1.166 +  { FTP }
   1.167 +  if jplWizard.ActivePage = jspFTP then begin
   1.168 +    if not IdFTP.Connected then
   1.169 +      IdFTP.Connect;
   1.170 +    eStr := TStringList.Create;
   1.171 +    ePath := '/';
   1.172 +    CurNode := trvDirectories.Selected;
   1.173 +    if (Assigned(CurNode)) then begin
   1.174 +      repeat
   1.175 +        ePath := '/' + CurNode.Text + ePath;
   1.176 +        CurNode := CurNode.Parent;
   1.177 +      until (not Assigned(CurNode));
   1.178 +    end;
   1.179 +    IdFTP.ChangeDir(ePath);
   1.180 +    IdFTP.List(eStr, '', False);
   1.181 +    if eStr.IndexOf('gameinfo.txt') = -1 then begin
   1.182 +      MessageBox(Handle, 'Invalid directory. Please select your mod directory and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.183 +      eStr.Free;
   1.184 +      exit;
   1.185 +    end
   1.186 +    else
   1.187 +      eStr.Free;
   1.188 +
   1.189 +    // design stuff
   1.190 +    trvDirectories.Enabled := False;
   1.191 +    cmdConnect.Enabled := False;
   1.192 +    optWindows.Enabled := False;
   1.193 +    optLinux.Enabled := False;
   1.194 +    Screen.Cursor := crHourGlass;
   1.195 +
   1.196 +    if optWindows.Checked then
   1.197 +      eOS := osWindows
   1.198 +    else
   1.199 +      eOS := osLinux;
   1.200 +
   1.201 +    jspInstallProgress.Show;
   1.202 +    // installation
   1.203 +    Screen.Cursor := crAppStart;
   1.204 +    InstallFTP(eOS);
   1.205 +  end
   1.206 +  else if jplWizard.ActivePage = jspInstallProgress then
   1.207 +    Close
   1.208 +  else if jplWizard.ActivePage = jspSelectMod then begin
   1.209 +    { Dedicated Server }
   1.210 +    if (frbDedicatedServer.Checked) or (frbStandaloneServer.Checked) then begin
   1.211 +      ePath := trvMods.Selected.Text;
   1.212 +      if ePath = 'Counter-Strike:Source' then
   1.213 +        ePath := 'cstrike'
   1.214 +      else if ePath = 'Day of Defeat:Source' then
   1.215 +        ePath := 'dod'
   1.216 +      else
   1.217 +        ePath := 'hl2mp';
   1.218 +      ePath := 'SteamApps\' + trvMods.Selected.Parent.Text + '\source dedicated server\' + ePath;
   1.219 +      // install it
   1.220 +      if frbDedicatedServer.Checked then begin
   1.221 +        if DirectoryExists(SteamPath + ePath) then begin
   1.222 +          jspInstallProgress.Show;
   1.223 +          InstallDedicated(IncludeTrailingPathDelimiter(SteamPath + ePath), True);
   1.224 +        end
   1.225 +        else begin
   1.226 +          MessageBox(Handle, 'Error: The directory of the mod you selected doesn''t exist any more. Run Dedicated Server with the chosen mod and try again.', PChar(Application.Title), MB_ICONERROR);
   1.227 +          jspSelectMod.Show;
   1.228 +          exit;
   1.229 +        end;
   1.230 +      end
   1.231 +      else begin
   1.232 +        if DirectoryExists(StandaloneServer + ePath) then begin
   1.233 +          jspInstallProgress.Show;
   1.234 +          InstallDedicated(IncludeTrailingPathDelimiter(StandaloneServer + ePath), False)
   1.235 +        end
   1.236 +        else begin
   1.237 +          MessageBox(Handle, 'Error: The directory of the mod you selected doesn''t exist (any more). Run Half-Life Dedicated Server with the chosen mod again and restart.', PChar(Application.Title), MB_ICONERROR);
   1.238 +          jspSelectMod.Show;
   1.239 +          exit;
   1.240 +        end;
   1.241 +      end;
   1.242 +    end;
   1.243 +    { Listen Server }
   1.244 +    if frbListenServer.Checked then begin
   1.245 +      ePath := trvMods.Selected.Text;
   1.246 +      if ePath = 'Counter-Strike:Source' then
   1.247 +        ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\counter-strike source\cstrike'
   1.248 +      else if ePath = 'Half-Life 2 Deathmatch' then
   1.249 +        ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\half-life 2 deathmatch\hl2mp'
   1.250 +      else
   1.251 +        ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\day of defeat source\dod';
   1.252 +
   1.253 +      if Pos(SteamPath, ePath) = 0 then
   1.254 +        MessageBox(Handle, 'An error occured. Please report this bug to the Metamod:Source team and post a new thread on the forums of www.amxmodx.org.', PChar(Application.Title), MB_ICONSTOP)
   1.255 +      else begin
   1.256 +         if not FileExists(ePath + '\gameinfo.txt') then begin
   1.257 +          MessageBox(Handle, 'You have to play this game once before installing Metamod:Source. Do that and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.258 +          exit;
   1.259 +        end;
   1.260 +
   1.261 +        jspInstallProgress.Show;
   1.262 +        InstallListen(IncludeTrailingPathDelimiter(ePath));
   1.263 +      end;
   1.264 +    end;
   1.265 +    { Custom mod below }
   1.266 +  end
   1.267 +  else if jplWizard.ActivePage <> jspInstallMethod then
   1.268 +    jplWizard.NextPage
   1.269 +  else begin
   1.270 +    if frbDedicatedServer.Checked then begin    // Dedicated Server
   1.271 +      eRegistry := TRegistry.Create(KEY_READ);
   1.272 +      try
   1.273 +        eRegistry.RootKey := HKEY_CURRENT_USER;
   1.274 +        if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
   1.275 +          ePath := eRegistry.ReadString('SteamPath');
   1.276 +          ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
   1.277 +          SteamPath := ePath;
   1.278 +
   1.279 +          ePath := ePath + 'SteamApps\';
   1.280 +          if DirectoryExists(ePath) then begin
   1.281 +            trvMods.Items.Clear;
   1.282 +            // Check Mods
   1.283 +            eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
   1.284 +            for i := 0 to eStr.Count -1 do begin
   1.285 +              CurNode := trvMods.Items.Add(nil, eStr[i]);
   1.286 +
   1.287 +              if DirectoryExists(ePath + eStr[i] + '\source dedicated server\cstrike') then
   1.288 +                trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
   1.289 +              if DirectoryExists(ePath + eStr[i] + '\source dedicated server\dod') then
   1.290 +                trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
   1.291 +              if DirectoryExists(ePath + eStr[i] + '\source dedicated server\hl2mp') then
   1.292 +                trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
   1.293 +
   1.294 +              if CurNode.Count = 0 then
   1.295 +                CurNode.Free
   1.296 +              else
   1.297 +                CurNode.Expand(False);
   1.298 +            end;
   1.299 +            // Misc
   1.300 +            jspSelectMod.Show;
   1.301 +            trvMods.Selected := nil;
   1.302 +            cmdNext.Enabled := False;
   1.303 +          end
   1.304 +          else
   1.305 +            MessageBox(Handle, 'You have to run Dedicated Server once before installing Metamod:Source!', 'Error', MB_ICONWARNING);
   1.306 +        end
   1.307 +        else
   1.308 +          MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   1.309 +      finally
   1.310 +        eRegistry.Free;
   1.311 +      end;
   1.312 +    end
   1.313 +    else if frbListenServer.Checked then begin  // Listen Server
   1.314 +      eRegistry := TRegistry.Create(KEY_READ);
   1.315 +      try
   1.316 +        eRegistry.RootKey := HKEY_CURRENT_USER;
   1.317 +        if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
   1.318 +          ePath := eRegistry.ReadString('SteamPath');
   1.319 +          ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
   1.320 +          SteamPath := ePath;
   1.321 +
   1.322 +          ePath := ePath + 'SteamApps\';
   1.323 +          if DirectoryExists(ePath) then begin
   1.324 +            trvMods.Items.Clear;
   1.325 +            // Check Mods
   1.326 +            eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
   1.327 +            for i := 0 to eStr.Count -1 do begin
   1.328 +              CurNode := trvMods.Items.Add(nil, eStr[i]);
   1.329 +
   1.330 +              if DirectoryExists(ePath + eStr[i] + '\counter-strike source') then
   1.331 +                trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
   1.332 +              if DirectoryExists(ePath + eStr[i] + '\day of defeat source') then
   1.333 +                trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
   1.334 +              if DirectoryExists(ePath + eStr[i] + '\half-life 2 deathmatch') then
   1.335 +                trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
   1.336 +
   1.337 +              if CurNode.Count = 0 then
   1.338 +                CurNode.Free
   1.339 +              else
   1.340 +                CurNode.Expand(False);
   1.341 +            end;
   1.342 +            // Misc
   1.343 +            jspSelectMod.Show;
   1.344 +            trvMods.Selected := nil;
   1.345 +            cmdNext.Enabled := False;
   1.346 +          end
   1.347 +          else
   1.348 +            MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   1.349 +        end
   1.350 +        else
   1.351 +          MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   1.352 +      finally
   1.353 +        eRegistry.Free;
   1.354 +      end;
   1.355 +    end
   1.356 +    else if frbStandaloneServer.Checked then begin // Standalone Server
   1.357 +      eRegistry := TRegistry.Create;
   1.358 +      try
   1.359 +        eRegistry.RootKey := HKEY_CURRENT_USER;
   1.360 +        if eRegistry.OpenKey('Software\Valve\HLServer', False) then begin
   1.361 +          StandaloneServer := IncludeTrailingPathDelimiter(eRegistry.ReadString('InstallPath'));
   1.362 +          if DirectoryExists(StandaloneServer + 'cstrike') then
   1.363 +            trvMods.Items.Add(nil, 'Counter-Strike:Source');
   1.364 +          if DirectoryExists(StandaloneServer + 'dod') then
   1.365 +            trvMods.Items.Add(nil, 'Day of Defeat:Source');
   1.366 +          if DirectoryExists(StandaloneServer + 'hl2mp') then
   1.367 +            trvMods.Items.Add(nil, 'Half-Life 2 Deatmatch');
   1.368 +          jspSelectMod.Show;
   1.369 +          cmdNext.Enabled := False;
   1.370 +        end
   1.371 +        else
   1.372 +          MessageBox(Handle, 'You haven''t installed Half-Life Dedicated Server yet!',  'Error', MB_ICONWARNING);
   1.373 +      finally
   1.374 +        eRegistry.Free;
   1.375 +      end;
   1.376 +    end
   1.377 +    else if frbSelectMod.Checked then begin 
   1.378 +      { Custom mod }
   1.379 +      if frmSelectModPath.ShowModal = mrOk then begin
   1.380 +        jspInstallProgress.Show;
   1.381 +        InstallCustom(IncludeTrailingPathDelimiter(frmSelectModPath.trvDirectory.SelectedFolder.PathName), osWindows);
   1.382 +      end;
   1.383 +    end
   1.384 +    else if frbFTP.Checked then // FTP
   1.385 +      jspFTP.Show;
   1.386 +  end;
   1.387 +end;
   1.388 +
   1.389 +procedure TfrmMain.CheckNext(Sender: TObject);
   1.390 +begin
   1.391 +  cmdNext.Enabled := frbAgree.Checked;
   1.392 +end;
   1.393 +
   1.394 +procedure TfrmMain.cmdBackClick(Sender: TObject);
   1.395 +begin
   1.396 +  if jplWizard.ActivePage = jspFTP then
   1.397 +    jspInstallMethod.Show
   1.398 +  else begin
   1.399 +    jplWizard.PrevPage;
   1.400 +    cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
   1.401 +  end;
   1.402 +end;
   1.403 +
   1.404 +procedure TfrmMain.cmdConnectClick(Sender: TObject);
   1.405 +var i: integer;
   1.406 +    eStr: TStringList;
   1.407 +    CurNode: TTreeNode;
   1.408 +    Path: String;
   1.409 +begin
   1.410 +  if (Trim(txtHost.Text) = '') or (Trim(txtUsername.Text) = '') then
   1.411 +    MessageBox(Handle, 'Please fill in each field!', PChar(Application.Title), MB_ICONWARNING)
   1.412 +  else if cmdConnect.Caption = 'Connect' then begin
   1.413 +    // ... design stuff ...
   1.414 +    Screen.Cursor := crHourGlass;
   1.415 +    cmdConnect.Enabled := False;
   1.416 +    cmdProxySettings.Enabled := False;
   1.417 +    txtHost.Enabled := False;
   1.418 +    txtPort.Enabled := False;
   1.419 +    txtUsername.Enabled := False;
   1.420 +    txtPassword.Enabled := False;
   1.421 +    chkPassive.Enabled := False;
   1.422 +    cmdConnect.Caption := 'Connecting...';
   1.423 +    // ... set values ...
   1.424 +    IdFTP.Host := txtHost.Text;
   1.425 +    IdFTP.Port := StrToInt(txtPort.Text);
   1.426 +    IdFTP.Username := txtUsername.Text;
   1.427 +    IdFTP.Passive := chkPassive.Checked;
   1.428 +    IdFTP.Password := txtPassword.Text;
   1.429 +    // ... connect and check values etc ...
   1.430 +    try
   1.431 +      IdFTP.Connect(True, 15000);
   1.432 +      // ... get initial directory ...
   1.433 +      Path := IdFTP.RetrieveCurrentDir;
   1.434 +      // ... "fix" path ...
   1.435 +      eStr := TStringList.Create;
   1.436 +      eStr.Text := StringReplace(Path, '/', #13, [rfReplaceAll]);
   1.437 +      for i := eStr.Count -1 downto 0 do begin
   1.438 +        if eStr[i] = '' then
   1.439 +          eStr.Delete(i);
   1.440 +      end;
   1.441 +      if (Copy(Path, Length(Path) -1, 1) <> '/') then
   1.442 +        Path := Path + '/';
   1.443 +      // ... connect successful, change captions ...
   1.444 +      trvDirectories.Enabled := True;
   1.445 +      cmdConnect.Enabled := True;
   1.446 +      cmdConnect.Caption := 'Disconnect';
   1.447 +      // ... change to / and create all the directories ...
   1.448 +      CurNode := nil;
   1.449 +      if (Path <> '/') then begin
   1.450 +        try
   1.451 +          IdFTP.ChangeDir('/');
   1.452 +          with GetAllDirs do begin
   1.453 +            for i := 0 to Count -1 do begin
   1.454 +              if (Assigned(CurNode)) then
   1.455 +                trvDirectories.Items.AddChild(trvDirectories.Items.Add(nil, Strings[i]), 'Scanning...')
   1.456 +              else begin
   1.457 +                CurNode := trvDirectories.Items.Add(nil, Strings[i]);
   1.458 +                trvDirectories.Items.AddChild(CurNode, 'Scanning...');
   1.459 +                if (Pos('/' + CurNode.Text + '/', Path) = 0) then
   1.460 +                  CurNode := nil;
   1.461 +              end
   1.462 +            end;
   1.463 +            Free;
   1.464 +          end;
   1.465 +          IdFTP.ChangeDir(Path);
   1.466 +        except
   1.467 +          if (IdFTP.Connected) then
   1.468 +            IdFTP.ChangeDir(Path)
   1.469 +          else
   1.470 +            IdFTP.Connect;
   1.471 +        end;
   1.472 +      end;
   1.473 +      // ... find directories in start path ...
   1.474 +      if eStr.Count <> 0 then begin
   1.475 +        for i := 0 to eStr.Count -1 do begin
   1.476 +          if (not ((i = 0) and (Assigned(CurNode)))) then
   1.477 +            CurNode := trvDirectories.Items.AddChild(CurNode, eStr[i]);
   1.478 +        end;
   1.479 +      end;
   1.480 +      trvDirectories.Selected := CurNode;
   1.481 +      eStr.Free;
   1.482 +      // ... scan for directories ...
   1.483 +      with GetAllDirs do begin
   1.484 +        for i := 0 to Count -1 do
   1.485 +          trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(CurNode, Strings[i]), 'Scanning...');
   1.486 +        Free;
   1.487 +      end;
   1.488 +
   1.489 +      if Assigned(CurNode) then
   1.490 +        CurNode.Expand(False);
   1.491 +    except
   1.492 +      on E: Exception do begin
   1.493 +        // reset button properties
   1.494 +        cmdConnect.Enabled := True;
   1.495 +        txtHost.Enabled := True;
   1.496 +        txtPort.Enabled := True;
   1.497 +        txtUsername.Enabled := True;
   1.498 +        txtPassword.Enabled := True;
   1.499 +        chkPassive.Enabled := True;
   1.500 +        cmdProxySettings.Enabled := True;
   1.501 +        cmdNext.Enabled := False;
   1.502 +        cmdConnect.Caption := 'Connect';
   1.503 +        // analyze messages
   1.504 +        if Pos('Login incorrect.', E.Message) <> 0 then begin // login failed
   1.505 +          MessageBox(Handle, 'Login incorrect. Check your FTP settings and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.506 +          txtUsername.SetFocus;
   1.507 +          txtUsername.SelectAll;
   1.508 +        end
   1.509 +        else if Pos('Host not found.', E.Message) <> 0 then begin // host not found
   1.510 +          MessageBox(Handle, 'The entered host couldn''t be found. Check your settings and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.511 +          txtHost.SetFocus;
   1.512 +          txtHost.SelectAll;
   1.513 +        end
   1.514 +        else if Pos('Connection refused.', E.Message) <> 0 then begin // wrong port (?)
   1.515 +          MessageBox(Handle, 'The host refused the connection. Check your port and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.516 +          txtPort.SetFocus;
   1.517 +          txtPort.SelectAll;
   1.518 +        end
   1.519 +        else if E is EIdProtocolReplyError then begin // wrong port
   1.520 +          MessageBox(Handle, 'The port you entered is definitely wrong. Check it and try again.', PChar(Application.Title), MB_ICONWARNING);
   1.521 +          txtPort.SetFocus;
   1.522 +          txtPort.SelectAll;
   1.523 +        end
   1.524 +        else
   1.525 +          MessageBox(Handle, PChar(E.Message), PChar(Application.Title), MB_ICONWARNING); // unknown error
   1.526 +        // ... connect failed, leave procedure ...
   1.527 +        Screen.Cursor := crDefault;
   1.528 +        exit;
   1.529 +      end;
   1.530 +    end;
   1.531 +
   1.532 +    Screen.Cursor := crDefault;
   1.533 +  end
   1.534 +  else begin
   1.535 +    Screen.Cursor := crHourGlass;
   1.536 +    IdFTP.Quit;
   1.537 +    trvDirectories.Items.Clear;
   1.538 +    trvDirectories.Enabled := False;
   1.539 +    cmdConnect.Enabled := True;
   1.540 +    cmdProxySettings.Enabled := True;
   1.541 +    txtHost.Enabled := True;
   1.542 +    txtPort.Enabled := True;
   1.543 +    txtUsername.Enabled := True;
   1.544 +    txtPassword.Enabled := True;
   1.545 +    chkPassive.Enabled := True;
   1.546 +    cmdConnect.Caption := 'Connect';
   1.547 +    cmdNext.Enabled := False;
   1.548 +    Screen.Cursor := crDefault;
   1.549 +  end;
   1.550 +end;
   1.551 +
   1.552 +procedure TfrmMain.jplWizardChange(Sender: TObject);
   1.553 +begin
   1.554 +  if (jplWizard.ActivePage = jspInstallProgress) then begin
   1.555 +    cmdNext.Caption := '&Finish';
   1.556 +    cmdNext.Enabled := False;
   1.557 +    cmdBack.Visible := False;
   1.558 +  end
   1.559 +  else begin
   1.560 +    cmdNext.Caption := '&Next >';
   1.561 +    cmdNext.Enabled := True;
   1.562 +    cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
   1.563 +  end;
   1.564 +
   1.565 +  if (jplWizard.ActivePage = jspLicense) then
   1.566 +    cmdNext.Enabled := frbAgree.Checked;
   1.567 +
   1.568 +  if (jplWizard.ActivePage = jspFTP) then
   1.569 +    cmdNext.Enabled := False;
   1.570 +end;
   1.571 +
   1.572 +procedure TfrmMain.FormCreate(Sender: TObject);
   1.573 +begin
   1.574 +  if LowerCase(ParamStr(1)) = '-logftp' then begin
   1.575 +    MessageBox(Handle, 'FTP installation will be logged to FTP.log!', PChar(Application.Title), MB_ICONINFORMATION);
   1.576 +    IdLogFile.Filename := ExtractFilePath(ParamStr(0)) + 'FTP.log';
   1.577 +    IdLogFile.Active := True;
   1.578 +  end;
   1.579 +
   1.580 +  rtfDetails.Clear;
   1.581 +end;
   1.582 +
   1.583 +procedure TfrmMain.cmdProxySettingsClick(Sender: TObject);
   1.584 +begin
   1.585 +  frmProxy.ShowModal;
   1.586 +  // Apply Proxy Settings
   1.587 +  case frmProxy.cboProxy.ItemIndex of
   1.588 +    0: IdFTP.ProxySettings.ProxyType := fpcmNone; // none
   1.589 +    1: IdFTP.ProxySettings.ProxyType := fpcmHttpProxyWithFtp; // HTTP Proxy with FTP
   1.590 +    2: IdFTP.ProxySettings.ProxyType := fpcmOpen; // Open
   1.591 +    3: IdFTP.ProxySettings.ProxyType := fpcmSite; // Site
   1.592 +    4: IdFTP.ProxySettings.ProxyType := fpcmTransparent; // Transparent
   1.593 +    5: IdFTP.ProxySettings.ProxyType := fpcmUserPass; // User (Password)
   1.594 +    6: IdFTP.ProxySettings.ProxyType := fpcmUserSite; // User (Site)
   1.595 +  end;
   1.596 +
   1.597 +  IdFTP.ProxySettings.Host := frmProxy.txtHost.Text;
   1.598 +  IdFTP.ProxySettings.UserName := frmProxy.txtPort.Text;
   1.599 +  IdFTP.ProxySettings.Password := frmProxy.txtPassword.Text;
   1.600 +  IdFTP.ProxySettings.Port := StrToInt(frmProxy.txtPort.Text);
   1.601 +end;
   1.602 +
   1.603 +procedure TfrmMain.txtPortChange(Sender: TObject);
   1.604 +var i: integer;
   1.605 +begin
   1.606 +  if txtPort.Text = '' then
   1.607 +    txtPort.Text := '21'
   1.608 +  else begin
   1.609 +    // check if value is numeric...
   1.610 +    for i := Length(txtPort.Text) downto 1 do begin
   1.611 +      if Pos(txtPort.Text[i], '0123456789') = 0 then begin
   1.612 +        txtPort.Text := '21';
   1.613 +        txtPort.SelStart := 4;
   1.614 +        exit;
   1.615 +      end;
   1.616 +    end;
   1.617 +  end;
   1.618 +end;
   1.619 +
   1.620 +procedure TfrmMain.trvDirectoriesExpanded(Sender: TObject;
   1.621 +  Node: TTreeNode);
   1.622 +var ePath: String;
   1.623 +    CurNode: TTreeNode;
   1.624 +    i: integer;
   1.625 +begin
   1.626 +  if Node.Item[0].Text = 'Scanning...' then begin // no directories added yet
   1.627 +    Screen.Cursor := crHourGlass;
   1.628 +    // get complete path
   1.629 +    ePath := '/';
   1.630 +    CurNode := Node;
   1.631 +    repeat
   1.632 +      ePath := '/' + CurNode.Text + ePath;
   1.633 +      CurNode := CurNode.Parent;
   1.634 +    until (not Assigned(CurNode));
   1.635 +    // change dir and add directories in it
   1.636 +    try
   1.637 +      Repaint;
   1.638 +      IdFTP.ChangeDir(ePath);
   1.639 +      with GetAllDirs do begin
   1.640 +        Node.Item[0].Free;
   1.641 +        for i := 0 to Count -1 do begin
   1.642 +          trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(Node, Strings[i]), 'Scanning...');
   1.643 +        end;
   1.644 +        Free;
   1.645 +      end;
   1.646 +    finally
   1.647 +      Application.ProcessMessages;
   1.648 +    end;
   1.649 +    Screen.Cursor := crDefault;
   1.650 +  end;
   1.651 +end;
   1.652 +
   1.653 +procedure TfrmMain.trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
   1.654 +begin
   1.655 +  cmdNext.Enabled := Assigned(trvDirectories.Selected);
   1.656 +end;
   1.657 +
   1.658 +procedure TfrmMain.IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
   1.659 +  const AWorkCount: Integer);
   1.660 +begin
   1.661 +  if AWorkCount > 15 then begin
   1.662 +    ggeItem.Progress := AWorkCount;
   1.663 +    CurrProgress := AWorkCount;
   1.664 +  end;
   1.665 +
   1.666 +  if Cancel then
   1.667 +    IdFTP.Abort;
   1.668 +    
   1.669 +  Application.ProcessMessages;
   1.670 +end;
   1.671 +
   1.672 +procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
   1.673 +begin
   1.674 +  if (jplWizard.ActivePage = jspFTP) and (IdFTP.Connected) then
   1.675 +    IdFTP.Quit;
   1.676 +  if (jplWizard.ActivePage = jspInstallProgress) and (ggeAll.Progress <> ggeAll.MaxValue) and (not Cancel) then begin
   1.677 +    if MessageBox(Handle, 'Do you really want to cancel the installation?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNO) = mrYes then begin
   1.678 +      Screen.Cursor := crDefault;
   1.679 +      Application.OnException := ExceptionHandler;
   1.680 +      Cancel := True;
   1.681 +      if IdFTP.Connected then
   1.682 +        IdFTP.Quit;
   1.683 +    end
   1.684 +    else
   1.685 +      Action := caNone;
   1.686 +  end;
   1.687 +end;
   1.688 +
   1.689 +procedure TfrmMain.ExceptionHandler(Sender: TObject; E: Exception);
   1.690 +begin
   1.691 +  // IF any exceptions were raised after close, nobody would want them so leave this empty
   1.692 +end;
   1.693 +
   1.694 +procedure TfrmMain.tmrSpeedTimer(Sender: TObject);
   1.695 +begin
   1.696 +  Caption := CalcSpeed(OldProgress, CurrProgress);
   1.697 +  OldProgress := CurrProgress;
   1.698 +end;
   1.699 +
   1.700 +procedure TfrmMain.trvDirectoriesExpanding(Sender: TObject;
   1.701 +  Node: TTreeNode; var AllowExpansion: Boolean);
   1.702 +begin
   1.703 +  Node.ImageIndex := 1;
   1.704 +  Node.SelectedIndex := 1;
   1.705 +end;
   1.706 +
   1.707 +procedure TfrmMain.trvDirectoriesCollapsing(Sender: TObject;
   1.708 +  Node: TTreeNode; var AllowCollapse: Boolean);
   1.709 +begin
   1.710 +  Node.ImageIndex := 0;
   1.711 +  Node.SelectedIndex := 0;
   1.712 +end;
   1.713 +
   1.714 +procedure TfrmMain.trvModsClick(Sender: TObject);
   1.715 +begin
   1.716 +  if Assigned(trvMods.Selected) then
   1.717 +    cmdNext.Enabled := Assigned(trvMods.Selected.Parent)
   1.718 +  else
   1.719 +    cmdNext.Enabled := False;
   1.720 +end;
   1.721 +
   1.722 +procedure TfrmMain.trvDirectoriesMouseDown(Sender: TObject;
   1.723 +  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
   1.724 +var Node: TTreeNode;
   1.725 +begin
   1.726 +  Node := trvDirectories.GetNodeAt(X, Y);
   1.727 +  if (Assigned(Node)) then begin
   1.728 +    if (Node.DisplayRect(True).Right < X) then
   1.729 +      trvDirectories.Selected := nil;
   1.730 +  end;
   1.731 +end;
   1.732 +
   1.733 +end.