Subversion Repositories userdetect2

Rev

Rev 88 | Rev 92 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 88 Rev 90
Line 9... Line 9...
9
{$INCLUDE 'UserDetect2.inc'}
9
{$INCLUDE 'UserDetect2.inc'}
10
 
10
 
11
uses
11
uses
12
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
12
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
13
  Dialogs, StdCtrls, Grids, ValEdit, UD2_Obj, ComCtrls, ImgList, ExtCtrls,
13
  Dialogs, StdCtrls, Grids, ValEdit, UD2_Obj, ComCtrls, ImgList, ExtCtrls,
14
  CommCtrl, Menus, VTSListView, VTSCompat;
14
  CommCtrl, Menus, VTSListView, VTSCompat, UD2_PluginStatus;
15
 
15
 
16
const
16
const
17
  DefaultIniFile = 'UserDetect2.ini';
17
  DefaultIniFile = 'UserDetect2.ini';
-
 
18
  DefaultWarnIfNothingMatchesGUI = 'true';
-
 
19
  TagWarnIfNothingMatchesGUI = 'WarnIfNothingMatches.GUI';
18
  DefaultWarnIfNothingMatches = 'false';
20
  DefaultWarnIfNothingMatchesCLI = 'false';
19
  TagWarnIfNothingMatches = 'WarnIfNothingMatches';
21
  TagWarnIfNothingMatchesCLI = 'WarnIfNothingMatches.CLI';
20
  DefaultCloseAfterLaunching = 'false';
22
  DefaultCloseAfterLaunching = 'false';
21
  TagCloseAfterLaunching = 'CloseAfterLaunching';
23
  TagCloseAfterLaunching = 'CloseAfterLaunching';
22
  TagIcon = 'Icon';
24
  TagIcon = 'Icon';
23
 
25
 
24
type
26
type
Line 91... Line 93...
91
    procedure LoadDetectedIDs;
93
    procedure LoadDetectedIDs;
92
    procedure LoadINITemplate;
94
    procedure LoadINITemplate;
93
    procedure LoadLoadedPluginList;
95
    procedure LoadLoadedPluginList;
94
    procedure LoadDynamicPluginList;
96
    procedure LoadDynamicPluginList;
95
    function GetIniFileName: string;
97
    function GetIniFileName: string;
96
    procedure DoRun(ShortTaskName: string);
98
    procedure DoRun(ShortTaskName: string; gui: boolean);
97
    procedure CheckForErrors;
99
    procedure CheckForErrors;
98
  public
100
  public
99
    procedure Run;
101
    procedure Run;
100
  end;
102
  end;
101
 
103
 
Line 216... Line 218...
216
  finally
218
  finally
217
    sl.Free;
219
    sl.Free;
218
  end;
220
  end;
219
end;
221
end;
220
 
222
 
221
procedure TUD2MainForm.DoRun(ShortTaskName: string);
223
procedure TUD2MainForm.DoRun(ShortTaskName: string; gui: boolean);
222
resourcestring
224
resourcestring
223
  LNG_TASK_NOT_EXISTS = 'The task "%s" does not exist in the INI file.';
225
  LNG_TASK_NOT_EXISTS = 'The task "%s" does not exist in the INI file.';
224
  LNG_NOTHING_MATCHES = 'No identification string matches to your environment. No application was launched. Please check the Task Definition File.';
226
  LNG_NOTHING_MATCHES = 'No identification string matches to your environment. No application was launched. Please check the Task Definition File.';
225
var
227
var
226
  i: integer;
228
  i: integer;
227
  cmds: TUD2CommandArray;
229
  cmds: TUD2CommandArray;
-
 
230
  showMismatchError: boolean;
228
begin
231
begin
229
  if not ud2.TaskExists(ShortTaskName) then
232
  if not ud2.TaskExists(ShortTaskName) then
230
  begin
233
  begin
231
    // This can happen if the task name is taken from command line
234
    // This can happen if the task name is taken from command line
232
    MessageDlg(Format(LNG_TASK_NOT_EXISTS, [ShortTaskName]), mtError, [mbOK], 0);
235
    MessageDlg(Format(LNG_TASK_NOT_EXISTS, [ShortTaskName]), mtError, [mbOK], 0);
233
    ExitCode := EXITCODE_TASK_NOT_EXISTS;
236
    ExitCode := EXITCODE_TASK_NOT_EXISTS;
234
    Exit;
237
    Exit;
235
  end;
238
  end;
236
 
239
 
237
  SetLength(cmds, 0);
240
  SetLength(cmds, 0);
238
  cmds := ud2.GetCommandList(ShortTaskName);
241
  cmds := ud2.GetCommandList(ShortTaskName); // TODO: What to do with AErrorOut (errors from dynamic queries?)
239
 
242
 
-
 
243
  if gui then
