Rev 84 | Rev 87 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 84 | Rev 85 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | uses |
5 | uses |
6 | Windows, SysUtils; |
6 | Windows, SysUtils; |
7 | 7 | ||
8 | // TODO: use this for better object oriented programming |
8 | // TODO: use this for better object oriented programming |
9 | 9 | ||
- | 10 | // TODO : WideStrings idName: WideString; ??? |
|
- | 11 | ||
- | 12 | const |
|
- | 13 | // Prefixes for UD2_RunCmd() |
|
- | 14 | UD2_RUN_IN_OWN_DIRECTORY_PREFIX = '$RIOD$'; |
|
- | 15 | UD2_RUN_AS_ADMIN = '$ADMIN$'; |
|
- | 16 | ||
10 | type |
17 | type |
11 | TUD2Command = record |
18 | TUD2Command = record |
12 | executable: string; |
19 | executable: string; |
13 | runAsAdmin: boolean; |
20 | runAsAdmin: boolean; |
14 | runInOwnDirectory: boolean; |
21 | runInOwnDirectory: boolean; |
Line 29... | Line 36... | ||
29 | ids: TUD2TDFConditionArray; |
36 | ids: TUD2TDFConditionArray; |
30 | commands: TUD2CommandArray; |
37 | commands: TUD2CommandArray; |
31 | end; |
38 | end; |
32 | TUD2TDFEntryArray = array of TUD2TDFEntry; |
39 | TUD2TDFEntryArray = array of TUD2TDFEntry; |
33 | 40 | ||
- | 41 | // Split |
|
- | 42 | function UD2P_ParseConditions(idTerm: string): TUD2TDFConditionArray; |
|
- | 43 | function UD2P_ParseTdfLine(idTermAndCmd: string; var entry: TUD2TDFEntry): boolean; |
|
- | 44 | function UD2P_DecodeCommand(line: string): TUD2Command; |
|
- | 45 | function UD2P_DecodeCondition(idName: string; var cond: TUD2TDFCondition): boolean; |
|
- | 46 | ||
- | 47 | // Merge |
|
- | 48 | function UD2_CondToStr(cond: TUD2TDFCondition): string; |
|
- | 49 | function UD2_CondsToStr(conds: TUD2TDFConditionArray): string; |
|
- | 50 | ||
34 | implementation |
51 | implementation |
35 | 52 | ||
36 | uses |
53 | uses |
37 | UD2_Utils; |
54 | UD2_Utils; |
38 | 55 | ||
39 | function ParseTdfLine(line: string; var entry: TUD2TDFEntry): boolean; |
56 | function UD2_CondsToStr(conds: TUD2TDFConditionArray): string; |
- | 57 | var |
|
- | 58 | i: integer; |
|
- | 59 | begin |
|
- | 60 | result := ''; |
|
- | 61 | for i := Low(conds) to High(conds) do |
|
40 | begin |
62 | begin |
- | 63 | if result <> '' then result := result + '&&'; |
|
- | 64 | result := result + UD2_CondToStr(conds[i]); |
|
41 | // TODO: xxxxx |
65 | end; |
- | 66 | end; |
|
42 | 67 | ||
- | 68 | function UD2_CondToStr(cond: TUD2TDFCondition): string; |
|
43 | (* |
69 | begin |
44 | entry.idName: string; |
70 | if cond.dynamicDataUsed then |
45 | entry.idValue: string; |
71 | begin |
46 | entry.dynamicDataUsed: Boolean; |
72 | result := cond.idMethodName+'('+cond.dynamicData+'):'+cond.idStr; |
47 | entry.dynamicData: string; |
73 | end |
- | 74 | else |
|
48 | entry.caseSensitive: boolean; |
75 | begin |
49 | entry.commands: TUD2CommandArray; |
76 | result := cond.idMethodName+':'+cond.idStr; |
50 | *) |
77 | end; |
- | 78 | end; |
|
51 | 79 | ||
- | 80 | function UD2P_DecodeCommand(line: string): TUD2Command; |
|
- | 81 | begin |
|
- | 82 | result.runAsAdmin := Pos(UD2_RUN_AS_ADMIN, line) >= 1; |
|
52 | // ReadSectionValues |
83 | if result.runAsAdmin then |
- | 84 | begin |
|
- | 85 | line := StringReplace(line, UD2_RUN_AS_ADMIN, '', [rfReplaceAll]); |
|
- | 86 | end; |
|
53 | 87 | ||
- | 88 | result.runInOwnDirectory := Pos(UD2_RUN_IN_OWN_DIRECTORY_PREFIX, line) >= 1; |
|
- | 89 | if result.runInOwnDirectory then |
|
- | 90 | begin |
|
- | 91 | line := StringReplace(line, UD2_RUN_IN_OWN_DIRECTORY_PREFIX, '', [rfReplaceAll]); |
|
- | 92 | end; |
|
54 | 93 | ||
55 | (* |
- | |
56 | nameVal := SplitString('=', idTermAndCmd); |
- | |
57 | if Length(nameVal) < 2 then exit; |
- | |
58 | idTerm := nameVal[0]; |
94 | result.executable := line; |
59 | cmd := nameVal[1]; |
95 | result.WindowMode := SW_NORMAL; // TODO (future): make it configurable |
60 | *) |
- | |
61 | end; |
96 | end; |
62 | 97 | ||
63 | function ParseCommandLine(line: string; var cmd: TUD2Command): boolean; |
98 | function UD2P_DecodeCondition(idName: string; var cond: TUD2TDFCondition): boolean; |
- | 99 | const |
|
- | 100 | CASE_SENSITIVE_FLAG = '$CASESENSITIVE$'; |
|
- | 101 | var |
|
- | 102 | a, b: TArrayOfString; |
|
64 | begin |
103 | begin |
- | 104 | result := false; |
|
- | 105 | ||
- | 106 | cond.caseSensitive := Pos(CASE_SENSITIVE_FLAG, idName) >= 1; |
|
65 | if Pos(UD2_RUN_AS_ADMIN, line) >= 1 then |
107 | if cond.caseSensitive then |
66 | begin |
108 | begin |
67 | line := StringReplace(line, UD2_RUN_AS_ADMIN, '', [rfReplaceAll]); |
109 | idName := StringReplace(idName, CASE_SENSITIVE_FLAG, '', [rfReplaceAll]); |
68 | cmd.runAsAdmin := true; |
- | |
69 | end |
110 | end; |
70 | else cmd.runAsAdmin := false; |
- | |
71 | 111 | ||
- | 112 | /// --- Start Dynamic Extension |
|
- | 113 | // xxxxxx ( xxxxx ): xxxxxxxxxxxx |
|
- | 114 | // xxxxx ( xx:xx ): xxxxx:xxx(x) |
|
- | 115 | // xxxxxxxxxxxx : xxxxx(xxx)xx |
|
- | 116 | ||
- | 117 | SetLength(a, 0); |
|
- | 118 | a := SplitString('(', idName); |
|
72 | if Pos(UD2_RUN_IN_OWN_DIRECTORY_PREFIX, line) >= 1 then |
119 | if (Length(a) >= 2) and (Pos(':', a[0]) = 0) then |
73 | begin |
120 | begin |
- | 121 | SetLength(b, 0); |
|
74 | line := StringReplace(line, UD2_RUN_IN_OWN_DIRECTORY_PREFIX, '', [rfReplaceAll]); |
122 | b := SplitString('):', a[1]); |
- | 123 | if Length(b) >= 2 then |
|
- | 124 | begin |
|
- | 125 | cond.idMethodName := a[0]; |
|
- | 126 | cond.idStr := b[1]; |
|
75 | cmd.runInOwnDirectory := true; |
127 | cond.dynamicDataUsed := true; |
- | 128 | cond.dynamicData := b[0]; |
|
- | 129 | result := true; |
|
- | 130 | Exit; |
|
- | 131 | end; |
|
76 | end |
132 | end; |
- | 133 | /// --- End Dynamic Extension |
|
- | 134 | ||
- | 135 | if not result then |
|
- | 136 | begin |
|
- | 137 | a := SplitString(':', idName); |
|
- | 138 | if Length(a) >= 2 then |
|
- | 139 | begin |
|
- | 140 | cond.idMethodName := a[0]; |
|
- | 141 | cond.idStr := a[1]; |
|
77 | else cmd.runInOwnDirectory := false; |
142 | cond.dynamicDataUsed := false; |
- | 143 | cond.dynamicData := ''; |
|
- | 144 | result := true; |
|
- | 145 | Exit; |
|
- | 146 | end; |
|
- | 147 | end; |
|
- | 148 | end; |
|
- | 149 | ||
- | 150 | function UD2P_ParseConditions(idTerm: string): TUD2TDFConditionArray; |
|
- | 151 | var |
|
- | 152 | cond: TUD2TDFCondition; |
|
- | 153 | x: TArrayOfString; |
|
- | 154 | i, l: integer; |
|
- | 155 | idName: string; |
|
- | 156 | begin |
|
- | 157 | SetLength(x, 0); |
|
- | 158 | x := SplitString('&&', idTerm); |
|
- | 159 | SetLength(result, 0); |
|
- | 160 | for i := Low(x) to High(x) do |
|
- | 161 | begin |
|
- | 162 | idName := x[i]; |
|
- | 163 | if UD2P_DecodeCondition(idName, cond) then |
|
- | 164 | begin |
|
- | 165 | l := Length(result); |
|
- | 166 | SetLength(result, l+1); |
|
- | 167 | result[l] := cond; |
|
- | 168 | end; |
|
- | 169 | end; |
|
- | 170 | end; |
|
- | 171 | ||
- | 172 | function UD2P_ParseTdfLine(idTermAndCmd: string; var entry: TUD2TDFEntry): boolean; |
|
- | 173 | var |
|
- | 174 | nameVal: TArrayOfString; |
|
- | 175 | idTerm, cmd: string; |
|
- | 176 | begin |
|
- | 177 | result := false; |
|
- | 178 | ||
- | 179 | // Split conditions and command |
|
- | 180 | nameVal := SplitString('=', idTermAndCmd); // TODO: problem... "=" could be inside dynamicData... |
|
- | 181 | if Length(nameVal) < 2 then exit; |
|
- | 182 | idTerm := nameVal[0]; |
|
- | 183 | cmd := nameVal[1]; |
|
78 | 184 | ||
79 | cmd.executable := line; |
185 | // Decode conditions |
- | 186 | entry.ids := UD2P_ParseConditions(idTerm); |
|
80 | 187 | ||
- | 188 | // Decode command |
|
- | 189 | SetLength(entry.commands, 1); |
|
81 | cmd.windowMode := SW_NORMAL; // TODO (future): make it configurable |
190 | entry.commands[0] := UD2P_DecodeCommand(cmd); |
82 | 191 | ||
83 | result := true; |
192 | result := true; |
84 | end; |
193 | end; |
85 | 194 | ||
86 | end. |
195 | end. |