Subversion Repositories userdetect2

Rev

Rev 86 | Rev 88 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 daniel-mar 1
unit UD2_Main;
2
 
3
interface
4
 
5
{$IF CompilerVersion >= 25.0}
6
{$LEGACYIFEND ON}
7
{$IFEND}
8
 
70 daniel-mar 9
{$INCLUDE 'UserDetect2.inc'}
10
 
68 daniel-mar 11
uses
12
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
13
  Dialogs, StdCtrls, Grids, ValEdit, UD2_Obj, ComCtrls, ImgList, ExtCtrls,
14
  CommCtrl, Menus, VTSListView, VTSCompat;
15
 
16
const
17
  DefaultIniFile = 'UserDetect2.ini';
18
  DefaultWarnIfNothingMatches = 'false';
19
  TagWarnIfNothingMatches = 'WarnIfNothingMatches';
20
  DefaultCloseAfterLaunching = 'false';
21
  TagCloseAfterLaunching = 'CloseAfterLaunching';
22
  TagIcon = 'Icon';
23
 
24
type
25
  TUD2MainForm = class(TForm)
26
    OpenDialog1: TOpenDialog;
27
    PageControl1: TPageControl;
28
    TasksTabSheet: TTabSheet;
29
    TabSheet2: TTabSheet;
30
    TabSheet3: TTabSheet;
31
    IniTemplateMemo: TMemo;
32
    TabSheet4: TTabSheet;
73 daniel-mar 33
    TasksListView: TVTSListView;
34
    TasksImageList: TImageList;
68 daniel-mar 35
    SaveDialog1: TSaveDialog;
36
    TabSheet5: TTabSheet;
37
    Image1: TImage;
38
    Label1: TLabel;
39
    Label2: TLabel;
40
    Label3: TLabel;
41
    Label4: TLabel;
42
    Label5: TLabel;
43
    Label6: TLabel;
44
    Label7: TLabel;
45
    Label8: TLabel;
73 daniel-mar 46
    LoadedPluginsListView: TVTSListView;
47
    IdentificationsListView: TVTSListView;
68 daniel-mar 48
    ErrorsTabSheet: TTabSheet;
49
    ErrorsMemo: TMemo;
50
    Memo1: TMemo;
51
    Panel1: TPanel;
86 daniel-mar 52
    OpenTDFButton: TButton;
53
    SaveTDFButton: TButton;
73 daniel-mar 54
    TasksPopupMenu: TPopupMenu;
68 daniel-mar 55
    Run1: TMenuItem;
56
    Properties1: TMenuItem;
73 daniel-mar 57
    IdentificationsPopupMenu: TPopupMenu;
68 daniel-mar 58
    CopyTaskDefinitionExample1: TMenuItem;
59
    Button3: TButton;
60
    VersionLabel: TLabel;
73 daniel-mar 61
    LoadedPluginsPopupMenu: TPopupMenu;
62
    MenuItem1: TMenuItem;
81 daniel-mar 63
    Panel2: TPanel;
64
    Image2: TImage;
86 daniel-mar 65
    DynamicTestGroupbox: TGroupBox;
66
    DynamicTestPluginComboBox: TComboBox;
67
    DynamicTestPluginLabel: TLabel;
68
    DynamicTestDataLabel: TLabel;
69
    DynamicTestDataEdit: TEdit;
70
    DynamicTestButton: TButton;
68 daniel-mar 71
    procedure FormDestroy(Sender: TObject);
73 daniel-mar 72
    procedure TasksListViewDblClick(Sender: TObject);
73
    procedure TasksListViewKeyPress(Sender: TObject; var Key: Char);
86 daniel-mar 74
    procedure OpenTDFButtonClick(Sender: TObject);
75
    procedure SaveTDFButtonClick(Sender: TObject);
68 daniel-mar 76
    procedure URLLabelClick(Sender: TObject);
73 daniel-mar 77
    procedure TasksPopupMenuPopup(Sender: TObject);
68 daniel-mar 78
    procedure Run1Click(Sender: TObject);
79
    procedure Properties1Click(Sender: TObject);
73 daniel-mar 80
    procedure IdentificationsPopupMenuPopup(Sender: TObject);
