-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuMessagesLoader.pas
360 lines (314 loc) · 15.1 KB
/
uMessagesLoader.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
unit uMessagesLoader;
{******************************************************************************}
{* Messages Loader Unit *}
{* Revolutionary Confederation of Anarcho Syndicalists *}
{* Written by: black.rabbit 2011 *}
{******************************************************************************}
interface
{$I 'std.inc'}
uses
Windows, SysUtils, Variants, Classes, Graphics,
Controls, ComCtrls, CommCtrl, Forms, Gauges,
ImgList, acAlphaImageList, jpeg, pngimage, acPNG,
{ utils }
DateUtils, Utils, Strings, VarRecs, Versions, EClasses,
DllThreads,
{ kernel }
Kernel, ProtoClasses, CryptoClasses, MetaClasses, ParaClasses,
HypoClasses, HyperClasses,
{ engine }
Engine,
{ SQLite }
SQLite3, SQLite3DLL, SQLiteTable3;
type
{ çàãðóç÷èê ñîîáùåíèé }
{$M+}
CMessagesLoader = class of TMessagesLoader;
PMessagesLoader = ^TMessagesLoader;
TMessagesLoader = class (TDllThread)
private
f_DBFileName: String; { ôàéë áàçû äàííûõ }
f_DB: TSQLiteDatabase; { îáúåêò áàçû äàííûõ }
f_Box: TScrollingWinControl; { êîíòåéíåð }
f_Gauge: TGauge; { ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_StatusPanel: TStatusPanel; { ñòðîêà ñîñòîÿíèÿ çàãðóçêè }
f_CategorieID: TID; { êàòåãîðèÿ }
f_Messages: TMessages; { ñïèñîê ñîîáùåíèé }
f_MessageIndex: 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 Box: TScrollingWinControl read f_Box write f_Box;
property Gauge: TGauge read f_Gauge write f_Gauge;
property StatusPanel: TStatusPanel read f_StatusPanel write f_StatusPanel;
property CategorieID: TID read f_CategorieID write f_CategorieID;
property Messages: TMessages read f_Messages write f_Messages;
property MessageIndex: LongInt read f_MessageIndex write f_MessageIndex;
end;
{$M-}
{ TMessagesLoader Errors }
resourcestring
ERR_TMESSAGESLOADER_INCORRECT_DATABASE = 'Íå èíèöèàëèçèðîâàí îáúåêò ÁÄ!';
ERR_TMESSAGESLOADER_INCORRECT_BOX = 'Îáúåêò êîíòåéíåðà èíèöèàëèçèðîâàí!';
ERR_TMESSAGESLOADER_INCORRECT_NODE = 'Îáúåêò ñîäåðæèìîãî êîíòåéíåðà íå èíèöèàëèçèðîâàí!';
ERR_TMESSAGESLOADER_INCORRECT_ID = 'Óçåë äåðåâà ñîäåðæèò íåêîððåêòíûé èäåíòèôèêàòîð!';
ERR_TMESSAGESLOADER_INCORRECT_GAUGE = 'Íå èíèöèàëèçèðîâàí ýëåìåíò êîíòðîëÿ ïðîãðåññà!';
ERR_TMESSAGESLOADER_INCORRECT_STATUS_PANEL = 'Íå èíèöèàëèçèðîâàíà ñòðîêà ñîñòîÿíèÿ!';
ERR_TMESSAGESLOADER_CREATE = 'Îøèáêà ñîçäàíèÿ ïîòîêà çàãðóçêè ñïèñêà ñîîáùåíèé!';
ERR_TMESSAGESLOADER_DESTROY = 'Îøèáêà óíè÷òîæåíèÿ ïîòîêà çàãðóçêè ñïèñêà ñîîáùåíèé!';
ERR_TMESSAGESLOADER_MAIN = 'Îøèáêà ãëàâíîé ôóíêöèè ïîòîêà!';
ERR_TMESSAGESLOADER_RETURN = 'Îøèáêà ôóíêöèè âîçâðàòà ïîòîêà!';
ERR_TMESSAGESLOADER_IMAGE_LOAD_FAILED = 'Îøèáêà çàãðóçêè èçîáðàæåíèÿ: %s';
ERR_TMESSAGESLOADER_WRITE_STATUS = 'Îøèáêà îòîáðàæåíèÿ ñòàòóñà!';
{ TMessagesLoader Hints }
resourcestring
MSG_TMESSAGESLOADER_LOAD_OBJECT = 'Çàãðóçêà ''%s'' ...';
MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY = 'Çàãðóçêà ''%s'' ... %s';
implementation
uses
uTmpMessage;
{ TMessagesLoader }
constructor TMessagesLoader.Create (anArgs: array of const);
var
I : Integer;
args : array_of_const;
OBJ : TObject;
begin
try
{ ïåðåäàåì ïàðàìåòðû ñîçäàíèÿ áàçîâîãî ïîòîêà,
íà÷èíàÿ ñ øåñòîãî àðãóìåíòà }
if ( High (anArgs) >= 5 ) then
begin
SetLength ( Args, High (anArgs)-5 +1 );
for I := 5 to High (anArgs) do
args [I-5] := 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_TMESSAGESLOADER_INCORRECT_DATABASE);
{ âòîðîé ïàðàìåòð - Box
êîíòåéíåð, êóäà áóäóò çàãðóæàòüñÿ ñîîáùåíèÿ }
f_Box := NIL;
if notEmpty (1,anArgs) then
begin
OBJ := toObject (anArgs [1]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TScrollingWinControl) ) then
f_Box := TScrollingWinControl (OBJ);
end;
if ( not Assigned (f_Box) ) then
raise Exception.Create (ERR_TMESSAGESLOADER_INCORRECT_BOX);
{ òðåòèé ïàðàìåòð - CategorieID
èäåíòèôèêàòîð òåêóùåé êàòåãîðèè }
f_CategorieID := 0;
if notEmpty (2,anArgs) then
f_CategorieID := toInt64 (anArgs [2]);
if ( f_CategorieID <= 0 ) then
raise Exception.Create (ERR_TMESSAGESLOADER_INCORRECT_ID);
{ ÷åòâåðòûé ïàðàìåòð - Gauge
ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_Gauge := NIL;
if notEmpty (3,anArgs) then
begin
OBJ := toObject (anArgs [3]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TControl) ) then
f_Gauge := TGauge (OBJ);
end;
{if ( not Assigned (f_Gauge) ) then
raise Exception.Create (ERR_TMESSAGESLOADER_INCORRECT_GAUGE);}
{ ïÿòûé ïàðàìåòð - StatusPanel
ïîêàçàòåëü ïðîãðåññà çàãðóçêè }
f_StatusPanel := NIL;
if notEmpty (4,anArgs) then
begin
OBJ := toObject (anArgs [4]);
if ( Assigned (OBJ) and OBJ.InheritsFrom (TStatusPanel) ) then
f_StatusPanel := TStatusPanel (OBJ);
end;
{if ( not Assigned (f_StatusPanel) ) then
raise Exception.Create (ERR_TMESSAGESLOADER_INCORRECT_STATUS_PANEL);}
f_Messages := NIL;
f_MessageIndex := -1;
except on E: Exception do
_raise ([ 'Create', ERR_TMESSAGESLOADER_CREATE, E, Exception (FatalException) ],
['{8FB83F58-CE7A-417C-A19C-2F4B03B87FBA}']);
end;
end;
destructor TMessagesLoader.Destroy;
begin
try
FreeAndNil (f_Messages);
FreeAndNil (f_DB);
inherited Destroy;
except on E: Exception do
_raise ([ 'Destroy', ERR_TMESSAGESLOADER_DESTROY, E, Exception (FatalException) ],
['{F318EC71-1316-4319-ADC1-82F3AC1F17E1}']);
end;
end;
procedure TMessagesLoader.Main;
begin
try
if Terminated then Exit;
inherited Main;
if not Assigned (Messages) then
f_Messages := TMessages.Load (DB,[ _([]),
_([CategorieID]),
_([]),
_([USER_ID]),
_([MESSAGE_FORUM_TYPE_ID]),
_([MESSAGE_ACTIVE_STATUS_ID]) ],
[ _msg_time_stamp_create,
'DESC' ]) as TMessages;
except on E: Exception do
_raise ([ 'Main', ERR_TMESSAGESLOADER_MAIN, E, Exception (FatalException) ],
['{3AD44240-8FDC-408B-861B-2017F9B3C14D}']);
end;
end;
procedure TMessagesLoader.Return;
var
Node : TTmpMessage;
Bmp : TBitMap;
begin
try
if Terminated then Exit;
if ( not Assigned (Messages) or (Messages.Count <= 0) ) then
begin
SetTabStatus (tabForum,tbsLoaded);
Terminate;
end
else if MessageIndex >= Messages.Count-1 then
begin
SetTabStatus (tabForum,tbsLoaded);
Terminate;
end
else
try
inherited Return;
MessageIndex := MessageIndex + 1;
if Assigned (StatusPanel) then
StatusPanel.Text := Format (MSG_TMESSAGESLOADER_LOAD_OBJECT,
[ Messages.ItemAt [MessageIndex].Subject ]);
Node := TTmpMessage.Create (Box,MessageIndex);
with PMessageNode (Node.Data)^ do
begin
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id].Caption ]);
ID := Messages.ItemAt [MessageIndex].ID;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id_categorie].Caption ]);
IDCategorie := Messages.ItemAt [MessageIndex].IDCategorie;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id_author].Caption ]);
IDAuthor := Messages.ItemAt [MessageIndex].IDAuthor;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id_type].Caption ]);
IDType := Messages.ItemAt [MessageIndex].IDType;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id_status].Caption ]);
IDStatus := Messages.ItemAt [MessageIndex].IDStatus;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_id_pic].Caption ]);
IDPic := Messages.ItemAt [MessageIndex].IDPic;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_index_pic].Caption ]);
IndexPic := Messages.ItemAt [MessageIndex].IndexPic;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_subject].Caption ]);
Subject := Messages.ItemAt [MessageIndex].Subject;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_text].Caption ]);
CopyMemory ( Text, PChar (Messages.ItemAt [MessageIndex].Text), MAX_MESSAGE_LENGTH );
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].Author.PropAt [_usr_login].Caption ]);
Author := Messages.ItemAt [MessageIndex].Author.Login;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_time_stamp_create].Caption ]);
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_time_stamp_create].Caption ]);
TimeStampCreate := Messages.ItemAt [MessageIndex].TimeStampCreate;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_time_stamp_modify].Caption ]);
TimeStampModify := Messages.ItemAt [MessageIndex].TimeStampModify;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_time_stamp_public].Caption ]);
TimeStampPublic := Messages.ItemAt [MessageIndex].TimeStampPublic;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_key_hash].Caption ]);
KeyHash := Messages.ItemAt [MessageIndex].KeyHash;
//WriteStatus (MSG_TMESSAGESLOADER_LOAD_OBJECT_PROPERTY,
// [ Messages.ItemAt [MessageIndex].Subject,
// Messages.ItemAt [MessageIndex].PropAt [_msg_data_hash].Caption ]);
DataHash := Messages.ItemAt [MessageIndex].DataHash;
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_TMESSAGESLOADER_RETURN, E, Exception (FatalException) ],
['{E5E815D6-1923-453F-A98C-4D7EF74C0997}']);
end;
end;
procedure TMessagesLoader.WriteStatus (const aMessage: String);
begin
try
if Assigned (StatusPanel) then
begin
StatusPanel.Text := aMessage;
ProcessMessages;
end;
except on E: Exception do
_raise (['WriteStatus',ERR_TMESSAGESLOADER_WRITE_STATUS,E],
['{1D9CEE12-B437-4159-A763-F03790771B12}']);
end;
end;
procedure TMessagesLoader.WriteStatus (const aMessage: String;
aParams: array of const);
begin
try
WriteStatus ( Format (aMessage,aParams) );
except on E: Exception do
_raise (['WriteStatus',ERR_TMESSAGESLOADER_WRITE_STATUS,E],
['{85AFD790-ADF5-4AA9-B658-812FA8257E26}']);
end;
end;
end.