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;
15 TfrmMain = class(TForm)
16 jplWizard: TJvPageList;
17 jspWelcome: TJvStandardPage;
21 cmdCancel: TFlatButton;
27 jspLicense: TJvStandardPage;
32 freLicense: TmxFlatRichEdit;
33 frbAgree: TFlatRadioButton;
34 ftbDontAgree: TFlatRadioButton;
35 jspInstallMethod: TJvStandardPage;
40 lblInstallMethod: TLabel;
41 pnlInstallMethod: TPanel;
42 frbDedicatedServer: TFlatRadioButton;
43 frbListenServer: TFlatRadioButton;
44 frbSelectMod: TFlatRadioButton;
45 frbFTP: TFlatRadioButton;
47 jspFTP: TJvStandardPage;
57 txtUserName: TFlatEdit;
58 txtPassword: TFlatEdit;
63 cmdConnect: TFlatButton;
65 trvDirectories: TTreeView;
67 jspInstallProgress: TJvStandardPage;
75 rtfDetails: TmxFlatRichEdit;
83 jspSelectMod: TJvStandardPage;
87 lblSelectModInfo: TLabel;
90 lstMods: TmxFlatListBox;
91 chkPassive: TFlatCheckBox;
94 optWindows: TFlatRadioButton;
95 optLinux: TFlatRadioButton;
97 cmdProxySettings: TFlatButton;
98 IdAntiFreeze: TIdAntiFreeze;
99 frbStandaloneServer: TFlatRadioButton;
101 IdLogFile: TIdLogFile;
102 procedure jvwStepsCancelButtonClick(Sender: TObject);
103 procedure cmdCancelClick(Sender: TObject);
104 procedure cmdNextClick(Sender: TObject);
105 procedure CheckNext(Sender: TObject);
106 procedure cmdBackClick(Sender: TObject);
107 procedure cmdConnectClick(Sender: TObject);
108 procedure jplWizardChange(Sender: TObject);
109 procedure FormCreate(Sender: TObject);
110 procedure lstModsClick(Sender: TObject);
111 procedure cmdProxySettingsClick(Sender: TObject);
112 procedure txtPortChange(Sender: TObject);
113 procedure trvDirectoriesExpanded(Sender: TObject; Node: TTreeNode);
114 procedure trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
115 procedure IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
116 const AWorkCount: Integer);
117 procedure FormClose(Sender: TObject; var Action: TCloseAction);
118 procedure tmrSpeedTimer(Sender: TObject);
119 procedure trvDirectoriesExpanding(Sender: TObject; Node: TTreeNode;
120 var AllowExpansion: Boolean);
121 procedure trvDirectoriesCollapsing(Sender: TObject; Node: TTreeNode;
122 var AllowCollapse: Boolean);
124 OldProgress: Integer;
125 CurrProgress: Integer;
127 procedure ExceptionHandler(Sender: TObject; E: Exception);
133 const VERSION = '1.2';
137 uses UnitFunctions, UnitfrmProxy, UnitInstall, UnitSelectModPath;
141 procedure TfrmMain.jvwStepsCancelButtonClick(Sender: TObject);
146 procedure TfrmMain.cmdCancelClick(Sender: TObject);
151 procedure TfrmMain.cmdNextClick(Sender: TObject);
153 eRegistry: TRegistry;
159 if jplWizard.ActivePage = jspFTP then begin
160 if not IdFTP.Connected then
162 eStr := TStringList.Create;
164 CurNode := trvDirectories.Selected;
166 ePath := '/' + CurNode.Text + ePath;
167 CurNode := CurNode.Parent;
168 until (not Assigned(CurNode));
169 IdFTP.ChangeDir(ePath);
170 IdFTP.List(eStr, '', False);
171 if eStr.IndexOf('gameinfo.txt') = -1 then begin
172 MessageBox(Handle, 'Invalid directory. Please select your mod directory and try again.', PChar(Application.Title), MB_ICONWARNING);
180 trvDirectories.Enabled := False;
181 cmdConnect.Enabled := False;
182 optWindows.Enabled := False;
183 optLinux.Enabled := False;
184 Screen.Cursor := crHourGlass;
186 if optWindows.Checked then
188 else if optLinux.Checked then
191 jspInstallProgress.Show;
193 Screen.Cursor := crAppStart;
196 else if jplWizard.ActivePage = jspInstallProgress then
198 else if jplWizard.ActivePage = jspSelectMod then begin
200 if (frbDedicatedServer.Checked) or (frbStandaloneServer.Checked) then begin
201 jspInstallProgress.Show;
202 ePath := lstMods.Items[lstMods.ItemIndex];
203 if ePath = 'Counter-Strike:Source' then
205 else if ePath = 'Day of Defeat:Source' then
210 if frbDedicatedServer.Checked then begin
211 if DirectoryExists(SteamPath + ePath) then
212 InstallDedicated(IncludeTrailingPathDelimiter(SteamPath + ePath), True)
214 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);
215 Application.Terminate;
220 if DirectoryExists(StandaloneServer + ePath) then
221 InstallDedicated(IncludeTrailingPathDelimiter(StandaloneServer + ePath), False)
223 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);
224 Application.Terminate;
230 if frbListenServer.Checked then begin
231 ePath := lstMods.Items[lstMods.ItemIndex];
232 if ePath = 'Counter-Strike:Source' then
233 ePath := SteamPath + 'counter-strike source\cstrike'
234 else if ePath = 'Half-Life 2 Deathmatch' then
235 ePath := SteamPath + 'half-life 2 deathmatch\hl2mp'
237 ePath := SteamPath + 'Day Of Defeat source\dod';
239 if Pos(SteamPath, ePath) = 0 then
240 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)
242 if not FileExists(ePath + '\gameinfo.txt') then begin
243 MessageBox(Handle, 'You have to play this game once before installing Metamod:Source. Do this and try again.', PChar(Application.Title), MB_ICONWARNING);
247 jspInstallProgress.Show;
248 ePath := IncludeTrailingPathDelimiter(ePath);
249 InstallListen(ePath);
254 else if jplWizard.ActivePage <> jspInstallMethod then
257 if frbDedicatedServer.Checked then begin // Dedicated Server
258 eRegistry := TRegistry.Create(KEY_READ);
260 eRegistry.RootKey := HKEY_CURRENT_USER;
261 if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
262 ePath := eRegistry.ReadString('ModInstallPath');
263 ePath := Copy(ePath, 1, Length(ePath) -10) + '\source dedicated server\';
264 if DirectoryExists(ePath) then begin
268 if DirectoryExists(SteamPath + 'cstrike') then
269 lstMods.Items.Add('Counter-Strike:Source');
270 if DirectoryExists(SteamPath + 'dod') then
271 lstMods.Items.Add('Day of Defeat:Source');
272 if DirectoryExists(SteamPath + 'hl2mp') then
273 lstMods.Items.Add('Half-Life 2 Deatmatch');
276 lstMods.ItemIndex := -1;
277 cmdNext.Enabled := False;
280 MessageBox(Handle, 'You have to run Dedicated Server once before installing Metamod:Source!', 'Error', MB_ICONWARNING);
283 MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
288 else if frbListenServer.Checked then begin // Listen Server
289 eRegistry := TRegistry.Create(KEY_READ);
291 eRegistry.RootKey := HKEY_CURRENT_USER;
292 if eRegistry.OpenKey('Software\Valve\Steam', False) then begin
293 ePath := eRegistry.ReadString('ModInstallPath') + '\';
295 ePath := Copy(ePath, 1, Length(ePath) -10);
296 if DirectoryExists(ePath) then begin
299 if DirectoryExists(SteamPath + 'counter-strike source') then
300 lstMods.Items.Add('Counter-Strike:Source');
301 if DirectoryExists(SteamPath + 'half-life 2 deathmatch') then
302 lstMods.Items.Add('Half-Life 2 Deathmatch');
303 if DirectoryExists(SteamPath + 'Day Of Defeat source') then
304 lstMods.Items.Add('Day of Defeat: Source');
307 lstMods.ItemIndex := -1;
308 cmdNext.Enabled := False;
311 MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
314 MessageBox(Handle, 'You haven''t installed Steam yet! Download it at www.steampowered.com, install Dedicated Server and try again.', 'Error', MB_ICONWARNING);
319 else if frbStandaloneServer.Checked then begin // Standalone Server
320 eRegistry := TRegistry.Create;
322 eRegistry.RootKey := HKEY_CURRENT_USER;
323 if eRegistry.OpenKey('Software\Valve\HLServer', False) then begin
324 StandaloneServer := IncludeTrailingPathDelimiter(eRegistry.ReadString('InstallPath'));
325 if DirectoryExists(StandaloneServer + 'cstrike') then
326 lstMods.Items.Add('Counter-Strike:Source');
327 if DirectoryExists(StandaloneServer + 'dod') then
328 lstMods.Items.Add('Day of Defeat:Source');
329 if DirectoryExists(StandaloneServer + 'hl2mp') then
330 lstMods.Items.Add('Half-Life 2 Deatmatch');
334 MessageBox(Handle, 'You haven''t installed Half-Life Dedicated Server yet!', 'Error', MB_ICONWARNING);
339 else if frbSelectMod.Checked then begin
341 if frmSelectModPath.ShowModal = mrOk then begin
342 jspInstallProgress.Show;
343 InstallCustom(IncludeTrailingPathDelimiter(frmSelectModPath.trvDirectory.SelectedFolder.PathName), osWindows);
346 else if frbFTP.Checked then // FTP
351 procedure TfrmMain.CheckNext(Sender: TObject);
353 cmdNext.Enabled := frbAgree.Checked;
356 procedure TfrmMain.cmdBackClick(Sender: TObject);
358 if jplWizard.ActivePage = jspFTP then
359 jspInstallMethod.Show
362 cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
366 procedure TfrmMain.cmdConnectClick(Sender: TObject);
371 if (Trim(txtHost.Text) = '') or (Trim(txtUsername.Text) = '') then
372 MessageBox(Handle, 'Please fill in each field!', PChar(Application.Title), MB_ICONWARNING)
373 else if cmdConnect.Caption = 'Connect' then begin
374 // ... design stuff ...
375 Screen.Cursor := crHourGlass;
376 cmdConnect.Enabled := False;
377 cmdProxySettings.Enabled := False;
378 txtHost.Enabled := False;
379 txtPort.Enabled := False;
380 txtUsername.Enabled := False;
381 txtPassword.Enabled := False;
382 chkPassive.Enabled := False;
383 cmdConnect.Caption := 'Connecting...';
384 // ... set values ...
385 IdFTP.Host := txtHost.Text;
386 IdFTP.Port := StrToInt(txtPort.Text);
387 IdFTP.Username := txtUsername.Text;
388 IdFTP.Passive := chkPassive.Checked;
389 IdFTP.Password := txtPassword.Text;
390 // ... connect and check values etc ...
392 IdFTP.Connect(True, 15000);
393 // ... scan for initial directory ...
394 eStr := TStringList.Create;
395 eStr.Text := StringReplace(IdFTP.RetrieveCurrentDir, '/', #13, [rfReplaceAll]);
396 for i := eStr.Count -1 downto 0 do begin
400 // ... connect successful, change captions ...
401 trvDirectories.Enabled := True;
402 cmdConnect.Enabled := True;
403 cmdConnect.Caption := 'Disconnect';
406 if eStr.Count <> 0 then begin
407 for i := 0 to eStr.Count -1 do
408 CurNode := trvDirectories.Items.AddChild(CurNode, eStr[i]);
410 if trvDirectories.Items.Count <> 0 then
411 trvDirectories.Items.Item[0].Expand(True);
414 // ... scan for directories ...
415 with GetAllDirs do begin
416 for i := 0 to Count -1 do
417 trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(CurNode, Strings[i]), 'Scanning...');
421 if Assigned(CurNode) then
422 CurNode.Expand(False);
424 on E: Exception do begin
425 // reset button properties
426 cmdConnect.Enabled := True;
427 txtHost.Enabled := True;
428 txtPort.Enabled := True;
429 txtUsername.Enabled := True;
430 txtPassword.Enabled := True;
431 chkPassive.Enabled := True;
432 cmdProxySettings.Enabled := True;
433 cmdNext.Enabled := False;
434 cmdConnect.Caption := 'Connect';
436 if Pos('Login incorrect.', E.Message) <> 0 then begin // login failed
437 MessageBox(Handle, 'Login incorrect. Check your FTP settings and try again.', PChar(Application.Title), MB_ICONWARNING);
438 txtUsername.SetFocus;
439 txtUsername.SelectAll;
441 else if Pos('Host not found.', E.Message) <> 0 then begin // host not found
442 MessageBox(Handle, 'The entered host couldn''t be found. Check your settings and try again.', PChar(Application.Title), MB_ICONWARNING);
446 else if Pos('Connection refused.', E.Message) <> 0 then begin // wrong port (?)
447 MessageBox(Handle, 'The host refused the connection. Check your port and try again.', PChar(Application.Title), MB_ICONWARNING);
451 else if E is EIdProtocolReplyError then begin // wrong port
452 MessageBox(Handle, 'The port you entered is definitely wrong. Check it and try again.', PChar(Application.Title), MB_ICONWARNING);
457 MessageBox(Handle, PChar(E.Message), PChar(Application.Title), MB_ICONWARNING); // unknown error
458 // ... connect failed, leave procedure ...
459 Screen.Cursor := crDefault;
464 Screen.Cursor := crDefault;
467 Screen.Cursor := crHourGlass;
469 trvDirectories.Items.Clear;
470 trvDirectories.Enabled := False;
471 cmdConnect.Enabled := True;
472 cmdProxySettings.Enabled := True;
473 txtHost.Enabled := True;
474 txtPort.Enabled := True;
475 txtUsername.Enabled := True;
476 txtPassword.Enabled := True;
477 chkPassive.Enabled := True;
478 cmdConnect.Caption := 'Connect';
479 cmdNext.Enabled := False;
480 Screen.Cursor := crDefault;
484 procedure TfrmMain.jplWizardChange(Sender: TObject);
486 if (jplWizard.ActivePage = jspInstallProgress) then begin
487 cmdNext.Caption := '&Finish';
488 cmdNext.Enabled := False;
489 cmdBack.Visible := False;
492 cmdNext.Caption := '&Next >';
493 cmdNext.Enabled := True;
494 cmdBack.Visible := jplWizard.ActivePageIndex <> 0;
497 if (jplWizard.ActivePage = jspLicense) then
498 cmdNext.Enabled := frbAgree.Checked;
500 if (jplWizard.ActivePage = jspFTP) then
501 cmdNext.Enabled := False;
504 procedure TfrmMain.FormCreate(Sender: TObject);
506 if LowerCase(ParamStr(1)) = '-logftp' then begin
507 MessageBox(Handle, 'FTP installation will be logged to FTP.log!', PChar(Application.Title), MB_ICONINFORMATION);
508 IdLogFile.Filename := ExtractFilePath(ParamStr(0)) + 'FTP.log';
509 IdLogFile.Active := True;
515 procedure TfrmMain.lstModsClick(Sender: TObject);
517 cmdNext.Enabled := lstMods.ItemIndex <> -1;
520 procedure TfrmMain.cmdProxySettingsClick(Sender: TObject);
523 // Apply Proxy Settings
524 case frmProxy.cboProxy.ItemIndex of
525 0: IdFTP.ProxySettings.ProxyType := fpcmNone; // none
526 1: IdFTP.ProxySettings.ProxyType := fpcmHttpProxyWithFtp; // HTTP Proxy with FTP
527 2: IdFTP.ProxySettings.ProxyType := fpcmOpen; // Open
528 3: IdFTP.ProxySettings.ProxyType := fpcmSite; // Site
529 4: IdFTP.ProxySettings.ProxyType := fpcmTransparent; // Transparent
530 5: IdFTP.ProxySettings.ProxyType := fpcmUserPass; // User (Password)
531 6: IdFTP.ProxySettings.ProxyType := fpcmUserSite; // User (Site)
534 IdFTP.ProxySettings.Host := frmProxy.txtHost.Text;
535 IdFTP.ProxySettings.UserName := frmProxy.txtPort.Text;
536 IdFTP.ProxySettings.Password := frmProxy.txtPassword.Text;
537 IdFTP.ProxySettings.Port := StrToInt(frmProxy.txtPort.Text);
540 procedure TfrmMain.txtPortChange(Sender: TObject);
543 if txtPort.Text = '' then
546 // check if value is numeric...
547 for i := Length(txtPort.Text) downto 1 do begin
548 if Pos(txtPort.Text[i], '0123456789') = 0 then begin
549 txtPort.Text := '21';
550 txtPort.SelStart := 4;
557 procedure TfrmMain.trvDirectoriesExpanded(Sender: TObject;
563 if Node.Item[0].Text = 'Scanning...' then begin // no directories added yet
564 Screen.Cursor := crHourGlass;
569 ePath := '/' + CurNode.Text + ePath;
570 CurNode := CurNode.Parent;
571 until (not Assigned(CurNode));
572 // change dir and add directories in it
575 IdFTP.ChangeDir(ePath);
576 with GetAllDirs do begin
578 for i := 0 to Count -1 do begin
579 trvDirectories.Items.AddChild(trvDirectories.Items.AddChild(Node, Strings[i]), 'Scanning...');
584 Application.ProcessMessages;
586 Screen.Cursor := crDefault;
590 procedure TfrmMain.trvDirectoriesChange(Sender: TObject; Node: TTreeNode);
592 cmdNext.Enabled := Assigned(trvDirectories.Selected);
595 procedure TfrmMain.IdFTPWork(Sender: TObject; AWorkMode: TWorkMode;
596 const AWorkCount: Integer);
598 if AWorkCount > 15 then begin
599 ggeItem.Progress := AWorkCount;
600 CurrProgress := AWorkCount;
606 Application.ProcessMessages;
609 procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
611 if (jplWizard.ActivePage = jspFTP) and (IdFTP.Connected) then
613 if (jplWizard.ActivePage = jspInstallProgress) and (ggeAll.Progress <> ggeAll.MaxValue) and (not Cancel) then begin
614 if MessageBox(Handle, 'Do you really want to cancel the installation?', PChar(Application.Title), MB_ICONQUESTION + MB_YESNO) = mrYes then begin
615 Screen.Cursor := crDefault;
616 Application.OnException := ExceptionHandler;
618 if IdFTP.Connected then
626 procedure TfrmMain.ExceptionHandler(Sender: TObject; E: Exception);
628 // IF any exceptions were raised after close, nobody would want them so leave this empty
631 procedure TfrmMain.tmrSpeedTimer(Sender: TObject);
633 Caption := CalcSpeed(OldProgress, CurrProgress);
634 OldProgress := CurrProgress;
637 procedure TfrmMain.trvDirectoriesExpanding(Sender: TObject;
638 Node: TTreeNode; var AllowExpansion: Boolean);
640 Node.ImageIndex := 1;
641 Node.SelectedIndex := 1;
644 procedure TfrmMain.trvDirectoriesCollapsing(Sender: TObject;
645 Node: TTreeNode; var AllowCollapse: Boolean);
647 Node.ImageIndex := 0;
648 Node.SelectedIndex := 0;