68 daniel-mar 81
    procedure CopyTaskDefinitionExample1Click(Sender: TObject);
80 daniel-mar 82
    procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
68 daniel-mar 83
    procedure Button3Click(Sender: TObject);
73 daniel-mar 84
    procedure LoadedPluginsPopupMenuPopup(Sender: TObject);
85
    procedure MenuItem1Click(Sender: TObject);
82 daniel-mar 86
    procedure FormCreate(Sender: TObject);
86 daniel-mar 87
    procedure DynamicTestButtonClick(Sender: TObject);
68 daniel-mar 88
  protected
89
    ud2: TUD2;
90
    procedure LoadTaskList;
91
    procedure LoadDetectedIDs;
92
    procedure LoadINITemplate;
93
    procedure LoadLoadedPluginList;
86 daniel-mar 94
    procedure LoadDynamicPluginList;
68 daniel-mar 95
    function GetIniFileName: string;
96
    procedure DoRun(ShortTaskName: string);
97
    procedure CheckForErrors;
81 daniel-mar 98
  public
99
    procedure Run;
68 daniel-mar 100
  end;
101
 
102
var
103
  UD2MainForm: TUD2MainForm;
104
 
105
implementation
106
 
107
{$R *.dfm}
108
 
109
uses
85 daniel-mar 110
  ShellAPI, Clipbrd, Math, AlphaNumSort, UD2_Utils, UD2_TaskProperties, UD2_Parsing;
68 daniel-mar 111
 
112
type
113
  TUD2ListViewEntry = class(TObject)
114
    ShortTaskName: string;
115
    CloseAfterLaunching: boolean;
116
    TaskPropertiesForm: TForm;
117
  end;
118
 
119
function AddIconRecToImageList(rec: TIconFileIdx; ImageList: TImageList): integer;
120
var
121
  icon: TIcon;
122
begin
123
  icon := TIcon.Create;
124
  try
125
    icon.Handle := ExtractIcon(Application.Handle, PChar(rec.FileName), rec.IconIndex);
126
 
127
    // result := ImageList.AddIcon(ico);
128
    result := AddTransparentIconToImageList(ImageList, icon);
129
  finally
130
    icon.Free;
131
  end;
132
end;
133
 
134
{ TUD2MainForm }
135
 
136
function TUD2MainForm.GetIniFileName: string;
137
resourcestring
138
  LNG_FILE_NOT_FOUND = 'File "%s" not found.';
139
begin
81 daniel-mar 140
  if (ParamCount >= 1) and not CheckBoolParam(1, 'C') then
68 daniel-mar 141
  begin
142
    if FileExists(ParamStr(1)) then
143
    begin
144
      result := ParamStr(1);
145
    end
146
    else
147
    begin
73 daniel-mar 148
      ExitCode := EXITCODE_INI_NOT_FOUND;
68 daniel-mar 149
      MessageDlg(Format(LNG_FILE_NOT_FOUND, [ParamStr(1)]), mtError, [mbOK], 0);
150
      result := '';
151
    end;
152
    Exit;
153
  end
154
  else
155
  begin
156
    if FileExists(DefaultIniFile) then
157
    begin
158
      result := DefaultIniFile;
159
      Exit;
160
    end;
161
 
162
    if FileExists(GetOwnCmdName + '.ini') then
163
    begin
164
      result := GetOwnCmdName + '.ini';
165
      Exit;
166
    end;
167
 
168
    if CompatOpenDialogExecute(OpenDialog1) then
169
    begin
170
      result := OpenDialog1.FileName;
171
      Exit;
172
    end;
173
 
174
    result := '';
175
    Exit;
176
  end;
177
end;
178
 
179
procedure TUD2MainForm.LoadTaskList;
180
var
181
  sl: TStringList;
182
  i: integer;
183
  ShortTaskName, iconString: string;
184
  iconIndex: integer;
185
  obj: TUD2ListViewEntry;
186
begin
73 daniel-mar 187
  TasksListView.Clear;
68 daniel-mar 188
  sl := TStringList.Create;
189
  try
190
    ud2.GetTaskListing(sl);
191
    for i := 0 to sl.Count-1 do
192
    begin
193
      ShortTaskName := sl.Names[i];
