1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/cruft/installer/UnitfrmMain.pas Fri Nov 14 04:14:35 2008 -0600
1.3 @@ -0,0 +1,804 @@
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 + Source: Boolean;
1.166 +begin
1.167 + { FTP }
1.168 + if jplWizard.ActivePage = jspFTP then begin
1.169 + if not IdFTP.Connected then
1.170 + IdFTP.Connect;
1.171 + eStr := TStringList.Create;
1.172 + ePath := '/';
1.173 + CurNode := trvDirectories.Selected;
1.174 + if (Assigned(CurNode)) then begin
1.175 + repeat
1.176 + ePath := '/' + CurNode.Text + ePath;
1.177 + CurNode := CurNode.Parent;
1.178 + until (not Assigned(CurNode));
1.179 + end;
1.180 + IdFTP.ChangeDir(ePath);
1.181 + IdFTP.List(eStr, '', False);
1.182 + eStr.CaseSensitive := False;
1.183 + // check if gameinfo.txt is in the directory -> valid installation
1.184 + if (eStr.IndexOf('gameinfo.txt') = -1) then begin
1.185 + MessageBox(Handle, 'Invalid directory. Please select your mod directory and try again.', PChar(Application.Title), MB_ICONWARNING);
1.186 + eStr.Free;
1.187 + exit;
1.188 + end
1.189 + else
1.190 + eStr.Free;
1.191 + // check for orangebox directory
1.192 + Source := True;
1.193 + if (AnsiSameText(ExtractFileName(trvDirectories.Selected.Text), 'tf')) then begin
1.194 + case MessageBox(Handle, 'It looks like your server is using the OrangeBox engine. Would you like to install the appropriate binaries for it?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNOCANCEL) of
1.195 + mrYes: Source := False;
1.196 + mrNo: Source := True;
1.197 + mrCancel: begin
1.198 + eStr.Free;
1.199 + exit;
1.200 + end;
1.201 + end;
1.202 + end;
1.203 + // design stuff
1.204 + trvDirectories.Enabled := False;
1.205 + cmdConnect.Enabled := False;
1.206 + optWindows.Enabled := False;
1.207 + optLinux.Enabled := False;
1.208 + Screen.Cursor := crHourGlass;
1.209 +
1.210 + if optWindows.Checked then
1.211 + eOS := osWindows
1.212 + else
1.213 + eOS := osLinux;
1.214 +
1.215 + jspInstallProgress.Show;
1.216 + // installation
1.217 + Screen.Cursor := crAppStart;
1.218 + InstallFTP(eOS, Source);
1.219 + end
1.220 + else if jplWizard.ActivePage = jspInstallProgress then
1.221 + Close
1.222 + else if jplWizard.ActivePage = jspSelectMod then begin
1.223 + { Dedicated Server }
1.224 + if frbDedicatedServer.Checked then begin
1.225 + Source := True;
1.226 + ePath := trvMods.Selected.Text;
1.227 + if ePath = 'Counter-Strike:Source' then
1.228 + ePath := trvMods.Selected.Parent.Text + '\source dedicated server\cstrike'
1.229 + else if ePath = 'Day of Defeat:Source' then
1.230 + ePath := trvMods.Selected.Parent.Text + '\source dedicated server\dod'
1.231 + else if ePath = 'Half-Life 2 Deathmatch' then
1.232 + ePath := trvMods.Selected.Parent.Text + '\source dedicated server\hl2mp'
1.233 + else begin
1.234 + { get games }
1.235 + if ePath = 'Team Fortress 2' then
1.236 + ePath := trvMods.Selected.Parent.Text + '\source 2007 dedicated server\tf';
1.237 + { ask user, just in case }
1.238 + case MessageBox(Handle, 'It looks like your server is using the OrangeBox engine. Would you like to install the appropriate binaries for it?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNOCANCEL) of
1.239 + mrYes: Source := False;
1.240 + mrNo: Source := True;
1.241 + mrCancel: exit;
1.242 + end;
1.243 + end;
1.244 + SteamPath := IncludeTrailingPathDelimiter(SteamPath) + 'steamapps\';
1.245 + // install it
1.246 + if DirectoryExists(SteamPath + ePath) then begin
1.247 + jspInstallProgress.Show;
1.248 + InstallDedicated(IncludeTrailingPathDelimiter(SteamPath + ePath), True, Source);
1.249 + end
1.250 + else begin
1.251 + 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.252 + jspSelectMod.Show;
1.253 + exit;
1.254 + end;
1.255 + end;
1.256 + { Standalone Server }
1.257 + if frbStandaloneServer.Checked then begin
1.258 + Source := True;
1.259 + ePath := trvMods.Selected.Text;
1.260 + if ePath = 'Counter-Strike:Source' then
1.261 + ePath := 'cstrike'
1.262 + else if ePath = 'Day of Defeat:Source' then
1.263 + ePath := 'dod'
1.264 + else if ePath = 'Half-Life 2 Deathmatch' then
1.265 + ePath := 'hl2mp'
1.266 + else begin
1.267 + { get games }
1.268 + if ePath = 'Team Fortress 2' then
1.269 + ePath := 'orangebox\tf';
1.270 + { ask user, just in case }
1.271 + case MessageBox(Handle, 'It looks like your server is using the OrangeBox engine. Would you like to install the appropriate binaries for it?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNOCANCEL) of
1.272 + mrYes: Source := False;
1.273 + mrNo: Source := True;
1.274 + mrCancel: exit;
1.275 + end;
1.276 + end;
1.277 + // install it
1.278 + if DirectoryExists(StandaloneServer + ePath) then begin
1.279 + jspInstallProgress.Show;
1.280 + InstallDedicated(IncludeTrailingPathDelimiter(StandaloneServer + ePath), False, Source)
1.281 + end
1.282 + else begin
1.283 + 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.284 + jspSelectMod.Show;
1.285 + exit;
1.286 + end;
1.287 + end;
1.288 + { Listen Server }
1.289 + if frbListenServer.Checked then begin
1.290 + Source := True;
1.291 + ePath := trvMods.Selected.Text;
1.292 + if ePath = 'Counter-Strike:Source' then
1.293 + ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\counter-strike source\cstrike'
1.294 + else if ePath = 'Half-Life 2 Deathmatch' then
1.295 + ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\half-life 2 deathmatch\hl2mp'
1.296 + else if ePath = 'Day of Defeat:Source' then
1.297 + ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\day of defeat source\dod'
1.298 + else begin
1.299 + { get games }
1.300 + if ePath = 'Team Fortress 2' then
1.301 + ePath := SteamPath + 'SteamApps\' + trvMods.Selected.Parent.Text + '\team fortress 2\tf';
1.302 + { ask user, just in case }
1.303 + case MessageBox(Handle, 'It looks like your server is using the OrangeBox engine. Would you like to install the appropriate binaries for it?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNOCANCEL) of
1.304 + mrYes: Source := False;
1.305 + mrNo: Source := True;
1.306 + mrCancel: exit;
1.307 + end;
1.308 + end;
1.309 +
1.310 + if Pos(SteamPath, ePath) = 0 then
1.311 + 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.312 + else begin
1.313 + if not FileExists(ePath + '\gameinfo.txt') then begin
1.314 + MessageBox(Handle, 'You have to play this game once before installing Metamod:Source. Do that and try again.', PChar(Application.Title), MB_ICONWARNING);
1.315 + exit;
1.316 + end;
1.317 +
1.318 + jspInstallProgress.Show;
1.319 + InstallListen(IncludeTrailingPathDelimiter(ePath), Source);
1.320 + end;
1.321 + end;
1.322 + { Custom mod below }
1.323 + end
1.324 + else if jplWizard.ActivePage <> jspInstallMethod then
1.325 + jplWizard.NextPage
1.326 + else begin
1.327 + if frbDedicatedServer.Checked then begin // Dedicated Server
1.328 + eRegistry := TRegistry.Create(KEY_READ);
1.329 + try
1.330 + eRegistry.RootKey := HKEY_CURRENT_USER;
1.331 + if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
1.332 + ePath := eRegistry.ReadString('SteamPath');
1.333 + ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
1.334 + SteamPath := ePath;
1.335 +
1.336 + ePath := ePath + 'SteamApps\';
1.337 + if DirectoryExists(ePath) then begin
1.338 + trvMods.Items.Clear;
1.339 + // Check Mods
1.340 + eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
1.341 + for i := 0 to eStr.Count -1 do begin
1.342 + CurNode := trvMods.Items.Add(nil, eStr[i]);
1.343 +
1.344 + if DirectoryExists(ePath + eStr[i] + '\source dedicated server\cstrike') then
1.345 + trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
1.346 + if DirectoryExists(ePath + eStr[i] + '\source dedicated server\dod') then
1.347 + trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
1.348 + if DirectoryExists(ePath + eStr[i] + '\source dedicated server\hl2mp') then
1.349 + trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
1.350 + if DirectoryExists(ePath + eStr[i] + '\source 2007 dedicated server\tf') then
1.351 + trvMods.Items.AddChild(CurNode, 'Team Fortress 2');
1.352 +
1.353 + if CurNode.Count = 0 then
1.354 + CurNode.Free
1.355 + else
1.356 + CurNode.Expand(False);
1.357 + end;
1.358 + // Misc
1.359 + jspSelectMod.Show;
1.360 + trvMods.Selected := nil;
1.361 + cmdNext.Enabled := False;
1.362 + end
1.363 + else
1.364 + MessageBox(Handle, 'You have to run Dedicated Server once before installing Metamod:Source!', 'Error', MB_ICONWARNING);
1.365 + end
1.366 + else
1.367 + MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
1.368 + finally
1.369 + eRegistry.Free;
1.370 + end;
1.371 + end
1.372 + else if frbListenServer.Checked then begin // Listen Server
1.373 + eRegistry := TRegistry.Create(KEY_READ);
1.374 + try
1.375 + eRegistry.RootKey := HKEY_CURRENT_USER;
1.376 + if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
1.377 + ePath := eRegistry.ReadString('SteamPath');
1.378 + ePath := IncludeTrailingPathDelimiter(StringReplace(ePath, '/', '\', [rfReplaceAll]));
1.379 + SteamPath := ePath;
1.380 +
1.381 + ePath := ePath + 'SteamApps\';
1.382 + if DirectoryExists(ePath) then begin
1.383 + trvMods.Items.Clear;
1.384 + // Check Mods
1.385 + eStr := GetAllFiles(ePath + '*.*', faDirectory, False, True, False);
1.386 + for i := 0 to eStr.Count -1 do begin
1.387 + CurNode := trvMods.Items.Add(nil, eStr[i]);
1.388 +
1.389 + if DirectoryExists(ePath + eStr[i] + '\counter-strike source') then
1.390 + trvMods.Items.AddChild(CurNode, 'Counter-Strike:Source');
1.391 + if DirectoryExists(ePath + eStr[i] + '\day of defeat source') then
1.392 + trvMods.Items.AddChild(CurNode, 'Day of Defeat:Source');
1.393 + if DirectoryExists(ePath + eStr[i] + '\half-life 2 deathmatch') then
1.394 + trvMods.Items.AddChild(CurNode, 'Half-Life 2 Deatmatch');
1.395 + if DirectoryExists(ePath + eStr[i] + '\team fortress 2') then
1.396 + trvMods.Items.AddChild(CurNode, 'Team Fortress 2');
1.397 +
1.398 + if CurNode.Count = 0 then
1.399 + CurNode.Free
1.400 + else
1.401 + CurNode.Expand(False);
1.402 + end;
1.403 + // Misc
1.404 + jspSelectMod.Show;
1.405 + trvMods.Selected := nil;
1.406 + cmdNext.Enabled := False;
1.407 + end
1.408 + else
1.409 + MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
1.410 + end
1.411 + else
1.412 + MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
1.413 + finally
1.414 + eRegistry.Free;
1.415 + end;
1.416 + end
1.417 + else if frbStandaloneServer.Checked then begin // Standalone Server
1.418 + eRegistry := TRegistry.Create;
1.419 + try
1.420 + eRegistry.RootKey := HKEY_CURRENT_USER;
1.421 + if eRegistry.OpenKey('Software\Valve\HLServer', False) then begin
1.422 + StandaloneServer := IncludeTrailingPathDelimiter(eRegistry.ReadString('InstallPath'));
1.423 + if DirectoryExists(StandaloneServer + 'cstrike') then
1.424 + trvMods.Items.Add(nil, 'Counter-Strike:Source');
1.425 + if DirectoryExists(StandaloneServer + 'dod') then
1.426 + trvMods.Items.Add(nil, 'Day of Defeat:Source');
1.427 + if DirectoryExists(StandaloneServer + 'hl2mp') then
1.428 + trvMods.Items.Add(nil, 'Half-Life 2 Deatmatch');
1.429 + if DirectoryExists(StandaloneServer + 'orangebox\tf') then
1.430 + trvMods.Items.Add(nil, 'Team Fortress 2');
1.431 + jspSelectMod.Show;
1.432 + cmdNext.Enabled := False;
1.433 + end
1.434 + else
1.435 + MessageBox(Handle, 'You haven''t installed Half-Life Dedicated Server yet!', 'Error', MB_ICONWARNING);
1.436 + finally
1.437 + eRegistry.Free;
1.438 + end;
1.439 + end
1.440 + else if frbSelectMod.Checked then begin
1.441 + { Custom mod }
1.442 + if frmSelectModPath.ShowModal = mrOk then begin
1.443 + ePath := frmSelectModPath.trvDirectory.SelectedFolder.PathName;
1.444 + { check if this is an orangebox game }
1.445 + Source := True;
1.446 + if (AnsiSameText(ExtractFileName(ePath), 'tf')) then begin
1.447 + case MessageBox(Handle, 'It looks like your server is using the OrangeBox engine. Would you like to install the appropriate binaries for it?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNOCANCEL) of
1.448 + mrYes: Source := False;
1.449 + mrNo: Source := True;
1.450 + mrCancel: exit;
1.451 + end;
1.452 + end;
1.453 + { install now }
1.454 + jspInstallProgress.Show;
1.455 + InstallCustom(IncludeTrailingPathDelimiter(ePath), osWindows, Source);
1.456 + end;
1.457 + end
1.458 + else if frbFTP.Checked then // FTP
1.459 + jspFTP.Show;
1.460 + end;
1.461 +end;
1.462 +
1.463 +procedure TfrmMain.CheckNext(Sender: TObject);
1.464 +begin
1.465 + cmdNext.Enabled := frbAgree.Checked;
1.466 +end;
1.467 +
1.468 +procedure TfrmMain.cmdBackClick(Sender: TObject);
1.469 +begin
1.470 + if jplWizard.ActivePage = jspFTP then
1.471 + jspInstallMethod.Show
1.472 + else begin
1.473 + jplWizard.PrevPage;
1.474 + cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
1.475 + end;
1.476 +end;
1.477 +
1.478 +procedure TfrmMain.cmdConnectClick(Sender: TObject);
1.479 +var i: integer;
1.480 + eStr: TStringList;
1.481 + CurNode: TTreeNode;
1.482 + Path: String;
1.483 +begin
1.484 + if (Trim(txtHost.Text) = '') or (Trim(txtUsername.Text) = '') then
1.485 + MessageBox(Handle, 'Please fill in each field!', PChar(Application.Title), MB_ICONWARNING)
1.486 + else if cmdConnect.Caption = 'Connect' then begin
1.487 + // ... design stuff ...
1.488 + Screen.Cursor := crHourGlass;
1.489 + cmdConnect.Enabled := False;
1.490 + cmdProxySettings.Enabled := False;
1.491 + txtHost.Enabled := False;
1.492 + txtPort.Enabled := False;
1.493 + txtUsername.Enabled := False;
1.494 + txtPassword.Enabled := False;
1.495 + chkPassive.Enabled := False;
1.496 + cmdConnect.Caption := 'Connecting...';
1.497 + // ... set values ...
1.498 + IdFTP.Host := txtHost.Text;
1.499 + IdFTP.Port := StrToInt(txtPort.Text);
1.500 + IdFTP.Username := txtUsername.Text;
1.501 + IdFTP.Passive := chkPassive.Checked;
1.502 + IdFTP.Password := txtPassword.Text;
1.503 + // ... connect and check values etc ...
1.504 + try
1.505 + IdFTP.Connect(True, 15000);
1.506 + // ... get initial directory ...
1.507 + Path := IdFTP.RetrieveCurrentDir;
1.508 + // ... "fix" path ...
1.509 + eStr := TStringList.Create;
1.510 + eStr.Text := StringReplace(Path, '/', #13, [rfReplaceAll]);
1.511 + for i := eStr.Count -1 downto 0 do begin
1.512 + if eStr[i] = '' then
1.513 + eStr.Delete(i);
1.514 + end;
1.515 + if (Copy(Path, Length(Path) -1, 1) <> '/') then
1.516 + Path := Path + '/';
1.517 + // ... connect successful, change captions ...
1.518 + trvDirectories.Enabled := True;
1.519 + cmdConnect.Enabled := True;
1.520 + cmdConnect.Caption := 'Disconnect';
1.521 + // ... change to / and create all the directories ...
1.522 + CurNode := nil;
1.523 + if (Path <> '/') then begin
1.524 + try
1.525 + IdFTP.ChangeDir('/');
1.526 + with GetAllDirs do begin
1.527 + for i := 0 to Count -1 do begin
1.528 + if (Assigned(CurNode)) then
1.529 + trvDirectories.Items.AddChild(trvDirectories.Items.Add(nil, Strings[i]), 'Scanning...')
1.530 + else begin
1.531 + CurNode := trvDirectories.Items.Add(nil, Strings[i]);
1.532 + trvDirectories.Items.AddChild(CurNode, 'Scanning...');
1.533 + if (Pos('/' + CurNode.Text + '/', Path) = 0) then
1.534 + CurNode := nil;
1.535 + end
1.536 + end;
1.537 + Free;
1.538 + end;
1.539 + IdFTP.ChangeDir(Path);
1.540 + except
1.541 + if (IdFTP.Connected) then
1.542 + IdFTP.ChangeDir(Path)
1.543 + else
1.544 + IdFTP.Connect;
1.545 + end;
1.546 + end;
1.547 + // ... find directories in start path ...
1.548 + if eStr.Count <> 0 then begin
1.549 + for i := 0 to eStr.Count -1 do begin
1.550 + if (not ((i = 0) and (Assigned(CurNode)))) then
1.551 + CurNode := trvDirectories.Items.AddChild(CurNode, eStr[i]);
1.552 + end;
1.553 + end;
1.554 + trvDirectories.Selected := CurNode;
1.555 + eStr.Free;
1.556 + // ... scan for directories ...
1.557 + with GetAllDirs do begin
1.558 + for i := 0 to Count -1 do
1.559 + trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(CurNode, Strings[i]), 'Scanning...');
1.560 + Free;
1.561 + end;
1.562 +
1.563 + if Assigned(CurNode) then
1.564 + CurNode.Expand(False);
1.565 + except
1.566 + on E: Exception do begin
1.567 + // reset button properties
1.568 + cmdConnect.Enabled := True;
1.569 + txtHost.Enabled := True;
1.570 + txtPort.Enabled := True;
1.571 + txtUsername.Enabled := True;
1.572 + txtPassword.Enabled := True;
1.573 + chkPassive.Enabled := True;
1.574 + cmdProxySettings.Enabled := True;
1.575 + cmdNext.Enabled := False;
1.576 + cmdConnect.Caption := 'Connect';
1.577 + // analyze messages
1.578 + if Pos('Login incorrect.', E.Message) <> 0 then begin // login failed
1.579 + MessageBox(Handle, 'Login incorrect. Check your FTP settings and try again.', PChar(Application.Title), MB_ICONWARNING);
1.580 + txtUsername.SetFocus;
1.581 + txtUsername.SelectAll;
1.582 + end
1.583 + else if Pos('Host not found.', E.Message) <> 0 then begin // host not found
1.584 + MessageBox(Handle, 'The entered host couldn''t be found. Check your settings and try again.', PChar(Application.Title), MB_ICONWARNING);
1.585 + txtHost.SetFocus;
1.586 + txtHost.SelectAll;
1.587 + end
1.588 + else if Pos('Connection refused.', E.Message) <> 0 then begin // wrong port (?)
1.589 + MessageBox(Handle, 'The host refused the connection. Check your port and try again.', PChar(Application.Title), MB_ICONWARNING);
1.590 + txtPort.SetFocus;
1.591 + txtPort.SelectAll;
1.592 + end
1.593 + else if E is EIdProtocolReplyError then begin // wrong port
1.594 + MessageBox(Handle, 'The port you entered is definitely wrong. Check it and try again.', PChar(Application.Title), MB_ICONWARNING);
1.595 + txtPort.SetFocus;
1.596 + txtPort.SelectAll;
1.597 + end
1.598 + else
1.599 + MessageBox(Handle, PChar(E.Message), PChar(Application.Title), MB_ICONWARNING); // unknown error
1.600 + // ... connect failed, leave procedure ...
1.601 + Screen.Cursor := crDefault;
1.602 + exit;
1.603 + end;
1.604 + end;
1.605 +
1.606 + Screen.Cursor := crDefault;
1.607 + end
1.608 + else begin
1.609 + Screen.Cursor := crHourGlass;
1.610 + IdFTP.Quit;
1.611 + trvDirectories.Items.Clear;
1.612 + trvDirectories.Enabled := False;
1.613 + cmdConnect.Enabled := True;
1.614 + cmdProxySettings.Enabled := True;
1.615 + txtHost.Enabled := True;
1.616 + txtPort.Enabled := True;
1.617 + txtUsername.Enabled := True;
1.618 + txtPassword.Enabled := True;
1.619 + chkPassive.Enabled := True;
1.620 + cmdConnect.Caption := 'Connect';
1.621 + cmdNext.Enabled := False;
1.622 + Screen.Cursor := crDefault;
1.623 + end;
1.624 +end;
1.625 +
1.626 +procedure TfrmMain.jplWizardChange(Sender: TObject);
1.627 +begin
1.628 + if (jplWizard.ActivePage = jspInstallProgress) then begin
1.629 + cmdNext.Caption := '&Finish';
1.630 + cmdNext.Enabled := False;
1.631 + cmdBack.Visible := False;
1.632 + end
1.633 + else begin
1.634 + cmdNext.Caption := '&Next >';
1.635 + cmdNext.Enabled := True;
1.636 + cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
1.637 + end;
1.638 +
1.639 + if (jplWizard.ActivePage = jspLicense) then
1.640 + cmdNext.Enabled := frbAgree.Checked;
1.641 +
1.642 + if (jplWizard.ActivePage = jspFTP) then
1.643 + cmdNext.Enabled := False;
1.644 +end;
1.645 +
1.646 +procedure TfrmMain.FormCreate(Sender: TObject);
1.647 +begin
1.648 + if LowerCase(ParamStr(1)) = '-logftp' then begin
1.649 + MessageBox(Handle, 'FTP installation will be logged to FTP.log!', PChar(Application.Title), MB_ICONINFORMATION);
1.650 + IdLogFile.Filename := ExtractFilePath(ParamStr(0)) + 'FTP.log';
1.651 + IdLogFile.Active := True;
1.652 + end;
1.653 +
1.654 + rtfDetails.Clear;
1.655 +end;
1.656 +
1.657 +procedure TfrmMain.cmdProxySettingsClick(Sender: TObject);
1.658 +begin
1.659 + frmProxy.ShowModal;
1.660 + // Apply Proxy Settings
1.661 + case frmProxy.cboProxy.ItemIndex of
1.662 + 0: IdFTP.ProxySettings.ProxyType := fpcmNone; // none
1.663 + 1: IdFTP.ProxySettings.ProxyType := fpcmHttpProxyWithFtp; // HTTP Proxy with FTP
1.664 + 2: IdFTP.ProxySettings.ProxyType := fpcmOpen; // Open
1.665 + 3: IdFTP.ProxySettings.ProxyType := fpcmSite; // Site
1.666 + 4: IdFTP.ProxySettings.ProxyType := fpcmTransparent; // Transparent
1.667 + 5: IdFTP.ProxySettings.ProxyType := fpcmUserPass; // User (Password)
1.668 + 6: IdFTP.ProxySettings.ProxyType := fpcmUserSite; // User (Site)
1.669 + end;
1.670 +
1.671 + IdFTP.ProxySettings.Host := frmProxy.txtHost.Text;
1.672 + IdFTP.ProxySettings.UserName := frmProxy.txtPort.Text;
1.673 + IdFTP.ProxySettings.Password := frmProxy.txtPassword.Text;
1.674 + IdFTP.ProxySettings.Port := StrToInt(frmProxy.txtPort.Text);
1.675 +end;
1.676 +
1.677 +procedure TfrmMain.txtPortChange(Sender: TObject);
1.678 +var i: integer;
1.679 +begin
1.680 + if txtPort.Text = '' then
1.681 + txtPort.Text := '21'
1.682 + else begin
1.683 + // check if value is numeric...
1.684 + for i := Length(txtPort.Text) downto 1 do begin
1.685 + if Pos(txtPort.Text[i], '0123456789') = 0 then begin
1.686 + txtPort.Text := '21';
1.687 + txtPort.SelStart := 4;
1.688 + exit;
1.689 + end;
1.690 + end;
1.691 + end;
1.692 +end;
1.693 +
1.694 +procedure TfrmMain.trvDirectoriesExpanded(Sender: TObject;
1.695 + Node: TTreeNode);
1.696 +var ePath: String;
1.697 + CurNode: TTreeNode;
1.698 + i: integer;
1.699 +begin
1.700 + if Node.Item[0].Text = 'Scanning...' then begin // no directories added yet
1.701 + Screen.Cursor := crHourGlass;
1.702 + // get complete path
1.703 + ePath := '/';
1.704 + CurNode := Node;
1.705 + repeat
1.706 + ePath := '/' + CurNode.Text + ePath;
1.707 + CurNode := CurNode.Parent;
1.708 + until (not Assigned(CurNode));
1.709 + // change dir and add directories in it
1.710 + try
1.711 + Repaint;
1.712 + IdFTP.ChangeDir(ePath);
1.713 + with GetAllDirs do begin
1.714 + Node.Item[0].Free;
1.715 + for i := 0 to Count -1 do begin
1.716 + trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(Node, Strings[i]), 'Scanning...');
1.717 + end;
1.718 + Free;
1.719 + end;
1.720 + finally
1.721 + Application.ProcessMessages;
1.722 + end;
1.723 + Screen.Cursor := crDefault;
1.724 + end;
1.725 +end;
1.726 +
1.727 +procedure TfrmMain.trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
1.728 +begin
1.729 + cmdNext.Enabled := Assigned(trvDirectories.Selected);
1.730 +end;
1.731 +
1.732 +procedure TfrmMain.IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
1.733 + const AWorkCount: Integer);
1.734 +begin
1.735 + if AWorkCount > 15 then begin
1.736 + ggeItem.Progress := AWorkCount;
1.737 + CurrProgress := AWorkCount;
1.738 + end;
1.739 +
1.740 + if Cancel then
1.741 + IdFTP.Abort;
1.742 +
1.743 + Application.ProcessMessages;
1.744 +end;
1.745 +
1.746 +procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
1.747 +begin
1.748 + if (jplWizard.ActivePage = jspFTP) and (IdFTP.Connected) then
1.749 + IdFTP.Quit;
1.750 + if (jplWizard.ActivePage = jspInstallProgress) and (ggeAll.Progress <> ggeAll.MaxValue) and (not Cancel) then begin
1.751 + if MessageBox(Handle, 'Do you really want to cancel the installation?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNO) = mrYes then begin
1.752 + Screen.Cursor := crDefault;
1.753 + Application.OnException := ExceptionHandler;
1.754 + Cancel := True;
1.755 + if IdFTP.Connected then
1.756 + IdFTP.Quit;
1.757 + end
1.758 + else
1.759 + Action := caNone;
1.760 + end;
1.761 +end;
1.762 +
1.763 +procedure TfrmMain.ExceptionHandler(Sender: TObject; E: Exception);
1.764 +begin
1.765 + // IF any exceptions were raised after close, nobody would want them so leave this empty
1.766 +end;
1.767 +
1.768 +procedure TfrmMain.tmrSpeedTimer(Sender: TObject);
1.769 +begin
1.770 + Caption := CalcSpeed(OldProgress, CurrProgress);
1.771 + OldProgress := CurrProgress;
1.772 +end;
1.773 +
1.774 +procedure TfrmMain.trvDirectoriesExpanding(Sender: TObject;
1.775 + Node: TTreeNode; var AllowExpansion: Boolean);
1.776 +begin
1.777 + Node.ImageIndex := 1;
1.778 + Node.SelectedIndex := 1;
1.779 +end;
1.780 +
1.781 +procedure TfrmMain.trvDirectoriesCollapsing(Sender: TObject;
1.782 + Node: TTreeNode; var AllowCollapse: Boolean);
1.783 +begin
1.784 + Node.ImageIndex := 0;
1.785 + Node.SelectedIndex := 0;
1.786 +end;
1.787 +
1.788 +procedure TfrmMain.trvModsClick(Sender: TObject);
1.789 +begin
1.790 + if Assigned(trvMods.Selected) then
1.791 + cmdNext.Enabled := Assigned(trvMods.Selected.Parent)
1.792 + else
1.793 + cmdNext.Enabled := False;
1.794 +end;
1.795 +
1.796 +procedure TfrmMain.trvDirectoriesMouseDown(Sender: TObject;
1.797 + Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1.798 +var Node: TTreeNode;
1.799 +begin
1.800 + Node := trvDirectories.GetNodeAt(X, Y);
1.801 + if (Assigned(Node)) then begin
1.802 + if (Node.DisplayRect(True).Right < X) then
1.803 + trvDirectories.Selected := nil;
1.804 + end;
1.805 +end;
1.806 +
1.807 +end.