-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuKeyWordsLoader.pas
469 lines (403 loc) · 18.1 KB
/
uKeyWordsLoader.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
unit uKeyWordsLoader;
{******************************************************************************}
{* KeyWords Loader Unit *}
{* Revolutionary Confederation of Anarcho Syndicalists *}
{* Written by: black.rabbit 2012 *}
{******************************************************************************}
interface
{$I 'std.inc'}
uses
Windows, SysUtils, Variants, Classes,
Controls, ComCtrls, Gauges,
sTreeView,
{ utils }
DateUtils, Utils, Strings, VarRecs, Versions, EClasses,
DllThreads,
{ kernel }
Kernel, ProtoClasses, CryptoClasses, MetaClasses, ParaClasses,
HypoClasses, HyperClasses,
{ engine }
Engine,
{ SQLite }
SQLite3, SQLite3DLL, SQLiteTable3;
type
{ çàãðóç÷èê êëþ÷åâûõ ñëîâ }
{$M+}
CKeyWordsLoader = class of TKeyWordsLoader;
PKeyWordsLoader = ^TKeyWordsLoader;
TKeyWordsLoader = class (TDllThread)
private
f_DBFileName: String; { ôàéë áàçû äàííûõ }
f_DB: TSQLiteDatabase; { îáúåêò áàçû äàííûõ }
f_TreeNodes: TTreeNodes; { äåðåâî }
f_Gauge: TGauge; { ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_StatusPanel: TStatusPanel; { ñòðîêà ñîñòîÿíèÿ çàãðóçêè }
f_ParentNode: TTreeNode; { óçåë, ñîäåðæàùèé èäåíòèôèêàòîð ïðåäêà òåêóùåé êàòåãîðèè }
f_Words: TStringList; { êëþ÷åâûå ñëîâà }
f_KeyWords: TKeyWords; { ñïèñîê êëþ÷åâûõ ñëîâ }
f_KeyWordIndex: LongInt; { ïîçèöèÿ â îáõîäå ñïèñêà }
public
constructor Create (anArgs: array of const); override;
destructor Destroy; override;
public
procedure Main; override;
procedure Return; override;
protected
procedure WriteStatus (const aMessage: String); overload;
procedure WriteStatus (const aMessage: String;
aParams: array of const); overload;
public
property DBFileName: String read f_DBFileName;
property DB: TSQLiteDatabase read f_DB write f_DB;
property TreeNodes: TTreeNodes read f_TreeNodes write f_TreeNodes;
property Gauge: TGauge read f_Gauge write f_Gauge;
property StatusPanel: TStatusPanel read f_StatusPanel write f_StatusPanel;
property ParentNode: TTreeNode read f_ParentNode write f_ParentNode;
property Words: TStringList read f_Words write f_Words;
property KeyWords: TKeyWords read f_KeyWords write f_KeyWords;
property KeyWordIndex: LongInt read f_KeyWordIndex write f_KeyWordIndex;
end;
{$M-}
{ TKeyWordsLoader Errors }
resourcestring
ERR_TKEYWORDSLOADER_INCORRECT_DATABASE = 'Íå èíèöèàëèçèðîâàí îáúåêò ÁÄ!';
ERR_TKEYWORDSLOADER_INCORRECT_NODES = 'Îáúåêò äåðåâà íå èíèöèàëèçèðîâàí!';
ERR_TKEYWORDSLOADER_INCORRECT_NODE = 'Îáúåêò óçëà äåðåâà íå èíèöèàëèçèðîâàí!';
ERR_TKEYWORDSLOADER_INCORRECT_WORDS = 'Íåêîððåêòíûé ñïèñîê êëþ÷åâûõ ñëîâ!';
ERR_TKEYWORDSLOADER_INCORRECT_GAUGE = 'Íå èíèöèàëèçèðîâàí ýëåìåíò êîíòðîëÿ ïðîãðåññà!';
ERR_TKEYWORDSLOADER_INCORRECT_STATUS_PANEL = 'Íå èíèöèàëèçèðîâàíà ñòðîêà ñîñòîÿíèÿ!';
ERR_TKEYWORDSLOADER_CREATE = 'Îøèáêà ñîçäàíèÿ ïîòîêà çàãðóçêè äåðåâà êàòåãîðèé!';
ERR_TKEYWORDSLOADER_DESTROY = 'Îøèáêà óíè÷òîæåíèÿ ïîòîêà çàãðóçêè äåðåâà êàòåãîðèé!';
ERR_TKEYWORDSLOADER_MAIN = 'Îøèáêà ãëàâíîé ôóíêöèè ïîòîêà!';
ERR_TKEYWORDSLOADER_RETURN = 'Îøèáêà ôóíêöèè âîçâðàòà ïîòîêà!';
ERR_TKEYWORDSLOADER_WRITE_STATUS = 'Îøèáêà îòîáðàæåíèÿ ñòàòóñà!';
{ TKeyWordsLoader Hints }
resourcestring
MSG_TKEYWORDSLOADER_LOAD_OBJECT = 'Çàãðóçêà ''%s'' ...';
MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY = 'Çàãðóçêà ''%s'' ... %s';
implementation
{ TKeyWordsLoader }
constructor TKeyWordsLoader.Create (anArgs: array of const);
var
I : Integer;
args : array_of_const;
OBJ : TObject;
arr : array_of_const;
S : String;
begin
try
{ ïåðåäàåì ïàðàìåòðû ñîçäàíèÿ áàçîâîãî ïîòîêà,
íà÷èíàÿ ñ ñåäüìîãî àðãóìåíòà }
if ( High (anArgs) >= 6 ) then
begin
SetLength ( Args, High (anArgs)-6 +1 );
for I := 6 to High (anArgs) do
args [I-6] := anArgs [I];
end
else
args := _array_of_const ([]);
inherited Create (args);
{ ÿâíî óêàçûâàåì íà íåîáõîäèìîñòü óíè÷òîæåíèÿ ïîòîêà ïî îêîí÷àíèþ ðàáîòû }
FreeOnTerminate := TRUE;
{ èìÿ ïîòîêà }
Name := ClassName;
{ ïåðâûé ïàðàìåòð - ôàéë ÁÄ }
f_DBFileName := '';
f_DB := NIL;
if notEmpty (0,anArgs) then
begin
f_DBFileName := toString (anArgs [0]);
f_DB := TSQLiteDatabase.Create (f_DBFileName);
end;
if ( not Assigned (f_DB) ) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_DATABASE);
{ âòîðîé ïàðàìåòð - TreeNodes
äåðåâî, êóäà áóäóò çàãðóæàòüñÿ êàòåãîðèè }
f_TreeNodes := NIL;
if notEmpty (1,anArgs) then
begin
OBJ := toObject (anArgs [1]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TTreeNodes) ) then
f_TreeNodes := TTreeNodes (OBJ);
end;
if ( not Assigned (f_TreeNodes) ) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_NODES);
{ òðåòèé ïàðàìåòð - ParentNode
óçåë, ñîäåðæàùèé èäåíòèôèêàòîð ïðåäêà òåêóùåé êàòåãîðèè }
f_ParentNode := NIL;
if notEmpty (2,anArgs) then
begin
OBJ := toObject (anArgs [2]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TTreeNode) ) then
f_ParentNode := TTreeNode (OBJ);
end;
{if ( not Assigned (f_ParentNode) ) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_NODE);}
{ ÷åòâåðòûé ïàðàìåòð - Words
ñïèñîê êëþ÷åâûõ ñëîâ äëÿ ïîèñêà }
f_Words := TStringList.Create;
if notEmpty (3,anArgs) then
begin
{ ïàðàìåòð ïåðåäàí ñïèñêîì }
OBJ := toObject (anArgs [3]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TStringList) ) then
Words.Assign ( TStringList (OBJ) )
{ ïàðàìåòð ïåðåäàí ìàññèâîì }
else
begin
arr := toArrayOfConst (anArgs [3]);
for I := 0 to High (arr) do
begin
S := Trim ( toString (arr [I]) );
if notEmpty (S) then
try
Words.Add (S);
finally
_FillChar ( S, Length (S), $00 );
end;
end;
end;
end;
if not Assigned (Words) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_WORDS);
{ ïÿòûé ïàðàìåòð - Gauge
ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_Gauge := NIL;
if notEmpty (4,anArgs) then
begin
OBJ := toObject (anArgs [4]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TControl) ) then
f_Gauge := TGauge (OBJ);
end;
{if ( not Assigned (f_Gauge) ) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_GAUGE);}
{ øåñòîé ïàðàìåòð - StatusPanel
ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_StatusPanel := NIL;
if notEmpty (5,anArgs) then
begin
OBJ := toObject (anArgs [5]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TStatusPanel) ) then
f_StatusPanel := TStatusPanel (OBJ);
end;
{if ( not Assigned (f_StatusPanel) ) then
raise Exception.Create (ERR_TKEYWORDSLOADER_INCORRECT_STATUS_PANEL);}
f_KeyWords := NIL;
f_KeyWordIndex := -1;
except on E: Exception do
_raise ([ 'Create', ERR_TKEYWORDSLOADER_CREATE, E, Exception (FatalException) ],
['{111C0FF1-7B56-4AE4-BA0A-226A4F2BD82F}']);
end;
end;
destructor TKeyWordsLoader.Destroy;
begin
try
FreeAndNil (f_KeyWords);
FreeAndNil (f_Words);
FreeAndNil (f_DB);
inherited Destroy;
except on E: Exception do
_raise ([ 'Destroy', ERR_TKEYWORDSLOADER_DESTROY, E, Exception (FatalException) ],
['{DE614587-EE9D-4DD2-AF4B-0F5BE575F621}']);
end;
end;
procedure TKeyWordsLoader.Main;
begin
try
if Terminated then Exit;
inherited Main;
if ( Words.Count <= 0 ) then
Terminate
else if not Assigned (KeyWords) then
f_KeyWords := TKeyWords.Load (DB,[ _([]),
Words,
_([]),
_([]),
_([]),
_([USER_ID]) ]) as TKeyWords;
except on E: Exception do
_raise ([ 'Main', ERR_TKEYWORDSLOADER_MAIN, E, Exception (FatalException) ],
['{C95C4BE0-3BD6-40CE-8180-A6EF6D64DDA5}']);
end;
end;
procedure TKeyWordsLoader.Return;
var
Ctg : TCategorie;
Msg : TMessage;
Node : TTreeNode;
P : Integer;
begin
try
if Terminated then Exit;
if ( not Assigned (KeyWords) or (KeyWords.Count <= 0) ) then
begin
SetTabStatus (tabForum,tbsLoaded);
Terminate;
end
else if KeyWordIndex >= KeyWords.Count-1 then
begin
SetTabStatus (tabUsers,tbsLoaded);
Terminate;
end
else
try
inherited Return;
KeyWordIndex := KeyWordIndex + 1;
Ctg := NIL;
if ( KeyWords.ItemAt [KeyWordIndex].IDCategorie > 0 ) then
Ctg := TCategorie.Load ( DB, KeyWords.ItemAt [KeyWordIndex].IDCategorie ) as TCategorie;
if ( KeyWords.ItemAt [KeyWordIndex].IDMessage > 0 ) then
begin
Msg := TMessage.Load ( DB, KeyWords.ItemAt [KeyWordIndex].IDMessage ) as TMessage;
if not Assigned (Ctg) then
Ctg := TCategorie.Load ( DB, Msg.IDCategorie ) as TCategorie;
end;
try
if Assigned (Ctg) then
begin
if Assigned (StatusPanel) then
StatusPanel.Text := Format (MSG_TKEYWORDSLOADER_LOAD_OBJECT,
[ Ctg.Name ]);
Node := TreeNodes.AddChild ( ParentNode,
{Format (' %s '#13#10' %s ',
[ Ctg.Name,
Ctg.Description ])}
'' );
Node.ImageIndex := Ctg.IndexPic*4 + 0;
Node.Data := CreateCategorieNode;
with PCategorieNode (Node.Data)^ do
begin
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id].Caption ]);
ID := Ctg.ID;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id_parent].Caption ]);
IDParent := Ctg.IDparent;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id_author].Caption ]);
IDAuthor := Ctg.IDAuthor;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id_type].Caption ]);
IDType := Ctg.IDType;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id_status].Caption ]);
IDStatus := Ctg.IDStatus;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_id_pic].Caption ]);
IDPic := Ctg.IDPic;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_index_pic].Caption ]);
IndexPic := Ctg.IndexPic;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_name].Caption ]);
Name := Ctg.Name;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_description].Caption ]);
Description := Ctg.Description;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.Author.PropAt [_usr_login].Caption ]);
Author := Ctg.Author.Login;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_time_stamp_create].Caption ]);
TimeStampCreate := Ctg.TimeStampCreate;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_time_stamp_modify].Caption ]);
TimeStampModify := Ctg.TimeStampModify;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_time_stamp_public].Caption ]);
TimeStampPublic := Ctg.TimeStampPublic;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_key_hash].Caption ]);
KeyHash := Ctg.KeyHash;
//WriteStatus (MSG_TKEYWORDSLOADER_LOAD_OBJECT_PROPERTY,
// [ Ctg.Name,
// Ctg.PropAt [_ctg_data_hash].Caption ]);
DataHash := Ctg.DataHash;
end;
end;
if Assigned (Ctg) and Assigned (Msg) then
begin
if Assigned (StatusPanel) then
StatusPanel.Text := Format (MSG_TKEYWORDSLOADER_LOAD_OBJECT,
[ Msg.Subject ]);
Node := TreeNodes.AddChild ( Node, '' );
Node.ImageIndex := TsTreeView (TreeNodes.Owner).Images.Count - 1;
Node.Data := CreateCategorieNode;
with PCategorieNode (Node.Data)^ do
begin
isMessage := TRUE;
ID := 0;
IDParent := 0;
IDAuthor := Msg.IDAuthor;
IDType := 0;
IDStatus := 0;
IDPic := 0;
IndexPic := -1;
Name := Msg.Subject;
P := Pos ( KeyWords.ItemAt [KeyWordIndex].KeyWord, Msg.Text );
if ( P > 32 ) then
Description := Format ('...%s...',[ Copy (Msg.Text,P-32,64) ])
else
Description := Format ('%s...',[ Copy (Msg.Text,1,64) ]);
Author := Msg.Author.Login;
TimeStampCreate := Msg.TimeStampCreate;
TimeStampModify := Msg.TimeStampModify;
TimeStampPublic := Msg.TimeStampPublic;
KeyHash := Msg.KeyHash;
DataHash := Msg.DataHash;
end;
//Node.Parent.Expand (FALSE);
end;
finally
FreeAndNil (Msg);
FreeAndNil (Ctg);
end;
{ ïðîãðåññ }
if Assigned (Gauge) then
Gauge.Progress := Gauge.Progress + 1;
except on E: Exception do
WriteStatus (E.Message);
end;
except on E: Exception do
_raise ([ 'Return', ERR_TKEYWORDSLOADER_RETURN, E, Exception (FatalException) ],
['{5B0D7C1C-1D0C-4788-932F-15EA24F9E012}']);
end;
end;
procedure TKeyWordsLoader.WriteStatus (const aMessage: String);
begin
try
if Assigned (StatusPanel) then
begin
StatusPanel.Text := aMessage;
ProcessMessages;
end;
except on E: Exception do
_raise (['WriteStatus',ERR_TKEYWORDSLOADER_WRITE_STATUS,E],
['{C4084910-5044-4A59-9ED5-FA13130A5256}']);
end;
end;
procedure TKeyWordsLoader.WriteStatus (const aMessage: String;
aParams: array of const);
begin
try
WriteStatus ( Format (aMessage,aParams) );
except on E: Exception do
_raise (['WriteStatus',ERR_TKEYWORDSLOADER_WRITE_STATUS,E],
['{C1F578AA-6DE7-493B-A55A-F922BBF81F05}']);
end;
end;
end.