194
 
195
      Obj := TUD2ListViewEntry.Create;
196
      Obj.ShortTaskName := ShortTaskName;
197
      Obj.CloseAfterLaunching := ud2.ReadMetatagBool(ShortTaskName, TagCloseAfterLaunching, DefaultCloseAfterLaunching);
198
 
73 daniel-mar 199
      TasksListView.AddItem(sl.Values[ShortTaskName], TObject(Obj));
68 daniel-mar 200
 
201
      iconString := ud2.ReadMetatagString(ShortTaskName, TagIcon, '');
202
      if iconString <> '' then
203
      begin
73 daniel-mar 204
        iconIndex := AddIconRecToImageList(SplitIconString(iconString), TasksImageList);
68 daniel-mar 205
        if iconIndex <> -1 then
206
        begin
73 daniel-mar 207
          TasksListView.Items.Item[TasksListView.Items.Count-1].ImageIndex := iconIndex;
68 daniel-mar 208
        end;
209
      end;
210
    end;
211
  finally
212
    sl.Free;
213
  end;
214
end;
215
 
216
procedure TUD2MainForm.DoRun(ShortTaskName: string);
217
resourcestring
218
  LNG_TASK_NOT_EXISTS = 'The task "%s" does not exist in the INI file.';
219
  LNG_NOTHING_MATCHES = 'No identification string matches to your environment. No application was launched. Please check the Task Definition File.';
220
var
221
  i: integer;
85 daniel-mar 222
  cmds: TUD2CommandArray;
68 daniel-mar 223
begin
224
  if not ud2.TaskExists(ShortTaskName) then
225
  begin
226
    // This can happen if the task name is taken from command line
227
    MessageDlg(Format(LNG_TASK_NOT_EXISTS, [ShortTaskName]), mtError, [mbOK], 0);
73 daniel-mar 228
    ExitCode := EXITCODE_TASK_NOT_EXISTS;
68 daniel-mar 229
    Exit;
230
  end;
231
 
85 daniel-mar 232
  SetLength(cmds, 0);
233
  cmds := ud2.GetCommandList(ShortTaskName);
68 daniel-mar 234
 
85 daniel-mar 235
  if (Length(cmds) = 0) and ud2.ReadMetatagBool(ShortTaskName, TagWarnIfNothingMatches, DefaultWarnIfNothingMatches) then
236
  begin
237
    MessageDlg(LNG_NOTHING_MATCHES, mtWarning, [mbOK], 0);
238
    ExitCode := EXITCODE_TASK_NOTHING_MATCHES;
239
  end;
68 daniel-mar 240
 
85 daniel-mar 241
  for i := Low(cmds) to High(cmds) do
242
  begin
243
    UD2_RunCMD(cmds[i]);
68 daniel-mar 244
  end;
245
end;
246
 
247
procedure TUD2MainForm.FormDestroy(Sender: TObject);
248
var
249
  i: integer;
250
begin
251
  if Assigned(ud2) then ud2.Free;
73 daniel-mar 252
  for i := 0 to TasksListView.Items.Count-1 do
68 daniel-mar 253
  begin
73 daniel-mar 254
    TUD2ListViewEntry(TasksListView.Items.Item[i].Data).Free;
68 daniel-mar 255
  end;
256
end;
257
 
258
procedure TUD2MainForm.CheckForErrors;
259
begin
260
  ErrorsTabSheet.TabVisible := ud2.Errors.Count > 0;
261
  if ErrorsTabSheet.TabVisible then
262
  begin
263
    ErrorsMemo.Lines.Assign(ud2.Errors);
264
    PageControl1.ActivePage := ErrorsTabSheet;
265
  end;
266
end;
267
 
268
procedure TUD2MainForm.LoadDetectedIDs;
269
var
270
  i, j: integer;
271
  pl: TUD2Plugin;
272
  ude: TUD2IdentificationEntry;
273
begin
73 daniel-mar 274
  IdentificationsListView.Clear;
68 daniel-mar 275
  for i := 0 to ud2.LoadedPlugins.Count-1 do
276
  begin
277
    pl := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
278
    for j := 0 to pl.DetectedIdentifications.Count-1 do
279
    begin
