Subversion Repositories userdetect2

Rev

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