-
 
244
    showMismatchError := ud2.ReadMetatagBool(ShortTaskName, TagWarnIfNothingMatchesGUI, DefaultWarnIfNothingMatchesGUI)
-
 
245
  else
240
  if (Length(cmds) = 0) and ud2.ReadMetatagBool(ShortTaskName, TagWarnIfNothingMatches, DefaultWarnIfNothingMatches) then
246
    showMismatchError := ud2.ReadMetatagBool(ShortTaskName, TagWarnIfNothingMatchesCLI, DefaultWarnIfNothingMatchesCLI);
-
 
247
 
-
 
248
  if (Length(cmds) = 0) and showMismatchError then
241
  begin
249
  begin
242
    MessageDlg(LNG_NOTHING_MATCHES, mtWarning, [mbOK], 0);
250
    MessageDlg(LNG_NOTHING_MATCHES, mtWarning, [mbOK], 0);
243
    ExitCode := EXITCODE_TASK_NOTHING_MATCHES;
251
    ExitCode := EXITCODE_TASK_NOTHING_MATCHES;
244
  end;
252
  end;
245
 
253
 
Line 312... Line 320...
312
  ude: TUD2IdentificationEntry;
320
  ude: TUD2IdentificationEntry;
313
  idNames: TStringList;
321
  idNames: TStringList;
314
begin
322
begin
315
  IniTemplateMemo.Clear;
323
  IniTemplateMemo.Clear;
316
  IniTemplateMemo.Lines.Add('[ExampleTask1]');
324
  IniTemplateMemo.Lines.Add('[ExampleTask1]');
317
  IniTemplateMemo.Lines.Add('; Description: Optional but recommended');
325
  IniTemplateMemo.Lines.Add('; Optional but recommended');
318
  IniTemplateMemo.Lines.Add('Description=Run Task #1');
326
  IniTemplateMemo.Lines.Add(UD2_TagDescription+'=Run Task #1');
319
  IniTemplateMemo.Lines.Add('; WarnIfNothingMatches: Warns when no application was launched. Default: false.');
327
  IniTemplateMemo.Lines.Add('; Warns when no application was launched. Default: false.');
-
 
328
  IniTemplateMemo.Lines.Add(TagWarnIfNothingMatchesGUI+'='+DefaultWarnIfNothingMatchesGUI);
320
  IniTemplateMemo.Lines.Add('WarnIfNothingMatches=false');
329
  IniTemplateMemo.Lines.Add(TagWarnIfNothingMatchesCLI+'='+DefaultWarnIfNothingMatchesCLI);
321
  IniTemplateMemo.Lines.Add('; Optional: IconDLL + IconIndex');
330
  IniTemplateMemo.Lines.Add('; Optional: IconDLL + IconIndex');
322
  IniTemplateMemo.Lines.Add('Icon=%SystemRoot%\system32\Shell32.dll,3');
331
  IniTemplateMemo.Lines.Add(TagIcon+'=%SystemRoot%\system32\Shell32.dll,3');
323
  IniTemplateMemo.Lines.Add('; Optional: Can be true or false');
332
  IniTemplateMemo.Lines.Add('; Optional: Can be true or false');
324
  IniTemplateMemo.Lines.Add(TagCloseAfterLaunching+'=true');
333
  IniTemplateMemo.Lines.Add(TagCloseAfterLaunching+'='+DefaultCloseAfterLaunching);
325
 
334
 
326
  for i := 0 to ud2.LoadedPlugins.Count-1 do
335
  for i := 0 to ud2.LoadedPlugins.Count-1 do
327
  begin
336
  begin
328
    pl := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
337
    pl := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
329
    for j := 0 to pl.DetectedIdentifications.Count-1 do
338
    for j := 0 to pl.DetectedIdentifications.Count-1 do
Line 383... Line 392...
383
var
392
var
384
  obj: TUD2ListViewEntry;
393
  obj: TUD2ListViewEntry;
385
begin
394
begin
386
  if TasksListView.ItemIndex = -1 then exit;
395
  if TasksListView.ItemIndex = -1 then exit;
387
  obj := TUD2ListViewEntry(TasksListView.Selected.Data);
396
  obj := TUD2ListViewEntry(TasksListView.Selected.Data);
388
  DoRun(obj.ShortTaskName);
397
  DoRun(obj.ShortTaskName, true);
389
  if obj.CloseAfterLaunching then Close;
398
  if obj.CloseAfterLaunching then Close;
390
end;
399
end;
391
 
400
 
392
procedure TUD2MainForm.TasksListViewKeyPress(Sender: TObject; var Key: Char);
401
procedure TUD2MainForm.TasksListViewKeyPress(Sender: TObject; var Key: Char);
393
begin
402
begin
Line 564... Line 573...
564
    Close;
573
    Close;