280
      ude := pl.DetectedIdentifications.Items[j] as TUD2IdentificationEntry;
73 daniel-mar 281
      with IdentificationsListView.Items.Add do
68 daniel-mar 282
      begin
283
        Caption := pl.PluginName;
83 daniel-mar 284
        if ude.DynamicDataUsed then
285
          SubItems.Add(ude.DynamicData)
286
        else
287
          SubItems.Add('');
68 daniel-mar 288
        SubItems.Add(pl.IdentificationMethodName);
289
        SubItems.Add(ude.IdentificationString);
87 daniel-mar 290
        SubItems.Add(pl.PluginGUIDString)
68 daniel-mar 291
      end;
292
    end;
293
  end;
294
 
73 daniel-mar 295
  for i := 0 to IdentificationsListView.Columns.Count-1 do
68 daniel-mar 296
  begin
73 daniel-mar 297
    IdentificationsListView.Columns.Items[i].Width := LVSCW_AUTOSIZE_USEHEADER;
68 daniel-mar 298
  end;
299
end;
300
 
301
procedure TUD2MainForm.LoadINITemplate;
302
var
303
  i, j: integer;
304
  pl: TUD2Plugin;
305
  ude: TUD2IdentificationEntry;
83 daniel-mar 306
  idNames: TStringList;
68 daniel-mar 307
begin
308
  IniTemplateMemo.Clear;
309
  IniTemplateMemo.Lines.Add('[ExampleTask1]');
310
  IniTemplateMemo.Lines.Add('; Description: Optional but recommended');
311
  IniTemplateMemo.Lines.Add('Description=Run Task #1');
312
  IniTemplateMemo.Lines.Add('; WarnIfNothingMatches: Warns when no application was launched. Default: false.');
313
  IniTemplateMemo.Lines.Add('WarnIfNothingMatches=false');
314
  IniTemplateMemo.Lines.Add('; Optional: IconDLL + IconIndex');
315
  IniTemplateMemo.Lines.Add('Icon=%SystemRoot%\system32\Shell32.dll,3');
316
  IniTemplateMemo.Lines.Add('; Optional: Can be true or false');
317
  IniTemplateMemo.Lines.Add(TagCloseAfterLaunching+'=true');
318
 
319
  for i := 0 to ud2.LoadedPlugins.Count-1 do
320
  begin
321
    pl := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
322
    for j := 0 to pl.DetectedIdentifications.Count-1 do
323
    begin
324
      ude := pl.DetectedIdentifications.Items[j] as TUD2IdentificationEntry;
325
      IniTemplateMemo.Lines.Add(Format('; %s', [ude.Plugin.PluginName]));
83 daniel-mar 326
 
327
      idNames := TStringList.Create;
328
      try
329
        ude.GetIdNames(idNames);
330
        if idNames.Count >= 1 then
331
          IniTemplateMemo.Lines.Add(idNames.Strings[0]+'=calc.exe');
332
      finally
333
        idNames.Free;
334
      end;
335
 
68 daniel-mar 336
    end;
337
  end;
338
end;
339
 
340
procedure TUD2MainForm.LoadLoadedPluginList;
69 daniel-mar 341
resourcestring
342
  LNG_MS = '%dms';
68 daniel-mar 343
var
344
  i: integer;
345
  pl: TUD2Plugin;
346
begin
73 daniel-mar 347
  LoadedPluginsListView.Clear;
68 daniel-mar 348
  for i := 0 to ud2.LoadedPlugins.Count-1 do
349
  begin
350
    pl := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
73 daniel-mar 351
    with LoadedPluginsListView.Items.Add do
68 daniel-mar 352
    begin
353
      Caption := pl.PluginDLL;
354
      SubItems.Add(pl.PluginVendor);
355
      SubItems.Add(pl.PluginName);
356
      SubItems.Add(pl.PluginVersion);
357
      SubItems.Add(pl.IdentificationMethodName);
86 daniel-mar 358
      if pl.AcceptsDynamicRequests then
359
        SubItems.Add('Yes')
360
      else
361
        SubItems.Add('No');
70 daniel-mar 362
      SubItems.Add(IntToStr(pl.DetectedIdentifications.Count));
