Subversion Repositories userdetect2

Rev

Rev 92 | Rev 95 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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