565
    Exit;
574
    Exit;
566
  end
575
  end
567
  else if CheckBoolParam(2, 'T') then
576
  else if CheckBoolParam(2, 'T') then
568
  begin
577
  begin
569
    DoRun(ParamStr(3));
578
    DoRun(ParamStr(3), false);
570
 
579
 
571
    Visible := false;
580
    Visible := false;
572
    Close;
581
    Close;
573
    Exit;
582
    Exit;
574
  end
583
  end
Line 595... Line 604...
595
procedure TUD2MainForm.DynamicTestButtonClick(Sender: TObject);
604
procedure TUD2MainForm.DynamicTestButtonClick(Sender: TObject);
596
var
605
var
597
  p: TUD2Plugin;
606
  p: TUD2Plugin;
598
  x: TArrayOfString;
607
  x: TArrayOfString;
599
  newStuff: boolean;
608
  newStuff: boolean;
-
 
609
  errors: TStrings;
600
resourcestring
610
resourcestring
601
  LNG_DETECTED_DYNAMICS = 'The plugin returns following identification strings:';
611
  LNG_DETECTED_DYNAMICS = 'The plugin returns following identification strings:';
602
  LNG_NOTHING_DETECTED = 'The plugin did not send any identification strings.';
612
  LNG_NOTHING_DETECTED = 'The plugin did not send any identification strings.';
-
 
613
  LNG_STATUS_RETURNED = 'The plugin sent following status in reply to your request:';
-
 
614
  LNG_ERROR_RETURNED = 'The dynamic plugin could not load. The plugin sent following error messages:';
603
begin
615
begin
604
  if DynamicTestPluginComboBox.ItemIndex = -1 then
616
  if DynamicTestPluginComboBox.ItemIndex = -1 then
605
  begin
617
  begin
606
    ShowMessage('Please select a plugin that is accepting dynamic requests.');
618
    ShowMessage('Please select a plugin that is accepting dynamic requests.');
607
    exit;
619
    Exit;
608
  end;
620
  end;
609
 
621
 
610
  p := DynamicTestPluginComboBox.Items.Objects[DynamicTestPluginComboBox.ItemIndex] as TUD2Plugin;
622
  p := DynamicTestPluginComboBox.Items.Objects[DynamicTestPluginComboBox.ItemIndex] as TUD2Plugin;
611
 
623
 
-
 
624
  errors := TStringList.Create;
-
 
625
  try
612
  newStuff := p.InvokeDynamicCheck(DynamicTestDataEdit.Text, x);
626
    newStuff := p.InvokeDynamicCheck(DynamicTestDataEdit.Text, errors, x);
-
 
627
    if errors.Count > 0 then
-
 
628
    begin
-
 
629
      ShowMessage(LNG_ERROR_RETURNED + #13#10#13#10 + errors.Text);
-
 
630
      Exit;
-
 
631
    end;
-
 
632
  finally
-
 
633
    FreeAndNil(errors);
-
 
634
  end;
-
 
635
 
-
 
636
  if p.IdentificationProcedureStatusCode.wCategory <> UD2_STATUSCAT_SUCCESS then
-
 
637
  begin
-
 
638
    // e.g. "Not available" because of invalid dynamic input data
-
 
639
    ShowMessage(LNG_STATUS_RETURNED + #13#10#13#10 + p.IdentificationProcedureStatusCodeDescribed);
-
 
640
    Exit;
-
 
641
  end;
613
 
642
 
614
  if Length(x) > 0 then
643
  if Length(x) > 0 then
615
    ShowMessage(LNG_DETECTED_DYNAMICS + #13#10#13#10 + MergeString(x, #13#10))
644
    ShowMessage(LNG_DETECTED_DYNAMICS + #13#10#13#10 + MergeString(x, #13#10))
616
  else
645
  else
617
    ShowMessage(LNG_NOTHING_DETECTED);
646
    ShowMessage(LNG_NOTHING_DETECTED);
Line 633... Line 662...
633
  for i := 0 to ud2.LoadedPlugins.Count-1 do
662
  for i := 0 to ud2.LoadedPlugins.Count-1 do
634
  begin
663
  begin
635
    p := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
664
    p := ud2.LoadedPlugins.Items[i] as TUD2Plugin;
636
    if p.AcceptsDynamicRequests then
665
    if p.AcceptsDynamicRequests then
637
    begin
666
    begin
-
 
667
      // TODO: PROBLEM!! Beim Dynamic Check (Dynamic Query) wird der plugin status überschrieben!!!
638
      DynamicTestPluginComboBox.Items.AddObject(p.PluginName, p);
668
      DynamicTestPluginComboBox.Items.AddObject(p.PluginName, p);
639
    end;
669
    end;
640
  end;
670
  end;
641
end;
671
end;
642
 
672