87 daniel-mar 363
      SubItems.Add(Format(LNG_MS, [Max(1,pl.LoadingTime)])); // at least show 1ms, otherwise it would look unloggical
70 daniel-mar 364
      SubItems.Add(pl.IdentificationProcedureStatusCodeDescribed);
68 daniel-mar 365
      SubItems.Add(pl.PluginGUIDString);
366
    end;
367
  end;
368
 
73 daniel-mar 369
  for i := 0 to LoadedPluginsListView.Columns.Count-1 do
68 daniel-mar 370
  begin
73 daniel-mar 371
    LoadedPluginsListView.Columns.Items[i].Width := LVSCW_AUTOSIZE_USEHEADER;
68 daniel-mar 372
  end;
373
end;
374
 
73 daniel-mar 375
procedure TUD2MainForm.TasksListViewDblClick(Sender: TObject);
68 daniel-mar 376
var
377
  obj: TUD2ListViewEntry;
378
begin
73 daniel-mar 379
  if TasksListView.ItemIndex = -1 then exit;
380
  obj := TUD2ListViewEntry(TasksListView.Selected.Data);
68 daniel-mar 381
  DoRun(obj.ShortTaskName);
382
  if obj.CloseAfterLaunching then Close;
383
end;
384
 
73 daniel-mar 385
procedure TUD2MainForm.TasksListViewKeyPress(Sender: TObject; var Key: Char);
68 daniel-mar 386
begin
387
  if Key = #13 then
388
  begin
73 daniel-mar 389
    TasksListViewDblClick(Sender);
68 daniel-mar 390
  end;
391
end;
392
 
86 daniel-mar 393
procedure TUD2MainForm.OpenTDFButtonClick(Sender: TObject);
85 daniel-mar 394
var
395
  cmd: TUD2Command;
68 daniel-mar 396
begin
85 daniel-mar 397
  cmd.executable := ud2.IniFileName;
398
  cmd.runAsAdmin := false;
399
  cmd.runInOwnDirectory := false;
400
  cmd.windowMode := SW_NORMAL;
401
  UD2_RunCMD(cmd);
68 daniel-mar 402
end;
403
 
86 daniel-mar 404
procedure TUD2MainForm.SaveTDFButtonClick(Sender: TObject);
68 daniel-mar 405
begin
406
  if CompatSaveDialogExecute(SaveDialog1) then
407
  begin
408
    IniTemplateMemo.Lines.SaveToFile(SaveDialog1.FileName);
409
  end;
410
end;
411
 
412
procedure TUD2MainForm.URLLabelClick(Sender: TObject);
413
var
85 daniel-mar 414
  cmd: TUD2Command;
68 daniel-mar 415
begin
85 daniel-mar 416
  cmd.executable := TLabel(Sender).Caption;
417
  if Pos('@', cmd.executable) > 0 then
418
    cmd.executable := 'mailto:' + cmd.executable
68 daniel-mar 419
  else
85 daniel-mar 420
    cmd.executable := 'http://' + cmd.executable;
421
 
422
  cmd.runAsAdmin := false;
423
  cmd.runInOwnDirectory := false;
424
  cmd.windowMode := SW_NORMAL;
425
 
426
  UD2_RunCMD(cmd);
68 daniel-mar 427
end;
428
 
73 daniel-mar 429
procedure TUD2MainForm.TasksPopupMenuPopup(Sender: TObject);
68 daniel-mar 430
begin
73 daniel-mar 431
  Run1.Enabled := TasksListView.ItemIndex <> -1;
432
  Properties1.Enabled := TasksListView.ItemIndex <> -1;
68 daniel-mar 433
end;
434
 
435
procedure TUD2MainForm.Run1Click(Sender: TObject);
436
begin
73 daniel-mar 437
  TasksListViewDblClick(Sender);
68 daniel-mar 438
end;
439
 
440
procedure TUD2MainForm.Properties1Click(Sender: TObject);
441
var
442
  obj: TUD2ListViewEntry;
443
begin
73 daniel-mar 444
  if TasksListView.ItemIndex = -1 then exit;
445
  obj := TUD2ListViewEntry(TasksListView.Selected.Data);
68 daniel-mar 446
  if obj.TaskPropertiesForm = nil then
