Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/ItemDownload.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.28 - (hide annotations) (download) (as text)
Tue Jun 29 15:31:28 2004 UTC (19 years, 9 months ago) by h677
Branch: MAIN
CVS Tags: v1_48_0_510
Changes since 1.27: +7 -2 lines
File MIME type: text/x-pascal
pluginの外部BBSでの中断処理が正しく作動するように修正

1 hi_ 1.1 unit ItemDownload;
2    
3     interface
4    
5     uses
6 yoffy 1.7 Windows, SysUtils, Classes, ComCtrls, Controls, Forms, IdHTTP,
7 yoffy 1.2 {HTTPApp,} YofUtils, IdGlobal, IdException, IdComponent, IniFiles, {DateUtils,}
8 h677 1.28 GikoSystem, BoardGroup, MonaUtils, ExternalBoardManager, ExternalBoardPlugInMain;
9 hi_ 1.1
10     type
11     TDownloadItem = class;
12     TGikoDownloadType = (gdtBoard, gdtThread);
13     TGikoDownloadState = (gdsWait, gdsWork, gdsComplete, gdsDiffComplete, gdsNotModify, gdsAbort, gdsError);
14     TGikoCgiStatus = (gcsOK, gcsINCR, gcsERR);
15     TGikoDLProgress = (gdpStd, gdpAll, gdpDatOchi, gdpOfflaw);
16    
17     TGikoWorkEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer; ID: Integer) of object;
18 q9_ 1.23 TGikoWorkBeginEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer; ID: Integer; const AWorkTitle: string) of object;
19 hi_ 1.1 TGikoWorkEndEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; ID: Integer) of object;
20     TDownloadEndEvent = procedure(Sender: TObject; Item: TDownloadItem) of object;
21     TDownloadMsgEvent = procedure(Sender: TObject; Item: TDownloadItem; Msg: string; Icon: TGikoMessageIcon) of object;
22    
23     TCgiStatus = record
24     FStatus: TGikoCgiStatus;
25     FSize: Integer;
26     FErrText: string;
27     end;
28    
29    
30     TDownloadThread = class(TThread)
31     private
32     FIndy: TIdHttp;
33     FItem: TDownloadItem;
34     FNumber: Integer;
35     FAbort: Boolean;
36     FMsg: string;
37     FIcon: TGikoMessageIcon;
38     FSessionID: string;
39     FOnWork: TGikoWorkEvent;
40     FOnWorkBegin: TGikoWorkBeginEvent;
41     FOnWorkEnd: TGikoWorkEndEvent;
42     FOnDownloadEnd: TDownloadEndEvent;
43     FOnDownloadMsg: TDownloadMsgEvent;
44 q9_ 1.23 FDownloadTitle: string;
45 hi_ 1.1
46     procedure FireDownloadEnd;
47     procedure FireDownloadMsg;
48     procedure GetSessionID;
49     procedure WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer);
50     procedure WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
51     procedure Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
52     function ParseCgiStatus(Content: string): TCgiStatus;
53 yoffy 1.13 function CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean;
54 hi_ 1.1 function DatDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime; RangeStart: Integer; AdjustLen: Integer): Boolean;
55     function DeleteStatusLine(Content: string): string;
56     protected
57     procedure Execute; override;
58     public
59     property Item: TDownloadItem read FItem write FItem;
60     property Number: Integer read FNumber write FNumber;
61     constructor Create(CreateSuspended: Boolean);
62 h677 1.22 destructor Destroy; override;
63 hi_ 1.1 procedure Abort;
64     property OnWork: TGikoWorkEvent read FOnWork write FOnWork;
65     property OnWorkBegin: TGikoWorkBeginEvent read FOnWorkBegin write FOnWorkBegin;
66     property OnWorkEnd: TGikoWorkEndEvent read FOnWorkEnd write FOnWorkEnd;
67     property OnDownloadEnd: TDownloadEndEvent read FOnDownloadEnd write FOnDownloadEnd;
68     property OnDownloadMsg: TDownloadMsgEvent read FOnDownloadMsg write FOnDownloadMsg;
69     end;
70    
71     TDownloadItem = class(TObject)
72     private
73     FDownType: TGikoDownloadType;
74     FBoard: TBoard;
75     FThreadItem: TThreadItem;
76    
77     FContentLength: Integer;
78     FLastModified: TDateTime;
79     FContent: string;
80     FResponseCode: Smallint;
81     FState: TGikoDownloadState;
82     FErrText: string;
83 q9_ 1.25 FForceDownload: Boolean;
84 hi_ 1.1 public
85     procedure SaveListFile;
86     procedure SaveItemFile;
87    
88     property DownType: TGikoDownloadType read FDownType write FDownType;
89     property Board: TBoard read FBoard write FBoard;
90     property ThreadItem: TThreadItem read FThreadItem write FThreadItem;
91    
92     property ContentLength: Integer read FContentLength write FContentLength;
93     property LastModified: TDateTime read FLastModified write FLastModified;
94     property Content: string read FContent write FContent;
95     property ResponseCode: Smallint read FResponseCode write FResponseCode;
96     property State: TGikoDownloadState read FState write FState;
97     property ErrText: string read FErrText write FErrText;
98 q9_ 1.25 property ForceDownload: Boolean read FForceDownload write FForceDownload;
99 hi_ 1.1 end;
100    
101     implementation
102    
103     constructor TDownloadThread.Create(CreateSuspended: Boolean);
104     begin
105     inherited Create(CreateSuspended);
106     FIndy := TIdHttp.Create(nil);
107    
108     FIndy.OnWorkBegin := WorkBegin;
109     FIndy.OnWorkEnd := WorkEnd;
110     FIndy.OnWork := Work;
111     end;
112    
113     destructor TDownloadThread.Destroy;
114     begin
115 h677 1.22 FIndy.Request.CustomHeaders.Clear;
116     FIndy.Request.RawHeaders.Clear;
117     FIndy.Request.Clear;
118     FIndy.Response.CustomHeaders.Clear;
119     FIndy.Response.RawHeaders.Clear;
120     FIndy.Response.Clear;
121     FIndy.ProxyParams.Clear;
122 hi_ 1.1 FIndy.Free;
123     inherited;
124     end;
125    
126     function RFC1123_Date(aDate : TDateTime) : String;
127     const
128     StrWeekDay : String = 'MonTueWedThuFriSatSun';
129 yoffy 1.13 StrMonth : String = 'JanFebMarAprMayJunJulAugSepOctNovDec';
130 hi_ 1.1 var
131 yoffy 1.13 Year, Month, Day : Word;
132     Hour, Min, Sec, MSec : Word;
133     DayOfWeek : Word;
134 hi_ 1.1 begin
135     DecodeDate(aDate, Year, Month, Day);
136 yoffy 1.13 DecodeTime(aDate, Hour, Min, Sec, MSec);
137 hi_ 1.1 DayOfWeek := ((Trunc(aDate) - 2) mod 7);
138     Result := Copy(StrWeekDay, 1 + DayOfWeek * 3, 3) + ', ' +
139     Format('%2.2d %s %4.4d %2.2d:%2.2d:%2.2d',
140     [Day, Copy(StrMonth, 1 + 3 * (Month - 1), 3),
141     Year, Hour, Min, Sec]);
142     end;
143    
144     procedure TDownloadThread.Execute;
145     var
146     ResStream: TMemoryStream;
147    
148     URL: string;
149     CgiStatus: TCgiStatus;
150     Modified: TDateTime;
151     RangeStart: Integer;
152     AdjustLen: Integer;
153     Idx: Integer;
154     ATitle: string;
155     DownloadResult: Boolean;
156     Abone: Boolean;
157 yoffy 1.13 foundPos: Integer;
158     boardPlugIn : TBoardPlugIn;
159     listContent : string;
160 hi_ 1.1 begin
161     while not Terminated do begin
162 yoffy 1.9 //===== 鐃?鐃緒申鐃?鐃?鐃緒申
163 h677 1.28 FAbort := False;
164 yoffy 1.13 boardPlugIn := nil;
165     ExternalBoardManager.OnWork := Work;
166     ExternalBoardManager.OnWorkBegin := WorkBegin;
167     ExternalBoardManager.OnWorkEnd := WorkEnd;
168    
169 q9_ 1.23 FDownloadTitle := '';
170 yoffy 1.13 case FItem.FDownType of
171     gdtBoard:
172     begin
173 q9_ 1.23 FDownloadTitle := FItem.FBoard.Title;
174 yoffy 1.13 if FItem.FBoard <> nil then begin
175     if FItem.FBoard.IsBoardPlugInAvailable then begin
176     boardPlugIn := FItem.FBoard.BoardPlugIn;
177     Item.State := TGikoDownloadState( boardPlugIn.DownloadBoard( DWORD( FItem.FBoard ) ) );
178     end;
179     end;
180     end;
181     gdtThread:
182     begin
183 q9_ 1.23 FDownloadTitle := FItem.FThreadItem.Title;
184 yoffy 1.13 if FItem.FThreadItem <> nil then begin
185     if FItem.FThreadItem.IsBoardPlugInAvailable then begin
186     boardPlugIn := FItem.FThreadItem.BoardPlugIn;
187     Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) );
188     end;
189     end;
190     end;
191     end;
192 q9_ 1.23 if Length(FDownloadTitle) = 0 then
193     FDownloadTitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
194 yoffy 1.13
195     if boardPlugIn <> nil then begin
196 h677 1.28 if FAbort then begin
197 yoffy 1.13 Item.State := gdsAbort;
198 h677 1.28 end;
199 yoffy 1.13 if Assigned( OnDownloadEnd ) then
200     Synchronize( FireDownloadEnd );
201     if Terminated then
202     Break;
203    
204     Suspend;
205     Continue;
206     end;
207 yoffy 1.9
208     //===== 鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
209 hi_ 1.1 FAbort := False;
210     FIndy.Request.CustomHeaders.Clear;
211     FIndy.Response.Clear;
212     FIndy.Request.Clear;
213 yoffy 1.14 FIndy.ProxyParams.Clear;
214     FIndy.Disconnect;
215 hi_ 1.1 FIndy.Request.UserAgent := GikoSys.GetUserAgent;
216     FIndy.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
217     FIndy.ProxyParams.BasicAuthentication := False;
218     {$IFDEF DEBUG}
219     Writeln('------------------------------------------------------------');
220     {$ENDIF}
221     //FIndy.AllowCookies := False;
222     if GikoSys.Setting.ReadProxy then begin
223     if GikoSys.Setting.ProxyProtocol then
224     FIndy.ProtocolVersion := pv1_1
225     else
226     FIndy.ProtocolVersion := pv1_0;
227     FIndy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
228     FIndy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
229     FIndy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
230     FIndy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
231     if GikoSys.Setting.ReadProxyUserID <> '' then
232     FIndy.ProxyParams.BasicAuthentication := True;
233     {$IFDEF DEBUG}
234     Writeln('鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申');
235     Writeln('鐃?鐃?鐃?: ' + GikoSys.Setting.ReadProxyAddress);
236     Writeln('鐃?鐃?鐃?: ' + IntToStr(GikoSys.Setting.ReadProxyPort));
237     {$ENDIF}
238     end else begin
239     if GikoSys.Setting.Protocol then
240     FIndy.ProtocolVersion := pv1_1
241     else
242     FIndy.ProtocolVersion := pv1_0;
243     FIndy.ProxyParams.ProxyServer := '';
244     FIndy.ProxyParams.ProxyPort := 80;
245     FIndy.ProxyParams.ProxyUsername := '';
246     FIndy.ProxyParams.ProxyPassword := '';
247     {$IFDEF DEBUG}
248     Writeln('鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申');
249     {$ENDIF}
250     end;
251    
252     FIndy.Request.ContentRangeStart := 0;
253     FIndy.Request.LastModified := ZERO_DATE;
254     ResStream := TMemoryStream.Create;
255     try
256     try
257     //********************
258     //DAT or Subject鐃緒申鐃緒申
259     //********************
260     Item.ResponseCode := 0;
261     RangeStart := 0;
262     AdjustLen := 0;
263     Modified := 0;
264     if Item.DownType = gdtBoard then begin
265     {$IFDEF DEBUG}
266     Writeln('Subject鐃緒申鐃緒申');
267     Writeln('URL: ' + Item.Board.GetReadCgiURL);
268     Writeln('Modified: ' + FloatToStr(Item.Board.LastModified));
269     {$ENDIF}
270     URL := Item.Board.GetReadCgiURL;
271 q9_ 1.25 if Item.ForceDownload then begin
272     // 鐃緒申鐃緒申鐃緒申鐃緒申
273     ATitle := Item.Board.Title;
274     if ATitle = '' then
275     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
276     FMsg := '鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
277     FIcon := gmiWhat;
278     if Assigned(OnDownloadMsg) then
279     Synchronize(FireDownloadMsg);
280     Modified := ZERO_DATE
281     end else begin
282     Modified := Item.Board.LastModified;
283     end;
284 hi_ 1.1 end else if Item.DownType = gdtThread then begin
285     {$IFDEF DEBUG}
286     Writeln('DAT鐃緒申鐃緒申');
287     Writeln('URL: ' + Item.ThreadItem.GetDatURL);
288     Writeln('Modified: ' + FloatToStr(Item.ThreadItem.LastModified));
289     {$ENDIF}
290     URL := Item.ThreadItem.GetDatURL;
291 q9_ 1.25 if Item.ForceDownload then begin
292     // 鐃緒申鐃緒申鐃緒申鐃緒申
293     ATitle := Item.ThreadItem.Title;
294     if ATitle = '' then
295     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
296     FMsg := '鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
297     FIcon := gmiWhat;
298     if FileExists(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG')) = true then
299     DeleteFile(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG'));
300     if Assigned(OnDownloadMsg) then
301     Synchronize(FireDownloadMsg);
302     Modified := ZERO_DATE;
303     RangeStart := 0;
304     AdjustLen := 0;
305     end else begin
306     Modified := Item.ThreadItem.LastModified;
307     if Item.ThreadItem.Size > 0 then begin
308     {$IFDEF DEBUG}
309     Writeln('RangeStart: ' + IntToStr(Item.ThreadItem.Size));
310     {$ENDIF}
311     //鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申
312     RangeStart := Item.ThreadItem.Size;
313     AdjustLen := -1;
314     end;
315 hi_ 1.1 end;
316     end;
317     Abone := False;
318     DownloadResult := DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen);
319     {$IFDEF DEBUG}
320     Writeln('ResponseCode: ' + IntToStr(FIndy.ResponseCode));
321     {$ENDIF}
322     if Item.DownType = gdtThread then begin
323     if Item.ResponseCode = 416 then begin
324     Abone := True;
325     DownloadResult := True;
326     end else if DownloadResult and (AdjustLen = -1) and (Item.Content[1] <> #10) then
327     Abone := True;
328     end;
329    
330     if Trim(FIndy.Response.RawHeaders.Values['Date']) <> '' then begin
331     if Item.DownType = gdtBoard then
332     Item.Board.LastGetTime := MonaUtils.DateStrToDateTime(FIndy.Response.RawHeaders.Values['Date'])
333     else
334     Item.ThreadItem.ParentBoard.LastGetTime := MonaUtils.DateStrToDateTime(FIndy.Response.RawHeaders.Values['Date']);
335     end;
336    
337     if DownloadResult then begin
338     {$IFDEF DEBUG}
339     Writeln('Date:' + FIndy.Response.RawHeaders.Values['Date']);
340     {$ENDIF}
341     if Abone then begin
342     {$IFDEF DEBUG}
343     Writeln('鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?');
344     {$ENDIF}
345     ATitle := Item.ThreadItem.Title;
346     if ATitle = '' then
347     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
348     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
349     RangeStart := 0;
350     AdjustLen := 0;
351     FMsg := '鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
352     FIcon := gmiWhat;
353 yoffy 1.13 if FileExists(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG')) = true then
354     DeleteFile(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG'));
355 hi_ 1.1 if Assigned(OnDownloadMsg) then
356     Synchronize(FireDownloadMsg);
357     if not DatDownload(Item.DownType, URL, ZERO_DATE, RangeStart, AdjustLen) then
358     Item.State := gdsError;
359     {$IFDEF DEBUG}
360     Writeln('鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申');
361     Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
362     {$ENDIF}
363     end else if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] = #10) then begin
364     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申
365     Item.Content := Copy(Item.Content, 2, Length(Item.Content));
366     end;
367     end else begin
368     Item.State := gdsError;
369     if (Item.DownType = gdtBoard) and (Item.ResponseCode = 302) then begin
370     FMsg := '鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申';
371     FIcon := gmiNG;
372     if Assigned(OnDownloadMsg) then
373     Synchronize(FireDownloadMsg);
374     end;
375     end;
376    
377     //********************
378     //dat.gz鐃緒申鐃緒申(1)
379     //********************
380     if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) then begin
381     {$IFDEF DEBUG}
382     Writeln('dat.gz鐃緒申鐃緒申');
383     {$ENDIF}
384     ATitle := Item.ThreadItem.Title;
385     if ATitle = '' then
386     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
387     FMsg := '鐃緒申dat鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?(dat.gz)鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
388     FIcon := gmiWhat;
389     if Assigned(OnDownloadMsg) then
390     Synchronize(FireDownloadMsg);
391     URL := Item.ThreadItem.GetDatgzURL;
392     Modified := Item.ThreadItem.LastModified;
393     RangeStart := 0;
394     AdjustLen := 0;
395     if not DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen) then
396     Item.State := gdsError;
397     {$IFDEF DEBUG}
398     Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
399     {$ENDIF}
400     end;
401    
402     //********************
403     //dat.gz鐃緒申鐃緒申(2)
404     //********************
405     {
406     if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) then begin
407     ATitle := Item.ThreadItem.Title;
408     if ATitle = '' then
409     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
410     FMsg := '鐃緒申鐃緒申鐃緒申鐃緒申鐃?(1)鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?(2)鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
411     FIcon := gmiWhat;
412     if Assigned(OnDownloadMsg) then
413     Synchronize(FireDownloadMsg);
414     URL := Item.ThreadItem.GetOldDatgzURL;
415     Modified := Item.ThreadItem.LastModified;
416     RangeStart := 0;
417     AdjustLen := 0;
418     if not DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen) then
419     Item.State := gdsError;
420     end;
421     }
422    
423     //********************
424     //offlaw.cgi鐃緒申鐃緒申鐃緒申
425     //********************
426     FSessionID := '';
427     Synchronize(GetSessionID);
428     if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) and (FSessionID <> '') then begin
429     {$IFDEF DEBUG}
430     Writeln('offlaw.cgi鐃緒申鐃緒申鐃緒申');
431     {$ENDIF}
432     ATitle := Item.ThreadItem.Title;
433     if ATitle = '' then
434     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
435     FMsg := '鐃緒申dat.gz鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申offlaw.cgi鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
436     FIcon := gmiWhat;
437     if Assigned(OnDownloadMsg) then
438     Synchronize(FireDownloadMsg);
439     URL := Item.ThreadItem.GetOfflawCgiURL(FSessionID);
440     Modified := Item.ThreadItem.LastModified;
441     RangeStart := 0;
442     AdjustLen := 0;
443     if not DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen) then begin
444     {$IFDEF DEBUG}
445     Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
446     {$ENDIF}
447     Item.State := gdsError;
448    
449     if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) then begin
450     FMsg := '鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?';
451     FIcon := gmiNG;
452     if Assigned(OnDownloadMsg) then
453     Synchronize(FireDownloadMsg);
454     end;
455    
456     end else begin
457     CgiStatus := ParseCgiStatus(Item.Content);
458     {$IFDEF DEBUG}
459     Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
460     {$ENDIF}
461     case CgiStatus.FStatus of
462     gcsOK: begin
463     {$IFDEF DEBUG}
464     Writeln('CGIStatus: OK');
465     {$ENDIF}
466     Item.ResponseCode := 200;
467     Item.Content := DeleteStatusLine(Item.Content);
468     Item.ContentLength := CgiStatus.FSize;
469     end;
470     gcsINCR: begin
471     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
472     {$IFDEF DEBUG}
473     Writeln('CGIStatus: 206');
474     {$ENDIF}
475     Item.ResponseCode := 206;
476     Item.Content := DeleteStatusLine(Item.Content);
477     Item.ContentLength := CgiStatus.FSize;
478     end;
479     gcsERR: begin
480     {$IFDEF DEBUG}
481     Writeln('CGIStatus: 404(ERROR)');
482     {$ENDIF}
483     Item.ResponseCode := 404;
484     Item.State := gdsError;
485     Item.ErrText := CgiStatus.FErrText;
486     end;
487     end;
488     if (Item.ResponseCode = 404) and (AnsiPos('鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申', Item.ErrText) <> 0) then begin
489     {$IFDEF DEBUG}
490     Writeln('鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申');
491     {$ENDIF}
492     ATitle := Item.ThreadItem.Title;
493     if ATitle = '' then
494     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
495     FMsg := '鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
496     FIcon := gmiWhat;
497     if Assigned(OnDownloadMsg) then
498     Synchronize(FireDownloadMsg);
499     Idx := Pos(' ', Item.ErrText);
500     if Idx <> 0 then begin
501     URL := Copy(Item.ErrText, Idx + 1, Length(Item.ErrText));
502 yoffy 1.17 if Pos( '://', URL ) = 0 then begin
503     if Pos('../', URL) = 1 then
504     URL := Copy(URL, 4, MaxInt );
505     if Pos( '/', URL ) = 1 then
506     URL := Copy( URL, 2, MaxInt );
507     URL := GikoSys.UrlToServer(Item.ThreadItem.ParentBoard.URL) + URL;
508     end;
509 hi_ 1.1 Modified := Item.ThreadItem.LastModified;
510     RangeStart := 0;
511     AdjustLen := 0;
512     if not DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen) then
513     Item.State := gdsError;
514     {$IFDEF DEBUG}
515     Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
516     {$ENDIF}
517     end;
518     end;
519     end;
520     end else begin
521     if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) and (FSessionID = '') then begin
522     {$IFDEF DEBUG}
523     Writeln('鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申');
524     {$ENDIF}
525     ATitle := Item.ThreadItem.Title;
526     if ATitle = '' then
527     ATitle := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?';
528     FMsg := '鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申 - [' + ATitle + ']';
529     FIcon := gmiSAD;
530     if Assigned(OnDownloadMsg) then
531     Synchronize(FireDownloadMsg);
532     end;
533     end;
534    
535     case Item.ResponseCode of
536     200: Item.State := gdsComplete;
537     206: Item.State := gdsDiffComplete;
538     304: Item.State := gdsNotModify;
539     else
540     Item.State := gdsError;
541     end;
542     {
543     //鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?
544     if (Item.ResponseCode in [200, 206]) and (Item.Content = '') then
545     Item.State := gdsError;
546     Item.LastModified := FIndy.Response.LastModified;
547     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?/span>C鐃?/span>i鐃?/span>X鐃緒申鐃緒申
548     Item.ContentLength := FIndy.Response.ContentLength + AdjustLen;
549     try
550     ResStream.Clear;
551     FIndy.Get(URL, ResStream);
552     Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding);
553     if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] <> #10) then begin
554     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
555     //鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃緒申鐃?
556     //event
557     FMsg := '鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申';
558     if Assigned(OnDownloadMsg) then
559     Synchronize(FireDownloadMsg);
560     FIndy.Request.ContentRangeStart := 0;
561     FIndy.Request.ContentRangeEnd := 0;
562     AdjustLen := 0;
563     ResStream.Clear;
564     FIndy.Get(URL, ResStream);
565     Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding);
566     end else if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] = #10) then begin
567     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申LF鐃緒申鐃緒申鐃緒申
568     Item.Content := Copy(Item.Content, 2, Length(Item.Content));
569     end;
570     except
571     Item.State := gdsError;
572     end;
573     Item.ResponseCode := FIndy.ResponseCode;
574     }
575     {
576     try
577     ResStream.Clear;
578     FIndy.Get(URL, ResStream);
579     Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding);
580     except
581     Item.State := gdsError;
582     end;
583    
584     CgiStatus := ParseCgiStatus(Item.Content);
585     if CgiStatus.FStatus = gcsOK then begin
586     if CgiStatus.FSize = 0 then
587     Item.State := gdsNotModify
588     else if Item.DownType = gdtBoard then
589     Item.State := gdsComplete
590     else
591     Item.State := gdsDiffComplete;
592     end else if CgiStatus.FStatus = gcsINCR then begin
593     Item.State := gdsComplete;
594     end else if CgiStatus.FStatus = gcsERR then begin
595     Item.State := gdsError;
596     Item.ErrText := CgiStatus.FErrText;
597     end;
598     Item.ContentLength := CgiStatus.FSize;
599     }
600     except
601     Item.State := gdsError;
602     end;
603     //Item.ResponseCode := FIndy.ResponseCode;
604     if FAbort then
605     Item.State := gdsAbort;
606     finally
607     if Assigned(OnDownloadEnd) then
608     Synchronize(FireDownloadEnd);
609     ResStream.Free;
610     end;
611 h677 1.22
612     FIndy.Request.CustomHeaders.Clear;
613     FIndy.Request.RawHeaders.Clear;
614     FIndy.Request.Clear;
615     FIndy.Response.CustomHeaders.Clear;
616     FIndy.Response.RawHeaders.Clear;
617     FIndy.Response.Clear;
618     FIndy.ProxyParams.Clear;
619    
620 hi_ 1.1 if Terminated then Break;
621     Suspend;
622 yoffy 1.5 end;
623     end;
624    
625     function TDownloadThread.CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean;
626     var
627     ResponseCode: Integer;
628     ResStream: TMemoryStream;
629     begin
630     ResponseCode := -1;
631     FIndy.Request.ContentRangeStart := 0;
632     FIndy.Request.ContentRangeEnd := 0;
633    
634     FIndy.Request.CustomHeaders.Clear;
635     if (Modified <> 0) and (Modified <> ZERO_DATE) then begin
636     FIndy.Request.LastModified := modified - OffsetFromUTC;
637     end;
638     FIndy.Request.AcceptEncoding := '';
639 yoffy 1.13 FIndy.Request.Accept := 'text/html';
640 yoffy 1.5 ResStream := TMemoryStream.Create;
641     try
642     try
643     ResStream.Clear;
644     {$IFDEF DEBUG}
645     Writeln('URL: ' + URL);
646     {$ENDIF}
647     FIndy.Get(URL, ResStream);
648     Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding);
649     Item.LastModified := FIndy.Response.LastModified;
650     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申
651     Item.ContentLength := Length(Item.Content);
652     //鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?
653     if Item.Content = '' then
654     Result := False
655     else
656     Result := True;
657     {$IFDEF DEBUG}
658     Writeln('鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申');
659     {$ENDIF}
660     ResponseCode := FIndy.ResponseCode;
661     except
662     on E: EIdSocketError do begin
663     Item.Content := '';
664     Item.LastModified := ZERO_DATE;
665     Item.ContentLength := 0;
666     Item.ErrText := E.Message;
667     Result := False;
668     ResponseCode := -1;
669 yoffy 1.13 Screen.Cursor := crDefault;
670 yoffy 1.5 end;
671     on E: EIdConnectException do begin
672     Item.Content := '';
673     Item.LastModified := ZERO_DATE;
674     Item.ContentLength := 0;
675     Item.ErrText := E.Message;
676     Result := False;
677     ResponseCode := -1;
678 yoffy 1.13 Screen.Cursor := crDefault;
679 yoffy 1.5 end;
680     on E: Exception do begin
681     {$IFDEF DEBUG}
682     Writeln('鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申');
683     Writeln('E.Message: ' + E.Message);
684     {$ENDIF}
685     Item.Content := '';
686     Item.LastModified := ZERO_DATE;
687     Item.ContentLength := 0;
688     Item.ErrText := E.Message;
689     ResponseCode := FIndy.ResponseCode;
690     Result := False;
691 yoffy 1.13 Screen.Cursor := crDefault;
692 yoffy 1.5 end;
693     end;
694     finally
695     if (Item.ContentLength = 0) and (ResponseCode = 206) then
696     Item.ResponseCode := 304
697     else
698     Item.ResponseCode := ResponseCode;
699     ResStream.Free;
700 hi_ 1.1 end;
701     end;
702    
703     function TDownloadThread.DatDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime; RangeStart: Integer; AdjustLen: Integer): Boolean;
704     var
705     ResponseCode: Integer;
706     ResStream: TMemoryStream;
707     begin
708     ResponseCode := -1;
709     if (ItemType = gdtThread) and (RangeStart > 0) then begin
710     // if (ItemType = gdtThread) and (Item.ThreadItem.Size > 0) then begin
711     // FIndy.Request.ContentRangeStart := Item.ThreadItem.Size + AdjustLen;
712     FIndy.Request.ContentRangeStart := RangeStart + AdjustLen;
713     FIndy.Request.ContentRangeEnd := 0;
714     end else begin
715     FIndy.Request.ContentRangeStart := 0;
716     FIndy.Request.ContentRangeEnd := 0;
717     end;
718    
719     FIndy.Request.CustomHeaders.Clear;
720     FIndy.Request.CacheControl := 'no-cache';
721     FIndy.Request.CustomHeaders.Add('Pragma: no-cache');
722     if (Modified <> 0) and (Modified <> ZERO_DATE) then begin
723     FIndy.Request.LastModified := modified - OffsetFromUTC;
724     //FIndy.Request.CustomHeaders.Add('If-Modified-Since: ' + RFC1123_Date(modified - OffsetFromUTC) + ' GMT');
725     end;
726     // FIndy.Request.AcceptEncoding := 'gzip';
727     if RangeStart = 0 then
728     FIndy.Request.AcceptEncoding := 'gzip'
729     else
730     FIndy.Request.AcceptEncoding := '';
731     ResStream := TMemoryStream.Create;
732     try
733     try
734     ResStream.Clear;
735     {$IFDEF DEBUG}
736     Writeln('URL: ' + URL);
737     {$ENDIF}
738     FIndy.Get(URL, ResStream);
739     Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding);
740     Item.LastModified := FIndy.Response.LastModified;
741     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申
742     // Item.ContentLength := FIndy.Response.ContentLength + AdjustLen;
743     Item.ContentLength := Length(Item.Content) + AdjustLen;
744     //鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?
745     // if (FIndy.ResponseCode in [200, 206]) and (Item.Content = '') then
746     // Result := False
747     if Item.Content = '' then
748     Result := False
749     else
750     Result := True;
751     {$IFDEF DEBUG}
752     Writeln('鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申');
753     {$ENDIF}
754     ResponseCode := FIndy.ResponseCode;
755     except
756     on E: EIdSocketError do begin
757     Item.Content := '';
758     Item.LastModified := ZERO_DATE;
759     Item.ContentLength := 0;
760     Item.ErrText := E.Message;
761     Result := False;
762     ResponseCode := -1;
763 yoffy 1.13 Screen.Cursor := crDefault;
764 hi_ 1.1 end;
765     on E: EIdConnectException do begin
766     Item.Content := '';
767     Item.LastModified := ZERO_DATE;
768     Item.ContentLength := 0;
769     Item.ErrText := E.Message;
770     Result := False;
771     ResponseCode := -1;
772 yoffy 1.13 Screen.Cursor := crDefault;
773 hi_ 1.1 end;
774     on E: Exception do begin
775     {$IFDEF DEBUG}
776     Writeln('鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申');
777     Writeln('E.Message: ' + E.Message);
778     {$ENDIF}
779     Item.Content := '';
780     Item.LastModified := ZERO_DATE;
781     Item.ContentLength := 0;
782     Item.ErrText := E.Message;
783     ResponseCode := FIndy.ResponseCode;
784     Result := False;
785 yoffy 1.13 Screen.Cursor := crDefault;
786 hi_ 1.1 end;
787     end;
788     finally
789     if (Item.ContentLength = 0) and (ResponseCode = 206) then
790     Item.ResponseCode := 304
791     else
792     Item.ResponseCode := ResponseCode;
793     ResStream.Free;
794     end;
795     end;
796    
797     procedure TDownloadThread.FireDownloadEnd;
798     begin
799     OnDownloadEnd(self, Item);
800     end;
801    
802     procedure TDownloadThread.FireDownloadMsg;
803     begin
804     OnDownloadMsg(Self, Item, FMsg, FIcon);
805     end;
806    
807     procedure TDownloadThread.GetSessionID;
808     begin
809     FSessionID := GikoSys.Dolib.SessionID;
810     end;
811    
812     procedure TDownloadThread.Abort;
813     begin
814     FAbort := True;
815     FIndy.DisconnectSocket;
816 h677 1.28 if socket <> nil then begin
817     socket.DisconnectSocket;
818     end;
819 hi_ 1.1 end;
820    
821     procedure TDownloadThread.WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer);
822     begin
823     if Assigned(OnWorkBegin) then
824 q9_ 1.23 OnWorkBegin(Sender, AWorkMode, AWorkCountMax, FNumber, FDownloadTitle);
825 hi_ 1.1 end;
826    
827     procedure TDownloadThread.WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
828     begin
829     if Assigned(OnWorkEnd) then
830     OnWorkEnd(Sender, AWorkMode, FNumber);
831     end;
832    
833     procedure TDownloadThread.Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
834     begin
835     if Assigned(OnWork) then
836     OnWork(Sender, AWorkMode, AWorkCount, FNumber);
837     end;
838    
839     function TDownloadThread.ParseCgiStatus(Content: string): TCgiStatus;
840     var
841     StatusLine: string;
842     Line: string;
843     Idx: Integer;
844     Status: string;
845     Size: string;
846     Msg: string;
847     begin
848     // [+OK] 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
849     // [-INCR] (Incorrect)鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?
850     // [-ERR (鐃?鐃?鐃?鐃?)]鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?
851     // 鐃緒申鐃?+OK 23094/512K
852 yoffy 1.13 // -INCR 23094/512K
853     // -ERR 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
854 hi_ 1.1 Idx := AnsiPos(#10, Content);
855     StatusLine := Copy(Content, 0, Idx);
856    
857     Idx := AnsiPos(' ', Content);
858     Status := Copy(StatusLine, 0, Idx - 1);
859     Line := Copy(StatusLine, Idx + 1, Length(StatusLine));
860    
861     // Idx := AnsiPos('/', Line);
862     if Trim(Status) = '-ERR' then
863     Msg := Trim(Line)
864     else
865     Size := Copy(Line, 0, Idx - 1);
866    
867     if Trim(Status) = '+OK' then
868     Result.FStatus := gcsOK
869     else if Trim(Status) = '-INCR' then
870     Result.FStatus := gcsINCR
871     else if Trim(Status) = '-ERR' then begin
872     Result.FStatus := gcsERR;
873     Result.FErrText := Msg;
874     Result.FSize := 0;
875     Exit;
876     end else begin
877     {$IFDEF DEBUG}
878     Writeln(Status);
879     {$ENDIF}
880     Result.FStatus := gcsERR;
881     Result.FErrText := '鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?';
882     Result.FSize := 0;
883     Exit;
884     end;
885    
886     if GikoSys.IsNumeric(Size) then
887     Result.FSize := StrToInt(Size)
888     else begin
889     Result.FSize := 0;
890     Result.FStatus := gcsERR;
891     Result.FErrText := '鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?[' + StatusLine + ']';
892     end;
893     end;
894    
895     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申1鐃?鐃緒申鐃緒申鐃緒申鐃緒申
896     function TDownloadThread.DeleteStatusLine(Content: string): string;
897     var
898     SList: TStringList;
899     begin
900     SList := TStringList.Create;
901     try
902     SList.Text := Content;
903     if SList.Count > 1 then
904     SList.Delete(0);
905     Result := SList.Text;
906     finally
907     SList.Free;
908     end;
909     end;
910    
911     procedure TDownloadItem.SaveListFile;
912     var
913     i: Integer;
914     index: Integer;
915     NewItem: TThreadItem;
916     NumCount: Integer;
917     Body: TStringList;
918     Rec: TSubjectRec;
919 yoffy 1.9 function MakeThreadCallBack(
920 yoffy 1.13 inInstance : DWORD; // TBoardItem 鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?
921 yoffy 1.10 inURL : PChar; // 鐃?鐃緒申鐃?鐃?鐃緒申 URL
922     inTitle : PChar; // 鐃?鐃緒申鐃?鐃?
923     inCount : DWORD // 鐃緒申鐃?鐃緒申鐃緒申
924     ) : Boolean; stdcall; // 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 True
925 yoffy 1.13 var
926 yoffy 1.18 _ThreadItem : TThreadItem; // '_' 鐃緒申鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
927 yoffy 1.13 boardItem : TBoard;
928     begin
929     Result := True;
930     boardItem := TBoard( inInstance );
931    
932     boardItem.IntData := boardItem.IntData + 1;
933     index := boardItem.GetIndexFromURL( string( inURL ) );
934     if index = -1 then begin
935     //鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?
936 yoffy 1.18 _ThreadItem := TThreadItem.Create( boardItem.BoardPlugIn, string( inURL ) );
937 yoffy 1.9
938 yoffy 1.18 _ThreadItem.Title := string( inTitle );
939     _ThreadItem.AllResCount := inCount;
940     _ThreadItem.ParentBoard := Board;
941     _ThreadItem.No := boardItem.IntData;
942     _ThreadItem.RoundDate := ZERO_DATE;
943     _ThreadItem.LastModified := ZERO_DATE;
944     _ThreadItem.AgeSage := gasNew;
945 h677 1.26 boardItem.Add(_ThreadItem);
946 yoffy 1.13 end else begin
947     if boardItem.Items[index].No > boardItem.IntData then
948     boardItem.Items[index].AgeSage := gasAge
949     else if boardItem.Items[index].AllResCount < inCount then
950     boardItem.Items[index].AgeSage := gasSage
951     else
952     boardItem.Items[index].AgeSage := gasNone;
953 yoffy 1.9
954 yoffy 1.13 boardItem.Items[index].No := boardItem.IntData;
955     boardItem.Items[index].AllResCount := inCount;
956     end;
957     end;
958 hi_ 1.1 begin
959 h677 1.26 //Board.ListData := TList.Create;
960 hi_ 1.1 Body := TStringList.Create;
961     try
962     //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?
963     Board.RoundDate := Now;
964     //鐃?鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申
965     Board.LastModified := LastModified;
966 h677 1.26 for i := Board.Count - 1 downto 0 do
967     Board.Items[i].AgeSage := gasNull;
968 hi_ 1.1
969 yoffy 1.13 if Board.IsBoardPlugInAvailable then begin
970     // 鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
971     // 鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
972     // 鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申
973     Board.IntData := 0;
974     Board.BoardPlugIn.EnumThread( DWORD( Board ), @MakeThreadCallBack );
975    
976 h677 1.27 //鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
977     for i := Board.Count - 1 downto 0 do begin
978     if( Board.Items[i].AgeSage = gasNull )and not (Board.Items[i].IsLogFile) then
979     Board.Delete(i);
980     end;
981    
982 yoffy 1.13 // 鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
983     for i := 0 to Board.Count - 1 do begin
984 h677 1.26 if(Board.Items[i].AgeSage = gasNull) and (Board.Items[i].IsLogFile) then begin
985 yoffy 1.13 Board.IntData := Board.IntData + 1;
986     Board.Items[i].No := Board.IntData;
987     Board.Items[i].AllResCount := Board.Items[i].Count;
988     Board.Items[i].NewResCount := 0;
989     Board.Items[i].AgeSage := gasNone;
990     end;
991     end;
992     end else begin
993     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
994     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
995     //鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申
996     Body.Text := Content;
997     NumCount := 0;
998     for i := 0 to Body.Count - 1 do begin
999     Rec := GikoSys.DivideSubject(Body[i]);
1000     Rec.FFileName := Trim(Rec.FFileName);
1001     if (Rec.FTitle = '') and (Rec.FCount = 0) then Continue;
1002     Inc(NumCount);
1003 yoffy 1.24 index := Board.GetIndexFromFileName(Rec.FFileName);
1004 yoffy 1.13 if index = -1 then begin
1005     //鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?
1006 yoffy 1.16 NewItem := TThreadItem.Create(
1007 h677 1.26 nil, GikoSys.Get2chBoard2ThreadURL( Board, ChangeFileExt( Rec.FFileName, '' ) ) );
1008 yoffy 1.13 NewItem.Title := Rec.FTitle;
1009     NewItem.AllResCount := Rec.FCount;
1010     NewItem.ParentBoard := Board;
1011     NewItem.No := NumCount;
1012     NewItem.RoundDate := ZERO_DATE;
1013     NewItem.LastModified := ZERO_DATE;
1014     NewItem.AgeSage := gasNew;
1015 h677 1.26 Board.Add(NewItem);
1016 yoffy 1.13 end else begin
1017     if Board.Items[index].No > NumCount then
1018     Board.Items[index].AgeSage := gasAge
1019     else if Board.Items[index].AllResCount < Rec.FCount then
1020     Board.Items[index].AgeSage := gasSage
1021     else
1022     Board.Items[index].AgeSage := gasNone;
1023    
1024     Board.Items[index].No := NumCount;
1025     Board.Items[index].AllResCount := Rec.FCount;
1026     end;
1027 h677 1.27 end;
1028     //鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
1029     for i := Board.Count - 1 downto 0 do begin
1030     if( Board.Items[i].AgeSage = gasNull )and not (Board.Items[i].IsLogFile) then
1031     Board.Delete(i);
1032 yoffy 1.13 end;
1033    
1034 h677 1.26 //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?
1035 yoffy 1.13 for i := 0 to Board.Count - 1 do begin
1036 h677 1.26 if( Board.Items[i].AgeSage = gasNull )and (Board.Items[i].IsLogFile) then begin
1037 yoffy 1.13 inc(NumCount);
1038     Board.Items[i].No := NumCount;
1039     Board.Items[i].AllResCount := Board.Items[i].Count;
1040     Board.Items[i].NewResCount := 0;
1041     Board.Items[i].AgeSage := gasNone;
1042     end;
1043     end;
1044     //鐃緒申鐃?鐃?(subject.txt)鐃緒申鐃緒申鐃緒申
1045     GikoSys.ForceDirectoriesEx(ExtractFilePath(Board.GetSubjectFileName));
1046     Body.SaveToFile(Board.GetSubjectFileName);
1047     end;
1048 hi_ 1.1 finally
1049     Body.Free;
1050     end;
1051 h677 1.26
1052    
1053 hi_ 1.1 end;
1054    
1055     {procedure TDownloadItem.SaveListFile;
1056     var
1057     i: Integer;
1058     index: Integer;
1059     NewItem: TThreadItem;
1060     NewList: TList;
1061     // SaveCount: Integer;
1062     NumCount: Integer;
1063     Body: TStringList;
1064     Rec: TSubjectRec;
1065     begin
1066     NewList := TList.Create;
1067     Body := TStringList.Create;
1068     try
1069     //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
1070     Board.RoundDate := Now;
1071     //鐃?鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申
1072     Board.LastModified := LastModified;
1073    
1074     //鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
1075     //SaveCount := MaxInt;
1076    
1077     //鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申
1078     for i := Board.Count - 1 downto 0 do
1079     if not Board.Items[i].IsLogFile then
1080     Board.Delete(i);
1081    
1082     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
1083     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
1084     //鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申
1085     Body.Text := Content;
1086     // Loop := Min(Body.Count, SaveCount);
1087     NumCount := 0;
1088     // for i := 0 to Loop - 1 do begin
1089     for i := 0 to Body.Count - 1 do begin
1090     if i = 0 then Continue; //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
1091    
1092     Rec := GikoSys.DivideSubject(Body[i]);
1093     if (Rec.FTitle = '') and (Rec.FCount = 0) then Continue;
1094     Inc(NumCount);
1095     index := Board.GetIndex(Rec.FFileName);
1096     if index = -1 then begin
1097     NewItem := TThreadItem.Create;
1098     NewItem.FileName := Rec.FFileName;
1099     NewItem.Title := Rec.FTitle;
1100     NewItem.Count := Rec.FCount;
1101     NewItem.ParentBoard := Board;
1102     NewItem.No := NumCount;
1103     NewItem.RoundDate := ZERO_DATE;
1104     NewItem.LastModified := ZERO_DATE;
1105     NewList.Add(NewItem);
1106     end else begin
1107     //Board.Items[index].Count := Count;
1108     Board.Items[index].No := NumCount;
1109     NewList.Add(Board.Items[index]);
1110     Board.DeleteList(index);
1111     end;
1112     end;
1113    
1114     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申
1115     for i := 0 to Board.Count - 1 do begin
1116     inc(NumCount);
1117     Board.Items[i].No := NumCount;
1118     NewList.Add(Board.Items[i]);
1119     end;
1120    
1121     //鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?
1122     for i := Board.Count - 1 downto 0 do
1123     Board.DeleteList(i);
1124    
1125     //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申
1126     for i := 0 to NewList.Count - 1 do
1127     Board.Add(TThreadItem(NewList[i]));
1128    
1129     //鐃緒申鐃?鐃?(subject.txt)鐃緒申鐃緒申鐃緒申
1130     // GikoSys.ForceDirectoriesEx(GikoSys.GetLogDir + Board.BBSID);
1131     // Body.SaveToFile(GikoSys.GetSubjectFileName(Board.BBSID));
1132     GikoSys.ForceDirectoriesEx(ExtractFilePath(Board.GetSubjectFileName));
1133     Body.SaveToFile(Board.GetSubjectFileName);
1134     finally
1135     Body.Free;
1136     NewList.Free;
1137     end;
1138     end;
1139     }
1140     procedure TDownloadItem.SaveItemFile;
1141     var
1142     Body: TStringList;
1143     Cnt: Integer;
1144     OldCnt: Integer;
1145     FileName: string;
1146     ini: TMemIniFile;
1147     Res: TResRec;
1148     NewRes: Integer;
1149 h677 1.19 finish : Boolean;
1150     loopCnt : Integer;
1151 hi_ 1.1 begin
1152     FileName := ThreadItem.GetThreadFileName;
1153    
1154 yoffy 1.15 if not ThreadItem.IsBoardPlugInAvailable then begin
1155     if Trim(Content) = '' then
1156     Exit;
1157     GikoSys.ForceDirectoriesEx(ExtractFilePath(FileName));
1158    
1159     // Cnt := 0;
1160     Body := TStringList.Create;
1161 h677 1.20 NewRes := 0;
1162     OldCnt := 0;
1163 yoffy 1.15 try
1164     // if FileExists(FileName) and (ResponseCode = 206) then begin
1165     if FileExists(FileName) and (State = gdsDiffComplete) then begin
1166     // Body.Text := Content;
1167     // if Body.Count > 0 then
1168     // Body.Delete(0);
1169     // Content := Body.Text;
1170 h677 1.19 loopCnt := 10;
1171     repeat
1172     finish := true;
1173     try
1174     Body.LoadFromFile(FileName);
1175     OldCnt := Body.Count;
1176     Body.Text := Body.Text + Content;
1177     Body.SaveToFile(FileName);
1178     NewRes := Body.Count - OldCnt;
1179     except
1180     on E:EFOpenError do begin
1181     sleep(10);
1182     finish := false;
1183     Dec(loopCnt);
1184     end;
1185     end;
1186     until finish and ( loopCnt > 0 );
1187     //Cnt := Body.Count;
1188 yoffy 1.15 end else begin
1189     Body.Text := Content;
1190     // if Body.Count > 0 then
1191     // Body.Delete(0);
1192     Body.SaveToFile(FileName);
1193 hi_ 1.1
1194 yoffy 1.15 if ThreadItem.Title = '' then begin
1195     Res := GikoSys.DivideStrLine(Body[0]);
1196     ThreadItem.Title := Res.FTitle;
1197     end;
1198     ThreadItem.Size := 0;
1199     //ThreadItem.Count := 0;
1200     ThreadItem.AllResCount := 0;
1201     ThreadItem.NewResCount := 0;
1202     OldCnt := 0;
1203     NewRes := Body.Count;
1204 h677 1.19 //Cnt := Body.Count;
1205 hi_ 1.1 end;
1206     Cnt := Body.Count;
1207 yoffy 1.15 finally
1208     Body.Free;
1209 hi_ 1.1 end;
1210 h677 1.19
1211 yoffy 1.15 ThreadItem.Size := ThreadItem.Size + ContentLength;
1212     ThreadItem.LastModified := LastModified;
1213     ThreadItem.Count := Cnt;
1214 h677 1.19 //ThreadItem.AllResCount := Cnt;
1215 yoffy 1.15 ThreadItem.NewResCount := NewRes;
1216     ThreadItem.NewReceive := OldCnt + 1;
1217 hi_ 1.1 end;
1218 h677 1.19 ThreadItem.AllResCount := ThreadItem.Count;
1219 yoffy 1.15 ThreadItem.IsLogFile := True;
1220 hi_ 1.1 ThreadItem.RoundDate := Now;
1221     ThreadItem.UnRead := True;
1222     ThreadItem.ParentBoard.UnRead := ThreadItem.ParentBoard.UnRead + 1;
1223     // if ThreadItem.RoundNo = 6 then
1224     // ThreadItem.RoundNo := 0;
1225    
1226     //鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?
1227     //鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
1228     //鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?
1229     ini := TMemIniFile.Create(ChangeFileExt(FileName, '.tmp'));
1230     try
1231     ini.WriteDateTime('Setting', 'RoundDate', ThreadItem.RoundDate);
1232     ini.WriteDateTime('Setting', 'LastModified', ThreadItem.LastModified);
1233     ini.WriteInteger('Setting', 'Size', ThreadItem.Size);
1234     ini.WriteInteger('Setting', 'Count', ThreadItem.Count);
1235     ini.WriteInteger('Setting', 'AllResCount', ThreadItem.AllResCount);
1236     ini.WriteInteger('Setting', 'NewResCount', ThreadItem.NewResCount);
1237     ini.WriteInteger('Setting', 'NewReceive', ThreadItem.NewReceive);
1238     // ini.WriteInteger('Setting', 'RoundNo', ThreadItem.RoundNo);
1239     ini.WriteBool('Setting', 'Round', ThreadItem.Round);
1240     ini.WriteBool('Setting', 'UnRead', ThreadItem.UnRead);
1241 h677 1.19 ini.UpdateFile;
1242 hi_ 1.1 finally
1243     ini.Free;
1244     end;
1245     end;
1246    
1247     end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26