installer/UnitfrmMain.pas
author Christian Hammacher <bmasterc@gmail.com>
Tue Jun 27 22:39:42 2006 +0000 (2006-06-27)
changeset 214 6f98af14f97f
parent 212 12e438a82d05
child 237 d141174cd362
permissions -rw-r--r--
added multi-account support
bumped version number to 1.2.4 (whoa, magic)
     1 unit UnitfrmMain;
     2 
     3 interface
     4 
     5 uses
     6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     7   Dialogs, TFlatRadioButtonUnit, StdCtrls, ComCtrls, mxFlatControls, JvPageList,
     8   ExtCtrls, JvExControls, JvComponent, TFlatButtonUnit, jpeg, TFlatEditUnit,
     9   TFlatGaugeUnit, ImgList, FileCtrl, Registry, CheckLst, TFlatComboBoxUnit,
    10   TFlatCheckBoxUnit, IdBaseComponent, IdComponent, IdTCPConnection,
    11   IdTCPClient, IdFTP, IdException, IdAntiFreezeBase, IdAntiFreeze,
    12   IdIntercept, IdLogBase, IdLogFile;
    13 
    14 type
    15   TfrmMain = class(TForm)
    16     jplWizard: TJvPageList;
    17     jspWelcome: TJvStandardPage;
    18     pnlButtons: TPanel;
    19     bvlSpace: TBevel;
    20     cmdNext: TFlatButton;
    21     cmdCancel: TFlatButton;
    22     imgInstall: TImage;
    23     lblWelcome: TLabel;
    24     lblInfo1: TLabel;
    25     lblInfo2: TLabel;
    26     lblInfo3: TLabel;
    27     jspLicense: TJvStandardPage;
    28     pnlLicense: TPanel;
    29     imgIcon1: TImage;
    30     lblTitle1: TLabel;
    31     lblSubTitle1: TLabel;
    32     freLicense: TmxFlatRichEdit;
    33     frbAgree: TFlatRadioButton;
    34     ftbDontAgree: TFlatRadioButton;
    35     jspInstallMethod: TJvStandardPage;
    36     pnlHeader2: TPanel;
    37     imgIcon2: TImage;
    38     lblTitle2: TLabel;
    39     lblSubTitle2: TLabel;
    40     lblInstallMethod: TLabel;
    41     pnlInstallMethod: TPanel;
    42     frbDedicatedServer: TFlatRadioButton;
    43     frbListenServer: TFlatRadioButton;
    44     frbSelectMod: TFlatRadioButton;
    45     frbFTP: TFlatRadioButton;
    46     cmdBack: TFlatButton;
    47     jspFTP: TJvStandardPage;
    48     pnlHeader3: TPanel;
    49     imgIcon3: TImage;
    50     lblTitle3: TLabel;
    51     lblSubTitle3: TLabel;
    52     lblStep1: TLabel;
    53     pnlFTPData: TPanel;
    54     lblHost: TLabel;
    55     txtHost: TFlatEdit;
    56     lblUserName: TLabel;
    57     txtUserName: TFlatEdit;
    58     txtPassword: TFlatEdit;
    59     lblPassword: TLabel;
    60     txtPort: TFlatEdit;
    61     lblPort: TLabel;
    62     lblStep2: TLabel;
    63     cmdConnect: TFlatButton;
    64     pnlDirectory: TPanel;
    65     trvDirectories: TTreeView;
    66     lblStep4: TLabel;
    67     jspInstallProgress: TJvStandardPage;
    68     pnlHeader5: TPanel;
    69     imgIcon4: TImage;
    70     lblTitle5: TLabel;
    71     lblSubTitle5: TLabel;
    72     ggeAll: TFlatGauge;
    73     lblProgress: TLabel;
    74     ggeItem: TFlatGauge;
    75     rtfDetails: TmxFlatRichEdit;
    76     lblDetails: TLabel;
    77     bvlSpace2: TBevel;
    78     ilImages: TImageList;
    79     bvlSpacer1: TBevel;
    80     bvlSpacer2: TBevel;
    81     bvlSpacer3: TBevel;
    82     bvlSpacer5: TBevel;
    83     jspSelectMod: TJvStandardPage;
    84     pnlSelectMod: TPanel;
    85     imgIcon5: TImage;
    86     lblSelectMod: TLabel;
    87     lblSelectModInfo: TLabel;
    88     bvlSelectMod: TBevel;
    89     lblInfo: TLabel;
    90     chkPassive: TFlatCheckBox;
    91     lblStep3: TLabel;
    92     pnlOS: TPanel;
    93     optWindows: TFlatRadioButton;
    94     optLinux: TFlatRadioButton;
    95     IdFTP: TIdFTP;
    96     cmdProxySettings: TFlatButton;
    97     IdAntiFreeze: TIdAntiFreeze;
    98     frbStandaloneServer: TFlatRadioButton;
    99     tmrSpeed: TTimer;
   100     IdLogFile: TIdLogFile;
   101     shpMods: TShape;
   102     trvMods: TTreeView;
   103     FlatRadioButton1: TFlatRadioButton;
   104     procedure jvwStepsCancelButtonClick(Sender: TObject);
   105     procedure cmdCancelClick(Sender: TObject);
   106     procedure cmdNextClick(Sender: TObject);
   107     procedure CheckNext(Sender: TObject);
   108     procedure cmdBackClick(Sender: TObject);
   109     procedure cmdConnectClick(Sender: TObject);
   110     procedure jplWizardChange(Sender: TObject);
   111     procedure FormCreate(Sender: TObject);
   112     procedure cmdProxySettingsClick(Sender: TObject);
   113     procedure txtPortChange(Sender: TObject);
   114     procedure trvDirectoriesExpanded(Sender: TObject; Node: TTreeNode);
   115     procedure trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
   116     procedure IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
   117       const AWorkCount: Integer);
   118     procedure FormClose(Sender: TObject; var Action: TCloseAction);
   119     procedure tmrSpeedTimer(Sender: TObject);
   120     procedure trvDirectoriesExpanding(Sender: TObject; Node: TTreeNode;
   121       var AllowExpansion: Boolean);
   122     procedure trvDirectoriesCollapsing(Sender: TObject; Node: TTreeNode;
   123       var AllowCollapse: Boolean);
   124     procedure trvModsClick(Sender: TObject);
   125   private
   126     OldProgress: Integer;
   127     CurrProgress: Integer;
   128   public
   129     procedure ExceptionHandler(Sender: TObject; E: Exception);
   130   end;
   131 
   132 var
   133   frmMain: TfrmMain;
   134 
   135 var VERSION: String = '1.2.4';
   136 
   137 implementation
   138 
   139 uses UnitFunctions, UnitfrmProxy, UnitInstall, UnitSelectModPath;
   140 
   141 {$R *.dfm}
   142 
   143 procedure TfrmMain.jvwStepsCancelButtonClick(Sender: TObject);
   144 begin
   145   Close;
   146 end;
   147 
   148 procedure TfrmMain.cmdCancelClick(Sender: TObject);
   149 begin
   150   Close;
   151 end;
   152 
   153 procedure TfrmMain.cmdNextClick(Sender: TObject);
   154 var ePath: String;
   155     eRegistry: TRegistry;
   156     eStr: TStringList;
   157     CurNode: TTreeNode;
   158     eOS: TOS;
   159     i: integer;
   160 begin
   161   { FTP }
   162   if jplWizard.ActivePage = jspFTP then begin
   163     if not IdFTP.Connected then
   164       IdFTP.Connect;
   165     eStr := TStringList.Create;
   166     ePath := '/';
   167     CurNode := trvDirectories.Selected;
   168     repeat
   169       ePath := '/' + CurNode.Text + ePath;
   170       CurNode := CurNode.Parent;
   171     until (not Assigned(CurNode));
   172     IdFTP.ChangeDir(ePath); 
   173     IdFTP.List(eStr, '', False);
   174     if eStr.IndexOf('gameinfo.txt') = -1 then begin
   175       MessageBox(Handle, 'Invalid directory. Please select your mod directory and try again.', PChar(Application.Title), MB_ICONWARNING);
   176       eStr.Free;
   177       exit;
   178     end
   179     else
   180       eStr.Free;
   181 
   182     // design stuff
   183     trvDirectories.Enabled := False;
   184     cmdConnect.Enabled := False;
   185     optWindows.Enabled := False;
   186     optLinux.Enabled := False;
   187     Screen.Cursor := crHourGlass;
   188 
   189     if optWindows.Checked then
   190       eOS := osWindows
   191     else
   192       eOS := osLinux;
   193 
   194     jspInstallProgress.Show;
   195     // installation
   196     Screen.Cursor := crAppStart;
   197     InstallFTP(eOS);
   198   end
   199   else if jplWizard.ActivePage = jspInstallProgress then
   200     Close
   201   else if jplWizard.ActivePage = jspSelectMod then begin
   202     { Dedicated Server }
   203     if (frbDedicatedServer.Checked) or (frbStandaloneServer.Checked) then begin
   204       ePath := trvMods.Selected.Text;
   205       if ePath = 'Counter-Strike:Source' then
   206         ePath := 'cstrike'
   207       else if ePath = 'Day of Defeat:Source' then
   208         ePath := 'dod'
   209       else
   210         ePath := 'hl2mp';
   211       ePath := 'SteamApps\' + trvMods.Selected.Parent.Text + '\source dedicated server\' + ePath;
   212       // install it
   213       if frbDedicatedServer.Checked then begin
   214         if DirectoryExists(SteamPath + ePath) then begin
   215           jspInstallProgress.Show;
   216           InstallDedicated(IncludeTrailingPathDelimiter(SteamPath + ePath), True);
   217         end
   218         else begin
   219           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);
   220           jspSelectMod.Show;
   221           exit;
   222         end;
   223       end
   224       else begin
   225         if DirectoryExists(StandaloneServer + ePath) then begin
   226           jspInstallProgress.Show;
   227           InstallDedicated(IncludeTrailingPathDelimiter(StandaloneServer + ePath), False)
   228         end
   229         else begin
   230           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);
   231           jspSelectMod.Show;
   232           exit;
   233         end;
   234       end;
   235     end;
   236     { Listen Server }
   237     if frbListenServer.Checked then begin
   238       ePath := trvMods.Selected.Text;
   239       if ePath = 'Counter-Strike:Source' then
   240         ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\counter-strike source\cstrike'
   241       else if ePath = 'Half-Life 2 Deathmatch' then
   242         ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\half-life 2 deathmatch\hl2mp'
   243       else
   244         ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\day of defeat source\dod';
   245 
   246       if Pos(SteamPath, ePath) = 0 then
   247         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)
   248       else begin
   249          if not FileExists(ePath + '\gameinfo.txt') then begin
   250           MessageBox(Handle, 'You have to play this game once before installing Metamod:Source. Do that and try again.', PChar(Application.Title), MB_ICONWARNING);
   251           exit;
   252         end;
   253 
   254         jspInstallProgress.Show;
   255         InstallListen(IncludeTrailingPathDelimiter(ePath));
   256       end;
   257     end;
   258     { Custom mod below }
   259   end
   260   else if jplWizard.ActivePage <> jspInstallMethod then
   261     jplWizard.NextPage
   262   else begin
   263     if frbDedicatedServer.Checked then begin    // Dedicated Server
   264       eRegistry := TRegistry.Create(KEY_READ);
   265       try
   266         eRegistry.RootKey := HKEY_CURRENT_USER;
   267         if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
   268           ePath := eRegistry.ReadString('SteamPath');
   269           ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
   270           SteamPath := ePath;
   271 
   272           ePath := ePath + 'SteamApps\';
   273           if DirectoryExists(ePath) then begin
   274             trvMods.Items.Clear;
   275             // Check Mods
   276             eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
   277             for i := 0 to eStr.Count -1 do begin
   278               CurNode := trvMods.Items.Add(nil, eStr[i]);
   279 
   280               if DirectoryExists(ePath + eStr[i] + '\source dedicated server\cstrike') then
   281                 trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
   282               if DirectoryExists(ePath + eStr[i] + '\source dedicated server\dod') then
   283                 trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
   284               if DirectoryExists(ePath + eStr[i] + '\source dedicated server\hl2mp') then
   285                 trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
   286 
   287               if CurNode.Count = 0 then
   288                 CurNode.Free
   289               else
   290                 CurNode.Expand(False);
   291             end;
   292             // Misc
   293             jspSelectMod.Show;
   294             trvMods.Selected := nil;
   295             cmdNext.Enabled := False;
   296           end
   297           else
   298             MessageBox(Handle, 'You have to run Dedicated Server once before installing Metamod:Source!', 'Error', MB_ICONWARNING);
   299         end
   300         else
   301           MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   302       finally
   303         eRegistry.Free;
   304       end;
   305     end
   306     else if frbListenServer.Checked then begin  // Listen Server
   307       eRegistry := TRegistry.Create(KEY_READ);
   308       try
   309         eRegistry.RootKey := HKEY_CURRENT_USER;
   310         if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
   311           ePath := eRegistry.ReadString('SteamPath');
   312           ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
   313           SteamPath := ePath;
   314 
   315           ePath := ePath + 'SteamApps\';
   316           if DirectoryExists(ePath) then begin
   317             trvMods.Items.Clear;
   318             // Check Mods
   319             eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
   320             for i := 0 to eStr.Count -1 do begin
   321               CurNode := trvMods.Items.Add(nil, eStr[i]);
   322 
   323               if DirectoryExists(ePath + eStr[i] + '\counter-strike source') then
   324                 trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
   325               if DirectoryExists(ePath + eStr[i] + '\day of defeat source') then
   326                 trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
   327               if DirectoryExists(ePath + eStr[i] + '\half-life 2 deathmatch') then
   328                 trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
   329 
   330               if CurNode.Count = 0 then
   331                 CurNode.Free
   332               else
   333                 CurNode.Expand(False);
   334             end;
   335             // Misc
   336             jspSelectMod.Show;
   337             trvMods.Selected := nil;
   338             cmdNext.Enabled := False;
   339           end
   340           else
   341             MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   342         end
   343         else
   344           MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
   345       finally
   346         eRegistry.Free;
   347       end;
   348     end
   349     else if frbStandaloneServer.Checked then begin // Standalone Server
   350       eRegistry := TRegistry.Create;
   351       try
   352         eRegistry.RootKey := HKEY_CURRENT_USER;
   353         if eRegistry.OpenKey('Software\Valve\HLServer', False) then begin
   354           StandaloneServer := IncludeTrailingPathDelimiter(eRegistry.ReadString('InstallPath'));
   355           if DirectoryExists(StandaloneServer + 'cstrike') then
   356             trvMods.Items.Add(nil, 'Counter-Strike:Source');
   357           if DirectoryExists(StandaloneServer + 'dod') then
   358             trvMods.Items.Add(nil, 'Day of Defeat:Source');
   359           if DirectoryExists(StandaloneServer + 'hl2mp') then
   360             trvMods.Items.Add(nil, 'Half-Life 2 Deatmatch');
   361           jspSelectMod.Show;
   362           cmdNext.Enabled := False;
   363         end
   364         else
   365           MessageBox(Handle, 'You haven''t installed Half-Life Dedicated Server yet!',  'Error', MB_ICONWARNING);
   366       finally
   367         eRegistry.Free;
   368       end;
   369     end
   370     else if frbSelectMod.Checked then begin 
   371       { Custom mod }
   372       if frmSelectModPath.ShowModal = mrOk then begin
   373         jspInstallProgress.Show;
   374         InstallCustom(IncludeTrailingPathDelimiter(frmSelectModPath.trvDirectory.SelectedFolder.PathName), osWindows);
   375       end;
   376     end
   377     else if frbFTP.Checked then // FTP
   378       jspFTP.Show;
   379   end;
   380 end;
   381 
   382 procedure TfrmMain.CheckNext(Sender: TObject);
   383 begin
   384   cmdNext.Enabled := frbAgree.Checked;
   385 end;
   386 
   387 procedure TfrmMain.cmdBackClick(Sender: TObject);
   388 begin
   389   if jplWizard.ActivePage = jspFTP then
   390     jspInstallMethod.Show
   391   else begin
   392     jplWizard.PrevPage;
   393     cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
   394   end;
   395 end;
   396 
   397 procedure TfrmMain.cmdConnectClick(Sender: TObject);
   398 var i: integer;
   399     eStr: TStringList;
   400     CurNode: TTreeNode;
   401 begin
   402   if (Trim(txtHost.Text) = '') or (Trim(txtUsername.Text) = '') then
   403     MessageBox(Handle, 'Please fill in each field!', PChar(Application.Title), MB_ICONWARNING)
   404   else if cmdConnect.Caption = 'Connect' then begin
   405     // ... design stuff ...
   406     Screen.Cursor := crHourGlass;
   407     cmdConnect.Enabled := False;
   408     cmdProxySettings.Enabled := False;
   409     txtHost.Enabled := False;
   410     txtPort.Enabled := False;
   411     txtUsername.Enabled := False;
   412     txtPassword.Enabled := False;
   413     chkPassive.Enabled := False;
   414     cmdConnect.Caption := 'Connecting...';
   415     // ... set values ...
   416     IdFTP.Host := txtHost.Text;
   417     IdFTP.Port := StrToInt(txtPort.Text);
   418     IdFTP.Username := txtUsername.Text;
   419     IdFTP.Passive := chkPassive.Checked;
   420     IdFTP.Password := txtPassword.Text;
   421     // ... connect and check values etc ...
   422     try
   423       IdFTP.Connect(True, 15000);
   424       // ... scan for initial directory ...
   425       eStr := TStringList.Create;
   426       eStr.Text := StringReplace(IdFTP.RetrieveCurrentDir, '/', #13, [rfReplaceAll]);
   427       for i := eStr.Count -1 downto 0 do begin
   428         if eStr[i] = '' then
   429           eStr.Delete(i);
   430       end;
   431       // ... connect successful, change captions ...
   432       trvDirectories.Enabled := True;
   433       cmdConnect.Enabled := True;
   434       cmdConnect.Caption := 'Disconnect';
   435 
   436       CurNode := nil;
   437       if eStr.Count <> 0 then begin
   438         for i := 0 to eStr.Count -1 do
   439           CurNode := trvDirectories.Items.AddChild(CurNode, eStr[i]);
   440       end;
   441       if trvDirectories.Items.Count <> 0 then
   442         trvDirectories.Items.Item[0].Expand(True);
   443       eStr.Free;
   444 
   445       // ... scan for directories ...
   446       with GetAllDirs do begin
   447         for i := 0 to Count -1 do
   448           trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(CurNode, Strings[i]), 'Scanning...');
   449         Free;
   450       end;
   451 
   452       if Assigned(CurNode) then
   453         CurNode.Expand(False);
   454     except
   455       on E: Exception do begin
   456         // reset button properties
   457         cmdConnect.Enabled := True;
   458         txtHost.Enabled := True;
   459         txtPort.Enabled := True;
   460         txtUsername.Enabled := True;
   461         txtPassword.Enabled := True;
   462         chkPassive.Enabled := True;
   463         cmdProxySettings.Enabled := True;
   464         cmdNext.Enabled := False;
   465         cmdConnect.Caption := 'Connect';
   466         // analyze messages
   467         if Pos('Login incorrect.', E.Message) <> 0 then begin // login failed
   468           MessageBox(Handle, 'Login incorrect. Check your FTP settings and try again.', PChar(Application.Title), MB_ICONWARNING);
   469           txtUsername.SetFocus;
   470           txtUsername.SelectAll;
   471         end
   472         else if Pos('Host not found.', E.Message) <> 0 then begin // host not found
   473           MessageBox(Handle, 'The entered host couldn''t be found. Check your settings and try again.', PChar(Application.Title), MB_ICONWARNING);
   474           txtHost.SetFocus;
   475           txtHost.SelectAll;
   476         end
   477         else if Pos('Connection refused.', E.Message) <> 0 then begin // wrong port (?)
   478           MessageBox(Handle, 'The host refused the connection. Check your port and try again.', PChar(Application.Title), MB_ICONWARNING);
   479           txtPort.SetFocus;
   480           txtPort.SelectAll;
   481         end
   482         else if E is EIdProtocolReplyError then begin // wrong port
   483           MessageBox(Handle, 'The port you entered is definitely wrong. Check it and try again.', PChar(Application.Title), MB_ICONWARNING);
   484           txtPort.SetFocus;
   485           txtPort.SelectAll;
   486         end
   487         else
   488           MessageBox(Handle, PChar(E.Message), PChar(Application.Title), MB_ICONWARNING); // unknown error
   489         // ... connect failed, leave procedure ...
   490         Screen.Cursor := crDefault;
   491         exit;
   492       end;
   493     end;
   494 
   495     Screen.Cursor := crDefault;
   496   end
   497   else begin
   498     Screen.Cursor := crHourGlass;
   499     IdFTP.Quit;
   500     trvDirectories.Items.Clear;
   501     trvDirectories.Enabled := False;
   502     cmdConnect.Enabled := True;
   503     cmdProxySettings.Enabled := True;
   504     txtHost.Enabled := True;
   505     txtPort.Enabled := True;
   506     txtUsername.Enabled := True;
   507     txtPassword.Enabled := True;
   508     chkPassive.Enabled := True;
   509     cmdConnect.Caption := 'Connect';
   510     cmdNext.Enabled := False;
   511     Screen.Cursor := crDefault;
   512   end;
   513 end;
   514 
   515 procedure TfrmMain.jplWizardChange(Sender: TObject);
   516 begin
   517   if (jplWizard.ActivePage = jspInstallProgress) then begin
   518     cmdNext.Caption := '&Finish';
   519     cmdNext.Enabled := False;
   520     cmdBack.Visible := False;
   521   end
   522   else begin
   523     cmdNext.Caption := '&Next >';
   524     cmdNext.Enabled := True;
   525     cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
   526   end;
   527 
   528   if (jplWizard.ActivePage = jspLicense) then
   529     cmdNext.Enabled := frbAgree.Checked;
   530 
   531   if (jplWizard.ActivePage = jspFTP) then
   532     cmdNext.Enabled := False;
   533 end;
   534 
   535 procedure TfrmMain.FormCreate(Sender: TObject);
   536 begin
   537   if LowerCase(ParamStr(1)) = '-logftp' then begin
   538     MessageBox(Handle, 'FTP installation will be logged to FTP.log!', PChar(Application.Title), MB_ICONINFORMATION);
   539     IdLogFile.Filename := ExtractFilePath(ParamStr(0)) + 'FTP.log';
   540     IdLogFile.Active := True;
   541   end;
   542 
   543   rtfDetails.Clear;
   544 end;
   545 
   546 procedure TfrmMain.cmdProxySettingsClick(Sender: TObject);
   547 begin
   548   frmProxy.ShowModal;
   549   // Apply Proxy Settings
   550   case frmProxy.cboProxy.ItemIndex of
   551     0: IdFTP.ProxySettings.ProxyType := fpcmNone; // none
   552     1: IdFTP.ProxySettings.ProxyType := fpcmHttpProxyWithFtp; // HTTP Proxy with FTP
   553     2: IdFTP.ProxySettings.ProxyType := fpcmOpen; // Open
   554     3: IdFTP.ProxySettings.ProxyType := fpcmSite; // Site
   555     4: IdFTP.ProxySettings.ProxyType := fpcmTransparent; // Transparent
   556     5: IdFTP.ProxySettings.ProxyType := fpcmUserPass; // User (Password)
   557     6: IdFTP.ProxySettings.ProxyType := fpcmUserSite; // User (Site)
   558   end;
   559 
   560   IdFTP.ProxySettings.Host := frmProxy.txtHost.Text;
   561   IdFTP.ProxySettings.UserName := frmProxy.txtPort.Text;
   562   IdFTP.ProxySettings.Password := frmProxy.txtPassword.Text;
   563   IdFTP.ProxySettings.Port := StrToInt(frmProxy.txtPort.Text);
   564 end;
   565 
   566 procedure TfrmMain.txtPortChange(Sender: TObject);
   567 var i: integer;
   568 begin
   569   if txtPort.Text = '' then
   570     txtPort.Text := '21'
   571   else begin
   572     // check if value is numeric...
   573     for i := Length(txtPort.Text) downto 1 do begin
   574       if Pos(txtPort.Text[i], '0123456789') = 0 then begin
   575         txtPort.Text := '21';
   576         txtPort.SelStart := 4;
   577         exit;
   578       end;
   579     end;
   580   end;
   581 end;
   582 
   583 procedure TfrmMain.trvDirectoriesExpanded(Sender: TObject;
   584   Node: TTreeNode);
   585 var ePath: String;
   586     CurNode: TTreeNode;
   587     i: integer;
   588 begin
   589   if Node.Item[0].Text = 'Scanning...' then begin // no directories added yet
   590     Screen.Cursor := crHourGlass;
   591     // get complete path
   592     ePath := '/';
   593     CurNode := Node;
   594     repeat
   595       ePath := '/' + CurNode.Text + ePath;
   596       CurNode := CurNode.Parent;
   597     until (not Assigned(CurNode));
   598     // change dir and add directories in it
   599     try
   600       Repaint;
   601       IdFTP.ChangeDir(ePath);
   602       with GetAllDirs do begin
   603         Node.Item[0].Free;
   604         for i := 0 to Count -1 do begin
   605           trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(Node, Strings[i]), 'Scanning...');
   606         end;
   607         Free;
   608       end;
   609     finally
   610       Application.ProcessMessages;
   611     end;
   612     Screen.Cursor := crDefault;
   613   end;
   614 end;
   615 
   616 procedure TfrmMain.trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
   617 begin
   618   cmdNext.Enabled := Assigned(trvDirectories.Selected);
   619 end;
   620 
   621 procedure TfrmMain.IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
   622   const AWorkCount: Integer);
   623 begin
   624   if AWorkCount > 15 then begin
   625     ggeItem.Progress := AWorkCount;
   626     CurrProgress := AWorkCount;
   627   end;
   628 
   629   if Cancel then
   630     IdFTP.Abort;
   631     
   632   Application.ProcessMessages;
   633 end;
   634 
   635 procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
   636 begin
   637   if (jplWizard.ActivePage = jspFTP) and (IdFTP.Connected) then
   638     IdFTP.Quit;
   639   if (jplWizard.ActivePage = jspInstallProgress) and (ggeAll.Progress <> ggeAll.MaxValue) and (not Cancel) then begin
   640     if MessageBox(Handle, 'Do you really want to cancel the installation?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNO) = mrYes then begin
   641       Screen.Cursor := crDefault;
   642       Application.OnException := ExceptionHandler;
   643       Cancel := True;
   644       if IdFTP.Connected then
   645         IdFTP.Quit;
   646     end
   647     else
   648       Action := caNone;
   649   end;
   650 end;
   651 
   652 procedure TfrmMain.ExceptionHandler(Sender: TObject; E: Exception);
   653 begin
   654   // IF any exceptions were raised after close, nobody would want them so leave this empty
   655 end;
   656 
   657 procedure TfrmMain.tmrSpeedTimer(Sender: TObject);
   658 begin
   659   Caption := CalcSpeed(OldProgress, CurrProgress);
   660   OldProgress := CurrProgress;
   661 end;
   662 
   663 procedure TfrmMain.trvDirectoriesExpanding(Sender: TObject;
   664   Node: TTreeNode; var AllowExpansion: Boolean);
   665 begin
   666   Node.ImageIndex := 1;
   667   Node.SelectedIndex := 1;
   668 end;
   669 
   670 procedure TfrmMain.trvDirectoriesCollapsing(Sender: TObject;
   671   Node: TTreeNode; var AllowCollapse: Boolean);
   672 begin
   673   Node.ImageIndex := 0;
   674   Node.SelectedIndex := 0;
   675 end;
   676 
   677 procedure TfrmMain.trvModsClick(Sender: TObject);
   678 begin
   679   if Assigned(trvMods.Selected) then
   680     cmdNext.Enabled := Assigned(trvMods.Selected.Parent)
   681   else
   682     cmdNext.Enabled := False;
   683 end;
   684 
   685 end.