447
  begin
448
    obj.TaskPropertiesForm := TUD2TaskPropertiesForm.Create(Self, ud2, obj.ShortTaskName);
449
  end;
450
  obj.TaskPropertiesForm.Show;
451
end;
452
 
73 daniel-mar 453
procedure TUD2MainForm.IdentificationsPopupMenuPopup(Sender: TObject);
68 daniel-mar 454
begin
73 daniel-mar 455
  CopyTaskDefinitionExample1.Enabled := IdentificationsListView.ItemIndex <> -1;
68 daniel-mar 456
end;
457
 
458
procedure TUD2MainForm.CopyTaskDefinitionExample1Click(Sender: TObject);
459
var
460
  s: string;
461
begin
73 daniel-mar 462
  s := '; '+IdentificationsListView.Selected.Caption+#13#10+
463
       IdentificationsListView.Selected.SubItems[0] + ':' + IdentificationsListView.Selected.SubItems[1] + '=calc.exe'+#13#10+
68 daniel-mar 464
       #13#10+
465
       '; Alternatively:'+#13#10+
73 daniel-mar 466
       IdentificationsListView.Selected.SubItems[2] + ':' + IdentificationsListView.Selected.SubItems[1] + '=calc.exe'+#13#10;
68 daniel-mar 467
  Clipboard.AsText := s;
468
end;
469
 
470
procedure TUD2MainForm.ListViewCompare(Sender: TObject; Item1,
471
  Item2: TListItem; Data: Integer; var Compare: Integer);
472
var
473
  ListView: TVTSListView;
474
begin
475
  ListView := Sender as TVTSListView;
476
  if ListView.CurSortedColumn = 0 then
477
  begin
69 daniel-mar 478
    Compare := AlphaNumCompare(Item1.Caption, Item2.Caption);
68 daniel-mar 479
  end
480
  else
481
  begin
69 daniel-mar 482
    Compare := AlphaNumCompare(Item1.SubItems[ListView.CurSortedColumn-1],
483
                               Item2.SubItems[ListView.CurSortedColumn-1]);
68 daniel-mar 484
  end;
485
  if ListView.CurSortedDesc then Compare := -Compare;
486
end;
487
 
488
procedure TUD2MainForm.Button3Click(Sender: TObject);
489
begin
490
  VTS_CheckUpdates('userdetect2', VersionLabel.Caption);
491
end;
492
 
73 daniel-mar 493
procedure TUD2MainForm.LoadedPluginsPopupMenuPopup(Sender: TObject);
494
begin
495
  MenuItem1.Enabled := LoadedPluginsListView.ItemIndex <> -1;
496
end;
497
 
498
procedure TUD2MainForm.MenuItem1Click(Sender: TObject);
499
var
500
  s: string;
501
begin
80 daniel-mar 502
  s := '; ' + LoadedPluginsListView.Selected.SubItems.Strings[6];
73 daniel-mar 503
  Clipboard.AsText := s;
504
end;
505
 
81 daniel-mar 506
procedure TUD2MainForm.Run;
507
resourcestring
508
  LNG_SYNTAX = 'Syntax: %s [TaskDefinitionFile [/T TaskName] | /C IdentificationTerm [Command] | /?]';
509
var
510
  LoadedIniFile: string;
511
begin
512
  ExitCode := EXITCODE_OK;
513
 
514
  if ((ParamCount = 1) and CheckBoolParam(1, '?')) or
515
     (CheckBoolParam(2, 'T') and (ParamCount > 3)) or
516
     (CheckBoolParam(1, 'C') and (ParamCount > 3)) or
517
     (not CheckBoolParam(2, 'T') and not CheckBoolParam(1, 'C') and (ParamCount > 1)) then
518
  begin
519
    ExitCode := EXITCODE_SYNTAX_ERROR;
520
    MessageDlg(Format(LNG_SYNTAX, [GetOwnCmdName]), mtInformation, [mbOK], 0);
521
 
522
    Visible := false;
523
    Close;
524
    Exit;
525
  end;
526
 
527
  LoadedIniFile := GetIniFileName;
528
  if LoadedIniFile = '' then
529
  begin
530
    Visible := false;
