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