Rev 84 | Rev 86 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 84 | Rev 85 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | 8 | ||
9 | {$INCLUDE 'UserDetect2.inc'} |
9 | {$INCLUDE 'UserDetect2.inc'} |
10 | 10 | ||
11 | uses |
11 | uses |
12 | Windows, SysUtils, Classes, IniFiles, Contnrs, Dialogs, UD2_PluginIntf, |
12 | Windows, SysUtils, Classes, IniFiles, Contnrs, Dialogs, UD2_PluginIntf, |
13 | UD2_PluginStatus, UD2_Utils; |
13 | UD2_PluginStatus, UD2_Utils, UD2_Parsing; |
14 | 14 | ||
15 | type |
15 | type |
16 | TUD2IdentificationEntry = class; |
16 | TUD2IdentificationEntry = class; |
17 | 17 | ||
18 | TUD2Plugin = class(TObject) |
18 | TUD2Plugin = class(TObject) |
Line 75... | Line 75... | ||
75 | property IniFileName: string read FIniFileName; |
75 | property IniFileName: string read FIniFileName; |
76 | property Errors: TStrings read FErrors; |
76 | property Errors: TStrings read FErrors; |
77 | property LoadedPlugins: TObjectList{<TUD2Plugin>} read FLoadedPlugins; |
77 | property LoadedPlugins: TObjectList{<TUD2Plugin>} read FLoadedPlugins; |
78 | property IniFile: TMemIniFile read FIniFile; |
78 | property IniFile: TMemIniFile read FIniFile; |
79 | procedure GetAllDetectedIDs(outSL: TStrings); |
79 | procedure GetAllDetectedIDs(outSL: TStrings); |
- | 80 | function FulfilsEverySubterm(conds: TUD2TDFConditionArray; slIdNames: TStrings=nil): boolean; overload; |
|
80 | function FulfilsEverySubterm(idTerm: WideString; slIdNames: TStrings=nil): boolean; |
81 | function FulfilsEverySubterm(idTerm: WideString; slIdNames: TStrings=nil): boolean; overload; |
81 | procedure CheckTerm(idTermAndCmd: string; commandSLout: TStrings; slIdNames: TStrings=nil); |
82 | function CheckTerm(idTermAndCmd: string; slIdNames: TStrings=nil): TUD2CommandArray; |
82 | function FindPluginByMethodNameOrGuid(idMethodName: string): TUD2Plugin; |
83 | function FindPluginByMethodNameOrGuid(idMethodName: string): TUD2Plugin; |
83 | procedure GetCommandList(ShortTaskName: string; outSL: TStrings); |
84 | function GetCommandList(ShortTaskName: string): TUD2CommandArray; |
84 | procedure HandlePluginDir(APluginDir, AFileMask: string); |
85 | procedure HandlePluginDir(APluginDir, AFileMask: string); |
85 | procedure GetTaskListing(outSL: TStrings); |
86 | procedure GetTaskListing(outSL: TStrings); |
86 | constructor Create(AIniFileName: string); |
87 | constructor Create(AIniFileName: string); |
87 | destructor Destroy; override; |
88 | destructor Destroy; override; |
88 | function TaskExists(ShortTaskName: string): boolean; |
89 | function TaskExists(ShortTaskName: string): boolean; |
Line 248... | Line 249... | ||
248 | end; |
249 | end; |
249 | 250 | ||
250 | { TUD2IdentificationEntry } |
251 | { TUD2IdentificationEntry } |
251 | 252 | ||
252 | procedure TUD2IdentificationEntry.GetIdNames(sl: TStrings); |
253 | procedure TUD2IdentificationEntry.GetIdNames(sl: TStrings); |
- | 254 | var |
|
- | 255 | cond: TUD2TDFCondition; |
|
253 | begin |
256 | begin |
254 | if DynamicDataUsed then |
257 | cond.idMethodName := Plugin.IdentificationMethodName; |
255 | begin |
258 | cond.idStr := IdentificationString; |
256 | sl.Add(Plugin.IdentificationMethodName+'('+DynamicData+'):'+IdentificationString); |
259 | cond.dynamicDataUsed := DynamicDataUsed; |
257 | sl.Add(Plugin.PluginGUIDString+'('+DynamicData+'):'+IdentificationString); |
260 | cond.dynamicData := DynamicData; |
258 | end |
261 | sl.Add(UD2_CondToStr(cond)); |
259 | else |
262 | |
260 | begin |
- | |
261 | sl.Add(Plugin.IdentificationMethodName+':'+IdentificationString); |
263 | cond.idMethodName := Plugin.PluginGUIDString; |
262 | sl.Add(Plugin.PluginGUIDString+':'+IdentificationString); |
264 | sl.Add(UD2_CondToStr(cond)); |
263 | end; |
- | |
264 | end; |
265 | end; |
265 | 266 | ||
266 | constructor TUD2IdentificationEntry.Create(AIdentificationString: WideString; |
267 | constructor TUD2IdentificationEntry.Create(AIdentificationString: WideString; |
267 | APlugin: TUD2Plugin); |
268 | APlugin: TUD2Plugin); |
268 | begin |
269 | begin |
Line 440... | Line 441... | ||
440 | ude.GetIdNames(outSL); |
441 | ude.GetIdNames(outSL); |
441 | end; |
442 | end; |
442 | end; |
443 | end; |
443 | end; |
444 | end; |
444 | 445 | ||
- | 446 | function TUD2.FulfilsEverySubterm(conds: TUD2TDFConditionArray; slIdNames: TStrings=nil): boolean; |
|
- | 447 | begin |
|
- | 448 | result := FulfilsEverySubterm(UD2_CondsToStr(conds), slIdNames); |
|
- | 449 | end; |
|
- | 450 | ||
445 | function TUD2.FulfilsEverySubterm(idTerm: WideString; slIdNames: TStrings=nil): boolean; |
451 | function TUD2.FulfilsEverySubterm(idTerm: WideString; slIdNames: TStrings=nil): boolean; |
446 | const |
- | |
447 | CASE_SENSITIVE_FLAG = '$CASESENSITIVE$'; |
- | |
448 | var |
452 | var |
449 | x, a, b: TArrayOfString; |
- | |
450 | i: integer; |
453 | i: integer; |
451 | p: TUD2Plugin; |
454 | p: TUD2Plugin; |
452 | idName: WideString; |
- | |
453 | cleanUpStringList: boolean; |
455 | cleanUpStringList: boolean; |
454 | caseSensitive: boolean; |
456 | conds: TUD2TDFConditionArray; |
455 | dynamicData: string; |
457 | cond: TUD2TDFCondition; |
456 | idMethodName: string; |
458 | idName: string; |
457 | begin |
459 | begin |
458 | cleanUpStringList := slIdNames = nil; |
460 | cleanUpStringList := slIdNames = nil; |
459 | try |
461 | try |
460 | if cleanUpStringList then |
462 | if cleanUpStringList then |
461 | begin |
463 | begin |
462 | slIdNames := TStringList.Create; |
464 | slIdNames := TStringList.Create; |
463 | GetAllDetectedIDs(slIdNames); |
465 | GetAllDetectedIDs(slIdNames); |
464 | end; |
466 | end; |
465 | 467 | ||
466 | SetLength(x, 0); |
- | |
467 | if Pos(':', idTerm) = 0 then |
- | |
468 | begin |
- | |
469 | // Exclude stuff like "Description" |
468 | conds := UD2P_ParseConditions(idTerm); |
470 | result := false; |
- | |
471 | Exit; |
- | |
472 | end; |
469 | |
473 | x := SplitString('&&', idTerm); |
- | |
474 | result := true; |
470 | result := true; |
475 | for i := Low(x) to High(x) do |
471 | for i := Low(conds) to High(conds) do |
476 | begin |
472 | begin |
477 | idName := x[i]; |
473 | cond := conds[i]; |
478 | - | ||
479 | /// --- Start Dynamic Extension |
- | |
480 | 474 | ||
481 | // xxxxxx ( xxxxx ): xxxxxxxxxxxx |
- | |
482 | // xxxxx ( xx:xx ): xxxxx:xxx(x) |
- | |
483 | // xxxxxxxxxxxx : xxxxx(xxx)xx |
- | |
484 | - | ||
485 | SetLength(a, 0); |
- | |
486 | a := SplitString('(', idName); |
475 | if cond.dynamicDataUsed then |
487 | if (Length(a) >= 2) and (Pos(':', a[0]) = 0) then |
- | |
488 | begin |
476 | begin |
489 | SetLength(b, 0); |
- | |
490 | b := SplitString('):', a[1]); |
477 | p := FindPluginByMethodNameOrGuid(cond.idMethodName); |
491 | if Length(b) >= 2 then |
478 | if Assigned(p) then |
492 | begin |
479 | begin |
493 | dynamicData := b[0]; |
- | |
494 | idMethodName := a[0]; |
- | |
495 | - | ||
496 | p := FindPluginByMethodNameOrGuid(idMethodName); |
480 | if p.InvokeDynamicCheck(cond.dynamicData) then |
497 | if Assigned(p) then |
- | |
498 | begin |
481 | begin |
499 | if p.InvokeDynamicCheck(dynamicData) then |
- | |
500 | begin |
- | |
501 | // Reload the identifications |
482 | // Reload the identifications |
502 | slIdNames.Clear; |
483 | slIdNames.Clear; |
503 | GetAllDetectedIDs(slIdNames); |
484 | GetAllDetectedIDs(slIdNames); |
504 | end; |
- | |
505 | end; |
485 | end; |
506 | end; |
486 | end; |
507 | end; |
487 | end; |
508 | 488 | ||
509 | /// --- End Dynamic Extension |
- | |
510 | - | ||
511 | if Pos(CASE_SENSITIVE_FLAG, idName) >= 1 then |
- | |
512 | begin |
- | |
513 | idName := StringReplace(idName, CASE_SENSITIVE_FLAG, '', [rfReplaceAll]); |
- | |
514 | caseSensitive := true; |
489 | idName := UD2_CondToStr(cond); |
515 | end |
- | |
516 | else |
- | |
517 | begin |
- | |
518 | caseSensitive := false; |
- | |
519 | end; |
- | |
520 | 490 | ||
521 | if (not caseSensitive and (slIdNames.IndexOf(idName) = -1)) or |
491 | if (not cond.caseSensitive and (slIdNames.IndexOf(idName) = -1)) or |
522 | (caseSensitive and (IndexOf_CS(slIdNames, idName) = -1)) then |
492 | (cond.caseSensitive and (IndexOf_CS(slIdNames, idName) = -1)) then |
523 | begin |
493 | begin |
524 | result := false; |
494 | result := false; |
525 | break; |
495 | break; |
526 | end; |
496 | end; |
527 | end; |
497 | end; |
Line 547... | Line 517... | ||
547 | Exit; |
517 | Exit; |
548 | end; |
518 | end; |
549 | end; |
519 | end; |
550 | end; |
520 | end; |
551 | 521 | ||
552 | procedure TUD2.GetCommandList(ShortTaskName: string; outSL: TStrings); |
522 | function TUD2.GetCommandList(ShortTaskName: string): TUD2CommandArray; |
553 | var |
523 | var |
554 | i: integer; |
524 | i, j, l: integer; |
555 | slSV, slIdNames: TStrings; |
525 | slSV, slIdNames: TStrings; |
- | 526 | tmpCmds: TUD2CommandArray; |
|
556 | begin |
527 | begin |
- | 528 | SetLength(result, 0); |
|
- | 529 | SetLength(tmpCmds, 0); |
|
- | 530 | ||
557 | slIdNames := TStringList.Create; |
531 | slIdNames := TStringList.Create; |
558 | try |
532 | try |
559 | GetAllDetectedIDs(slIdNames); |
533 | GetAllDetectedIDs(slIdNames); |
560 | 534 | ||
561 | slSV := TStringList.Create; |
535 | slSV := TStringList.Create; |
562 | try |
536 | try |
563 | FIniFile.ReadSectionValues(ShortTaskName, slSV); |
537 | FIniFile.ReadSectionValues(ShortTaskName, slSV); |
564 | for i := 0 to slSV.Count-1 do |
538 | for i := 0 to slSV.Count-1 do |
565 | begin |
539 | begin |
566 | CheckTerm(slSV.Strings[i], outSL, slIdNames); |
540 | tmpCmds := CheckTerm(slSV.Strings[i], slIdNames); |
- | 541 | for j := Low(tmpCmds) to High(tmpCmds) do |
|
- | 542 | begin |
|
- | 543 | l := Length(result); |
|
- | 544 | SetLength(result, l+1); |
|
- | 545 | result[l] := tmpCmds[j]; |
|
- | 546 | end; |
|
567 | end; |
547 | end; |
568 | finally |
548 | finally |
569 | slSV.Free; |
549 | slSV.Free; |
570 | end; |
550 | end; |
571 | finally |
551 | finally |
572 | slIdNames.Free; |
552 | slIdNames.Free; |
573 | end; |
553 | end; |
574 | end; |
554 | end; |
575 | 555 | ||
576 | procedure TUD2.CheckTerm(idTermAndCmd: string; commandSLout: TStrings; slIdNames: TStrings=nil); |
556 | function TUD2.CheckTerm(idTermAndCmd: string; slIdNames: TStrings=nil): TUD2CommandArray; |
577 | var |
557 | var |
578 | nameVal: TArrayOfString; |
- | |
579 | idTerm, cmd: string; |
- | |
580 | slIdNamesCreated: boolean; |
558 | slIdNamesCreated: boolean; |
- | 559 | ent: TUD2TDFEntry; |
|
581 | begin |
560 | begin |
- | 561 | SetLength(result, 0); |
|
- | 562 | ||
582 | slIdNamesCreated := false; |
563 | slIdNamesCreated := false; |
583 | try |
564 | try |
584 | if not Assigned(slIdNames) then |
565 | if not Assigned(slIdNames) then |
585 | begin |
566 | begin |
586 | slIdNamesCreated := true; |
567 | slIdNamesCreated := true; |
587 | slIdNames := TStringList.Create; |
568 | slIdNames := TStringList.Create; |
588 | GetAllDetectedIDs(slIdNames); |
569 | GetAllDetectedIDs(slIdNames); |
589 | end; |
570 | end; |
590 | 571 | ||
591 | SetLength(nameVal, 0); |
- | |
592 | - | ||
593 | // We are doing the interpretation of the line ourselves, because |
572 | if not UD2P_ParseTdfLine(idTermAndCmd, ent) then Exit; |
594 | // TStringList.Values[] would not allow multiple command lines with the |
573 | if FulfilsEverySubterm(ent.ids, slIdNames) then |
595 | // same key (idTerm) |
574 | begin |
596 | // TODO xxx: big problem when we want to check environment variables, since our idTerm would contain '=' ! |
- | |
597 | nameVal := SplitString('=', idTermAndCmd); |
- | |
598 | if Length(nameVal) < 2 then exit; |
- | |
599 | idTerm := nameVal[0]; |
575 | result := ent.commands; |
600 | cmd := nameVal[1]; |
576 | end; |
601 | - | ||
602 | if FulfilsEverySubterm(idTerm, slIdNames) then commandSLout.Add(cmd); |
- | |
603 | finally |
577 | finally |
604 | if slIdNamesCreated then slIdNames.Free; |
578 | if slIdNamesCreated then slIdNames.Free; |
605 | end; |
579 | end; |
606 | end; |
580 | end; |
607 | 581 |