531
    Close;
532
    Exit;
533
  end;
534
  ud2 := TUD2.Create(LoadedIniFile);
535
 
82 daniel-mar 536
  ud2.HandlePluginDir('',        '*.udp');
537
  ud2.HandlePluginDir('Plugins', '*.udp');
81 daniel-mar 538
  ud2.HandlePluginDir('Plugins', '*.dll');
539
 
540
  if CheckBoolParam(1, 'C') then
541
  begin
542
    if ud2.FulfilsEverySubterm(ParamStr(2)) then
543
    begin
544
      ExitCode := EXITCODE_OK;
545
 
85 daniel-mar 546
      if ParamStr(3) <> '' then
547
      begin
548
        UD2_RunCMD(UD2P_DecodeCommand(ParamStr(3)));
549
      end;
81 daniel-mar 550
    end
551
    else
552
    begin
553
      ExitCode := EXITCODE_TASK_NOTHING_MATCHES;
554
    end;
555
 
556
    Visible := false;
557
    Close;
558
    Exit;
559
  end
560
  else if CheckBoolParam(2, 'T') then
561
  begin
562
    DoRun(ParamStr(3));
563
 
564
    Visible := false;
565
    Close;
566
    Exit;
567
  end
568
  else
569
  begin
570
    LoadTaskList;
571
    LoadDetectedIDs;
572
    LoadINITemplate;
573
    LoadLoadedPluginList;
86 daniel-mar 574
    LoadDynamicPluginList;
81 daniel-mar 575
    CheckForErrors;
576
 
577
    Visible := true;
578
    Exit;
579
  end;
580
end;
581
 
82 daniel-mar 582
procedure TUD2MainForm.FormCreate(Sender: TObject);
583
begin
584
  // To avoid accidental change of the default tab from the IDE VCL Designer
585
  PageControl1.ActivePage := TasksTabSheet;
586
end;
587
 
86 daniel-mar 588
procedure TUD2MainForm.DynamicTestButtonClick(Sender: TObject);
83 daniel-mar 589
var
86 daniel-mar 590
  p: TUD2Plugin;
591
  x: TArrayOfString;
592
  newStuff: boolean;
593
resourcestring
594
  LNG_DETECTED_DYNAMICS = 'The plugin returns following identification strings:';
87 daniel-mar 595
  LNG_NOTHING_DETECTED = 'The plugin did not send any identification strings.';
83 daniel-mar 596
begin
86 daniel-mar 597
  if DynamicTestPluginComboBox.ItemIndex = -1 then
598
  begin
599
    ShowMessage('Please select a plugin that is accepting dynamic requests.');
600
    exit;
601
  end;
84 daniel-mar 602
 
86 daniel-mar 603
  p := DynamicTestPluginComboBox.Items.Objects[DynamicTestPluginComboBox.ItemIndex] as TUD2Plugin;
604
 
605
  newStuff := p.InvokeDynamicCheck(DynamicTestDataEdit.Text, x);
606
 
87 daniel-mar 607
  if Length(x) > 0 then
608
    ShowMessage(LNG_DETECTED_DYNAMICS + #13#10#13#10 + MergeString(x, #13#10))
609
  else
610
    ShowMessage(LNG_NOTHING_DETECTED);
611
 
86 daniel-mar 612
  if newStuff then
83 daniel-mar 613
  begin
86 daniel-mar 614
    LoadDetectedIDs;
615
    LoadINITemplate;
87 daniel-mar 616
    LoadLoadedPluginList; // To update the "Detected IDs" column
86 daniel-mar 617
  end;
618
end;
85 daniel-mar 619
 
86 daniel-mar 620
procedure TUD2MainForm.LoadDynamicPluginList;
621
var
622
  i: integer;
623
  p: TUD2Plugin;
624
begin
625
  for i := 0 to ud2.LoadedPlugins.Count-1 do
626
  begin
627
    p := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
628
    if p.AcceptsDynamicRequests then
85 daniel-mar 629
    begin
86 daniel-mar 630
      DynamicTestPluginComboBox.Items.AddObject(p.PluginName, p);
83 daniel-mar 631
    end;
632
  end;
633
end;
634
 
68 daniel-mar 635
end.