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