X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=ItemDownload.pas;h=fe0fb18e75e307325ffd472990615748de2c573f;hb=21fef4e58359ae52b77a404272173b7b9bb012b5;hp=618dba23dbe6d04272c49d2c4d0a03cdc1183e19;hpb=5b547056133e220a8fe83445eff8cd5010605e50;p=gikonavigoeson%2Fgikonavi.git
diff --git a/ItemDownload.pas b/ItemDownload.pas
index 618dba2..fe0fb18 100644
--- a/ItemDownload.pas
+++ b/ItemDownload.pas
@@ -5,7 +5,8 @@ interface
uses
Windows, SysUtils, Classes, ComCtrls, Controls, Forms, IdHTTP,
{HTTPApp,} YofUtils, IdGlobal, IdException, IdComponent, IniFiles, {DateUtils,}
- GikoSystem, BoardGroup, MonaUtils, ExternalBoardManager;
+ GikoSystem, BoardGroup, MonaUtils, ExternalBoardManager, ExternalBoardPlugInMain,
+ Sort;
type
TDownloadItem = class;
@@ -15,7 +16,7 @@ type
TGikoDLProgress = (gdpStd, gdpAll, gdpDatOchi, gdpOfflaw);
TGikoWorkEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer; ID: Integer) of object;
- TGikoWorkBeginEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer; ID: Integer) of object;
+ TGikoWorkBeginEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer; ID: Integer; const AWorkTitle: string) of object;
TGikoWorkEndEvent = procedure(Sender: TObject; AWorkMode: TWorkMode; ID: Integer) of object;
TDownloadEndEvent = procedure(Sender: TObject; Item: TDownloadItem) of object;
TDownloadMsgEvent = procedure(Sender: TObject; Item: TDownloadItem; Msg: string; Icon: TGikoMessageIcon) of object;
@@ -41,6 +42,7 @@ type
FOnWorkEnd: TGikoWorkEndEvent;
FOnDownloadEnd: TDownloadEndEvent;
FOnDownloadMsg: TDownloadMsgEvent;
+ FDownloadTitle: string;
procedure FireDownloadEnd;
procedure FireDownloadMsg;
@@ -49,7 +51,7 @@ type
procedure WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
function ParseCgiStatus(Content: string): TCgiStatus;
- function CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean;
+ function CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean;
function DatDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime; RangeStart: Integer; AdjustLen: Integer): Boolean;
function DeleteStatusLine(Content: string): string;
protected
@@ -58,7 +60,7 @@ type
property Item: TDownloadItem read FItem write FItem;
property Number: Integer read FNumber write FNumber;
constructor Create(CreateSuspended: Boolean);
- destructor Destroy; override;
+ destructor Destroy; override;
procedure Abort;
property OnWork: TGikoWorkEvent read FOnWork write FOnWork;
property OnWorkBegin: TGikoWorkBeginEvent read FOnWorkBegin write FOnWorkBegin;
@@ -79,6 +81,8 @@ type
FResponseCode: Smallint;
FState: TGikoDownloadState;
FErrText: string;
+ FForceDownload: Boolean;
+ FIsAbone : Boolean;
public
procedure SaveListFile;
procedure SaveItemFile;
@@ -93,6 +97,8 @@ type
property ResponseCode: Smallint read FResponseCode write FResponseCode;
property State: TGikoDownloadState read FState write FState;
property ErrText: string read FErrText write FErrText;
+ property ForceDownload: Boolean read FForceDownload write FForceDownload;
+ property IsAbone : Boolean read FIsAbone write FIsAbone;
end;
implementation
@@ -109,6 +115,13 @@ end;
destructor TDownloadThread.Destroy;
begin
+ FIndy.Request.CustomHeaders.Clear;
+ FIndy.Request.RawHeaders.Clear;
+ FIndy.Request.Clear;
+ FIndy.Response.CustomHeaders.Clear;
+ FIndy.Response.RawHeaders.Clear;
+ FIndy.Response.Clear;
+ FIndy.ProxyParams.Clear;
FIndy.Free;
inherited;
end;
@@ -116,14 +129,14 @@ end;
function RFC1123_Date(aDate : TDateTime) : String;
const
StrWeekDay : String = 'MonTueWedThuFriSatSun';
- StrMonth : String = 'JanFebMarAprMayJunJulAugSepOctNovDec';
+ StrMonth : String = 'JanFebMarAprMayJunJulAugSepOctNovDec';
var
- Year, Month, Day : Word;
- Hour, Min, Sec, MSec : Word;
- DayOfWeek : Word;
+ Year, Month, Day : Word;
+ Hour, Min, Sec, MSec : Word;
+ DayOfWeek : Word;
begin
DecodeDate(aDate, Year, Month, Day);
- DecodeTime(aDate, Hour, Min, Sec, MSec);
+ DecodeTime(aDate, Hour, Min, Sec, MSec);
DayOfWeek := ((Trunc(aDate) - 2) mod 7);
Result := Copy(StrWeekDay, 1 + DayOfWeek * 3, 3) + ', ' +
Format('%2.2d %s %4.4d %2.2d:%2.2d:%2.2d',
@@ -143,39 +156,67 @@ var
Idx: Integer;
ATitle: string;
DownloadResult: Boolean;
- Abone: Boolean;
- foundPos: Integer;
- boardPlugIn : TBoardPlugIn;
+ boardPlugIn : TBoardPlugIn;
+ lastContent : string;
+ logFile : TFileStream;
+ adjustMargin : Integer;
+const
+ ADJUST_MARGIN = 16;
begin
while not Terminated do begin
- if FItem.FThreadItem <> nil then
- boardPlugIn := FItem.FThreadItem.BoardPlugIn
- else
- boardPlugIn := nil;
- if boardPlugIn <> nil then begin
- if Assigned( Pointer( boardPlugIn.Module ) ) then begin
- ExternalBoardManager.OnWork := Work;
- ExternalBoardManager.OnWorkBegin := WorkBegin;
- ExternalBoardManager.OnWorkEnd := WorkEnd;
- boardPlugIn.Download( DWORD( FItem.FThreadItem ) );
-
- if FAbort then
- Item.State := gdsAbort
- else
- Item.State := gdsComplete;
- if Assigned( OnDownloadEnd ) then
- Synchronize( FireDownloadEnd );
- if Terminated then
- Break;
-
- Suspend;
- Continue;
- end;
- end;
+ //===== vOC
+ FAbort := False;
+ boardPlugIn := nil;
+ ExternalBoardManager.OnWork := Work;
+ ExternalBoardManager.OnWorkBegin := WorkBegin;
+ ExternalBoardManager.OnWorkEnd := WorkEnd;
+
+ FDownloadTitle := '';
+ case FItem.FDownType of
+ gdtBoard:
+ begin
+ FDownloadTitle := FItem.FBoard.Title;
+ if FItem.FBoard <> nil then begin
+ if FItem.FBoard.IsBoardPlugInAvailable then begin
+ boardPlugIn := FItem.FBoard.BoardPlugIn;
+ Item.State := TGikoDownloadState( boardPlugIn.DownloadBoard( DWORD( FItem.FBoard ) ) );
+ end;
+ end;
+ end;
+ gdtThread:
+ begin
+ FDownloadTitle := FItem.FThreadItem.Title;
+ if FItem.FThreadItem <> nil then begin
+ if FItem.FThreadItem.IsBoardPlugInAvailable then begin
+ boardPlugIn := FItem.FThreadItem.BoardPlugIn;
+ Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) );
+ end;
+ end;
+ end;
+ end;
+ if Length(FDownloadTitle) = 0 then
+ FDownloadTitle := 'i¼Ìs¾j';
+
+ if boardPlugIn <> nil then begin
+ if FAbort then begin
+ Item.State := gdsAbort;
+ end;
+ if Assigned( OnDownloadEnd ) then
+ Synchronize( FireDownloadEnd );
+ if Terminated then
+ Break;
+
+ Suspend;
+ Continue;
+ end;
+
+ //===== vOCðgpµÈ¢ê
FAbort := False;
FIndy.Request.CustomHeaders.Clear;
FIndy.Response.Clear;
FIndy.Request.Clear;
+ FIndy.ProxyParams.Clear;
+ FIndy.Disconnect;
FIndy.Request.UserAgent := GikoSys.GetUserAgent;
FIndy.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
FIndy.ProxyParams.BasicAuthentication := False;
@@ -213,6 +254,25 @@ begin
{$ENDIF}
end;
+ adjustMargin := 0;
+ if Item.DownType = gdtThread then begin
+ if FileExists( Item.ThreadItem.GetThreadFileName ) then begin
+ // dat t@CÌÅãðÇÝo·
+ SetLength( lastContent, ADJUST_MARGIN + 1 );
+ logFile := TFileStream.Create( Item.ThreadItem.GetThreadFileName, fmOpenRead or fmShareDenyWrite );
+ try
+ logFile.Seek( -(ADJUST_MARGIN + 1), soFromEnd );
+ logFile.Read( lastContent[ 1 ], ADJUST_MARGIN + 1 );
+ lastContent := StringReplace( lastContent, #13, '', [] ); // CR Ìí
+ finally
+ logFile.Free;
+ end;
+ end else begin
+ lastContent := '';
+ end;
+ adjustMargin := Length( lastContent );
+ end;
+
FIndy.Request.ContentRangeStart := 0;
FIndy.Request.LastModified := ZERO_DATE;
ResStream := TMemoryStream.Create;
@@ -232,7 +292,19 @@ begin
Writeln('Modified: ' + FloatToStr(Item.Board.LastModified));
{$ENDIF}
URL := Item.Board.GetReadCgiURL;
- Modified := Item.Board.LastModified;
+ if Item.ForceDownload then begin
+ // §æ¾
+ ATitle := Item.Board.Title;
+ if ATitle = '' then
+ ATitle := 'i¼Ìs¾j';
+ FMsg := '§æ¾ðs¢Ü· - [' + ATitle + ']';
+ FIcon := gmiWhat;
+ if Assigned(OnDownloadMsg) then
+ Synchronize(FireDownloadMsg);
+ Modified := ZERO_DATE
+ end else begin
+ Modified := Item.Board.LastModified;
+ end;
end else if Item.DownType = gdtThread then begin
{$IFDEF DEBUG}
Writeln('DATæ¾');
@@ -240,27 +312,45 @@ begin
Writeln('Modified: ' + FloatToStr(Item.ThreadItem.LastModified));
{$ENDIF}
URL := Item.ThreadItem.GetDatURL;
- Modified := Item.ThreadItem.LastModified;
- if Item.ThreadItem.Size > 0 then begin
- {$IFDEF DEBUG}
- Writeln('RangeStart: ' + IntToStr(Item.ThreadItem.Size));
- {$ENDIF}
- // Ú[ñ`FbN̽ßPoCgO©çæ¾
- RangeStart := Item.ThreadItem.Size;
- AdjustLen := -1;
+ if Item.ForceDownload then begin
+ // §æ¾
+ ATitle := Item.ThreadItem.Title;
+ if ATitle = '' then
+ ATitle := 'i¼Ìs¾j';
+ FMsg := '§æ¾ðs¢Ü· - [' + ATitle + ']';
+ FIcon := gmiWhat;
+ if FileExists(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG')) = true then
+ DeleteFile(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG'));
+ if Assigned(OnDownloadMsg) then
+ Synchronize(FireDownloadMsg);
+ Modified := ZERO_DATE;
+ RangeStart := 0;
+ AdjustLen := 0;
+ end else begin
+ Modified := Item.ThreadItem.LastModified;
+ if Item.ThreadItem.Size > 0 then begin
+ {$IFDEF DEBUG}
+ Writeln('RangeStart: ' + IntToStr(Item.ThreadItem.Size));
+ {$ENDIF}
+ // Ú[ñ`FbNÌ½ß adjustMargin oCgO©çæ¾
+ RangeStart := Item.ThreadItem.Size;
+ AdjustLen := -adjustMargin;
+ end;
end;
end;
- Abone := False;
+ Item.IsAbone := False;
DownloadResult := DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen);
{$IFDEF DEBUG}
Writeln('ResponseCode: ' + IntToStr(FIndy.ResponseCode));
{$ENDIF}
if Item.DownType = gdtThread then begin
if Item.ResponseCode = 416 then begin
- Abone := True;
+ Item.IsAbone := True;
DownloadResult := True;
- end else if DownloadResult and (AdjustLen = -1) and (Item.Content[1] <> #10) then
- Abone := True;
+ end else if DownloadResult and (AdjustLen < 0) then begin
+ if Copy( Item.Content, 1, adjustMargin ) <> lastContent then
+ Item.IsAbone := True;
+ end;
end;
if Trim(FIndy.Response.RawHeaders.Values['Date']) <> '' then begin
@@ -274,7 +364,7 @@ begin
{$IFDEF DEBUG}
Writeln('Date:' + FIndy.Response.RawHeaders.Values['Date']);
{$ENDIF}
- if Abone then begin
+ if Item.IsAbone then begin
{$IFDEF DEBUG}
Writeln(' Ú[ño');
{$ENDIF}
@@ -286,8 +376,8 @@ begin
AdjustLen := 0;
FMsg := 'u Ú[ñvðoµ½ÌÅÄæ¾ðs¢Ü· - [' + ATitle + ']';
FIcon := gmiWhat;
- if FileExists(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG')) = true then
- DeleteFile(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG'));
+ if FileExists(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG')) = true then
+ DeleteFile(ChangeFileExt(Item.FThreadItem.GetThreadFileName,'.NG'));
if Assigned(OnDownloadMsg) then
Synchronize(FireDownloadMsg);
if not DatDownload(Item.DownType, URL, ZERO_DATE, RangeStart, AdjustLen) then
@@ -296,9 +386,9 @@ begin
Writeln(' Ú[ñÄæ¾ã');
Writeln('ResponseCode: ' + IntToStr(Item.ResponseCode));
{$ENDIF}
- end else if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] = #10) then begin
- //·ªæ¾©ÂPoCgÚªLFÌêi³íæ¾jͪÌLFðí
- Item.Content := Copy(Item.Content, 2, Length(Item.Content));
+ end else if (Item.DownType = gdtThread) and (AdjustLen < 0) then begin
+ // ·ªæ¾ªo½êÍ Ú[ñ`FbNpÉæ¾µ½]ªÈTCYðí
+ Item.Content := Copy(Item.Content, adjustMargin + 1, MaxInt);
end;
end else begin
Item.State := gdsError;
@@ -435,9 +525,13 @@ begin
Idx := Pos(' ', Item.ErrText);
if Idx <> 0 then begin
URL := Copy(Item.ErrText, Idx + 1, Length(Item.ErrText));
- if Pos('../', URL) = 1 then
- URL := Copy(URL, 4, Length(URL));
- URL := GikoSys.UrlToServer(Item.ThreadItem.ParentBoard.URL) + URL;
+ if Pos( '://', URL ) = 0 then begin
+ if Pos('../', URL) = 1 then
+ URL := Copy(URL, 4, MaxInt );
+ if Pos( '/', URL ) = 1 then
+ URL := Copy( URL, 2, MaxInt );
+ URL := GikoSys.UrlToServer(Item.ThreadItem.ParentBoard.URL) + URL;
+ end;
Modified := Item.ThreadItem.LastModified;
RangeStart := 0;
AdjustLen := 0;
@@ -464,40 +558,6 @@ begin
end;
end;
- {$IFDEF DEBUG}
- if (Item.DownType = gdtThread) and (Item.ResponseCode = 302) then begin
- ATitle := Item.ThreadItem.Title;
- if ATitle = '' then
- ATitle := 'i¼Ìs¾j';
- FMsg := 'ßO(1)ª¶ÝµÈ¢½ßgoogleLbV
©çTµÜ· - [' + ATitle + ']';
- FIcon := gmiWhat;
- if Assigned(OnDownloadMsg) then
- Synchronize(FireDownloadMsg);
- URL := 'http://www.google.co.jp/search?q=cache:' + Item.ThreadItem.URL;
- URL := StringReplace( URL, 'l50', '', [rfReplaceAll] );
- Modified := Item.ThreadItem.LastModified;
- Repeat
- if not CgiDownload(Item.DownType, URL, Modified) then
- Item.State := gdsError;
- URL := FIndy.Response.Location;
- Until Item.ResponseCode <> 301;
- if Item.ResponseCode = 200 then begin
- foundPos := Pos( '
', Item.Content ) + Length( '' );
- Item.Content := Copy( Item.Content, foundPos, Length( Item.Content ) );
- foundPos := Pos( '', Item.Content );
- If foundPos > 0 Then
- Item.Content := Copy( Item.Content, 1, foundPos - 1 );
- Item.Content := StringReplace( Item.Content, '', '<>' + #13#10, [rfReplaceAll] );
- Item.Content := StringReplace( Item.Content, '', '<>', [rfReplaceAll] );
- Item.Content := StringReplace( Item.Content, '', '<>', [rfReplaceAll] );
- Item.Content := StringReplace( Item.Content, '', '<>', [rfReplaceAll] );
- Item.Content := StringReplace( Item.Content, '', '<>', [rfReplaceAll] );
- Item.Content := StringReplace( Item.Content, '', '<>', [rfReplaceAll] );
- end;
- end;
- {$ENDIF}
-
case Item.ResponseCode of
200: Item.State := gdsComplete;
206: Item.State := gdsDiffComplete;
@@ -574,6 +634,15 @@ begin
Synchronize(FireDownloadEnd);
ResStream.Free;
end;
+
+ FIndy.Request.CustomHeaders.Clear;
+ FIndy.Request.RawHeaders.Clear;
+ FIndy.Request.Clear;
+ FIndy.Response.CustomHeaders.Clear;
+ FIndy.Response.RawHeaders.Clear;
+ FIndy.Response.Clear;
+ FIndy.ProxyParams.Clear;
+
if Terminated then Break;
Suspend;
end;
@@ -593,7 +662,7 @@ begin
FIndy.Request.LastModified := modified - OffsetFromUTC;
end;
FIndy.Request.AcceptEncoding := '';
- FIndy.Request.Accept := 'text/html';
+ FIndy.Request.Accept := 'text/html';
ResStream := TMemoryStream.Create;
try
try
@@ -623,7 +692,7 @@ begin
Item.ErrText := E.Message;
Result := False;
ResponseCode := -1;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
on E: EIdConnectException do begin
Item.Content := '';
@@ -632,7 +701,7 @@ begin
Item.ErrText := E.Message;
Result := False;
ResponseCode := -1;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
on E: Exception do begin
{$IFDEF DEBUG}
@@ -645,7 +714,7 @@ begin
Item.ErrText := E.Message;
ResponseCode := FIndy.ResponseCode;
Result := False;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
end;
finally
@@ -717,7 +786,7 @@ begin
Item.ErrText := E.Message;
Result := False;
ResponseCode := -1;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
on E: EIdConnectException do begin
Item.Content := '';
@@ -726,7 +795,7 @@ begin
Item.ErrText := E.Message;
Result := False;
ResponseCode := -1;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
on E: Exception do begin
{$IFDEF DEBUG}
@@ -739,7 +808,7 @@ begin
Item.ErrText := E.Message;
ResponseCode := FIndy.ResponseCode;
Result := False;
- Screen.Cursor := crDefault;
+ Screen.Cursor := crDefault;
end;
end;
finally
@@ -770,12 +839,15 @@ procedure TDownloadThread.Abort;
begin
FAbort := True;
FIndy.DisconnectSocket;
+ if socket <> nil then begin
+ socket.DisconnectSocket;
+ end;
end;
procedure TDownloadThread.WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer);
begin
if Assigned(OnWorkBegin) then
- OnWorkBegin(Sender, AWorkMode, AWorkCountMax, FNumber);
+ OnWorkBegin(Sender, AWorkMode, AWorkCountMax, FNumber, FDownloadTitle);
end;
procedure TDownloadThread.WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
@@ -803,8 +875,8 @@ begin
// [-INCR] (Incorrect)ÌêÍ·×ÄÌf[^
// [-ERR (eLXg)]ÌêÍÈñ©G[
// áF+OK 23094/512K
-// -INCR 23094/512K
-// -ERR »ñÈÂȢŷ
+// -INCR 23094/512K
+// -ERR »ñÈÂȢŷ
Idx := AnsiPos(#10, Content);
StatusLine := Copy(Content, 0, Idx);
@@ -867,13 +939,50 @@ var
i: Integer;
index: Integer;
NewItem: TThreadItem;
- NewList: TList;
-// SaveCount: Integer;
NumCount: Integer;
Body: TStringList;
Rec: TSubjectRec;
+ function MakeThreadCallBack(
+ inInstance : DWORD; // TBoardItem ÌCX^X
+ inURL : PChar; // XbhÌ URL
+ inTitle : PChar; // X^C
+ inCount : DWORD // XÌ
+ ) : Boolean; stdcall; // ñð±¯éÈç True
+ var
+ _ThreadItem : TThreadItem; // '_' ÍNXÌvpeBÆ©ÔÁÄéÌÅ
+ boardItem : TBoard;
+ begin
+ Result := True;
+ boardItem := TBoard( inInstance );
+
+ boardItem.IntData := boardItem.IntData + 1;
+ index := boardItem.GetIndexFromURL( string( inURL ) );
+ if index = -1 then begin
+ //Vµ¢Xbh
+ _ThreadItem := TThreadItem.Create( boardItem.BoardPlugIn, string( inURL ) );
+
+ _ThreadItem.Title := string( inTitle );
+ _ThreadItem.AllResCount := inCount;
+ _ThreadItem.ParentBoard := Board;
+ _ThreadItem.No := boardItem.IntData;
+ _ThreadItem.RoundDate := ZERO_DATE;
+ _ThreadItem.LastModified := ZERO_DATE;
+ _ThreadItem.AgeSage := gasNew;
+ boardItem.Add(_ThreadItem);
+ end else begin
+ if boardItem.Items[index].No > boardItem.IntData then
+ boardItem.Items[index].AgeSage := gasAge
+ else if boardItem.Items[index].AllResCount < inCount then
+ boardItem.Items[index].AgeSage := gasSage
+ else
+ boardItem.Items[index].AgeSage := gasNone;
+
+ boardItem.Items[index].No := boardItem.IntData;
+ boardItem.Items[index].AllResCount := inCount;
+ end;
+ end;
begin
- NewList := TList.Create;
+ //Board.ListData := TList.Create;
Body := TStringList.Create;
try
//_E[húÝèi[Júj
@@ -881,81 +990,102 @@ begin
//T[oãt@CÌXVÝè
Board.LastModified := LastModified;
- //Vµ¢Xgð쬷é
- //Vµ¢XgÉâXgÌOª éÈç»êðVµ¢XgÉÇÁ
- //âOªÈ¯êÎAV½ÉXIuWFNgðì¬
- Body.Text := Content;
- NumCount := 0;
- for i := 0 to Body.Count - 1 do begin
- //if i = 0 then Continue; //PsÚÍXe[^Xs̽ßȵ
+ //dat¿XÌ\[gðè·é½ßÉ\[g·é
+ if GikoSys.Setting.DatOchiSortIndex >= 0 then begin
+ Sort.SortNoFlag := true;
+ Sort.SortOrder := GikoSys.Setting.DatOchiSortOrder;
+ Sort.SortIndex := GikoSys.Setting.DatOchiSortIndex;
+ //Sort.SortNonAcquiredCountFlag := GikoSys.Setting.NonAcquiredCount;
+ Board.CustomSort(ThreadItemSortProc);
+ end;
- Rec := GikoSys.DivideSubject(Body[i]);
- Rec.FFileName := Trim(Rec.FFileName);
- if (Rec.FTitle = '') and (Rec.FCount = 0) then Continue;
- Inc(NumCount);
- index := Board.GetIndex(Rec.FFileName);
- if index = -1 then begin
- //Vµ¢Xbh
- NewItem := TThreadItem.Create;
- NewItem.FileName := Rec.FFileName;
- NewItem.Title := Rec.FTitle;
-// NewItem.Count := Rec.FCount;
- NewItem.AllResCount := Rec.FCount;
- NewItem.ParentBoard := Board;
- NewItem.No := NumCount;
- NewItem.RoundDate := ZERO_DATE;
- NewItem.LastModified := ZERO_DATE;
- NewItem.AgeSage := gasNew;
- NewList.Add(NewItem);
- end else begin
- //Board.Items[index].Count := Count;
- //Board.Items[index].Count := Rec.FCount;
- if Board.Items[index].No > NumCount then
- Board.Items[index].AgeSage := gasAge
- else if Board.Items[index].AllResCount < Rec.FCount then
- Board.Items[index].AgeSage := gasSage
- else
- Board.Items[index].AgeSage := gasNone;
+ for i := Board.Count - 1 downto 0 do
+ Board.Items[i].AgeSage := gasNull;
+
+ if Board.IsBoardPlugInAvailable then begin
+ // Vµ¢Xgð쬷é
+ // Vµ¢XgÉâXgÌOª éÈç»êðVµ¢XgÉÇÁ
+ // âOªÈ¯êÎAV½ÉXIuWFNgðì¬
+ Board.IntData := 0;
+ Board.BoardPlugIn.EnumThread( DWORD( Board ), @MakeThreadCallBack );
+
+ //âXgɵ©È¢âÂçðí
+ for i := Board.Count - 1 downto 0 do begin
+ if( Board.Items[i].AgeSage = gasNull )and not (Board.Items[i].IsLogFile) then
+ Board.Delete(i);
+ end;
+ // Vµ¢Xgɳ©Á½ACeðVµ¢XgÉÇÁ
+ for i := 0 to Board.Count - 1 do begin
+ if(Board.Items[i].AgeSage = gasNull) and (Board.Items[i].IsLogFile) then begin
+ Board.IntData := Board.IntData + 1;
+ Board.Items[i].No := Board.IntData;
+ Board.Items[i].AllResCount := Board.Items[i].Count;
+ Board.Items[i].NewResCount := 0;
+ Board.Items[i].AgeSage := gasNone;
+ end;
+ end;
+ end else begin
+ //Vµ¢Xgð쬷é
+ //Vµ¢XgÉâXgÌOª éÈç»êðVµ¢XgÉÇÁ
+ //âOªÈ¯êÎAV½ÉXIuWFNgðì¬
+ Body.Text := Content;
+ NumCount := 0;
+ for i := 0 to Body.Count - 1 do begin
+ Rec := GikoSys.DivideSubject(Body[i]);
+ Rec.FFileName := Trim(Rec.FFileName);
+ if (Rec.FTitle = '') and (Rec.FCount = 0) then Continue;
+ Inc(NumCount);
+ index := Board.GetIndexFromFileName(Rec.FFileName);
+ if index = -1 then begin
+ //Vµ¢Xbh
+ NewItem := TThreadItem.Create(
+ nil, GikoSys.Get2chBoard2ThreadURL( Board, ChangeFileExt( Rec.FFileName, '' ) ) );
+ NewItem.Title := Rec.FTitle;
+ NewItem.AllResCount := Rec.FCount;
+ NewItem.ParentBoard := Board;
+ NewItem.No := NumCount;
+ NewItem.RoundDate := ZERO_DATE;
+ NewItem.LastModified := ZERO_DATE;
+ NewItem.AgeSage := gasNew;
+ Board.Add(NewItem);
+ end else begin
+ if Board.Items[index].No > NumCount then
+ Board.Items[index].AgeSage := gasAge
+ else if Board.Items[index].AllResCount < Rec.FCount then
+ Board.Items[index].AgeSage := gasSage
+ else
+ Board.Items[index].AgeSage := gasNone;
- Board.Items[index].No := NumCount;
- Board.Items[index].AllResCount := Rec.FCount;
-// if not Board.Items[index].IsLogFile then
-// Board.Items[index].Count := Rec.FCount;
- NewList.Add(Board.Items[index]);
- Board.DeleteList(index);
+ Board.Items[index].No := NumCount;
+ Board.Items[index].AllResCount := Rec.FCount;
+ end;
+ end;
+ //âXgÌí
+ for i := Board.Count - 1 downto 0 do begin
+ if( Board.Items[i].AgeSage = gasNull )and not (Board.Items[i].IsLogFile) then
+ Board.Delete(i);
end;
- end;
- //Vµ¢Xgɳ©Á½ACeðVµ¢XgÉÇÁ
- for i := 0 to Board.Count - 1 do begin
- if Board.Items[i].IsLogFile then begin
- inc(NumCount);
- Board.Items[i].No := NumCount;
- Board.Items[i].AllResCount := Board.Items[i].Count;
- Board.Items[i].NewResCount := 0;
- Board.Items[i].AgeSage := gasNone;
- NewList.Add(Board.Items[i]);
+ //Vµ¢Xgɳ©Á½ACeÌXV
+ for i := 0 to Board.Count - 1 do begin
+ if( Board.Items[i].AgeSage = gasNull )and (Board.Items[i].IsLogFile) then begin
+ inc(NumCount);
+ Board.Items[i].No := NumCount;
+ Board.Items[i].AllResCount := Board.Items[i].Count;
+ Board.Items[i].NewResCount := 0;
+ Board.Items[i].AgeSage := gasNone;
+ end;
end;
+ //Xg(subject.txt)ðÛ¶
+ GikoSys.ForceDirectoriesEx(ExtractFilePath(Board.GetSubjectFileName));
+ Body.SaveToFile(Board.GetSubjectFileName);
end;
-
- //âXgðÁ·iXgÌÝBXIuWFNg©ÌÍÁ³È¢j
- for i := Board.Count - 1 downto 0 do
- Board.DeleteList(i);
-
- //Vµ¢Xgð{[hIuWFNgÉÇÁ
- for i := 0 to NewList.Count - 1 do
- Board.Add(TThreadItem(NewList[i]));
-
- //Xg(subject.txt)ðÛ¶
-// GikoSys.ForceDirectoriesEx(GikoSys.GetLogDir + Board.BBSID);
-// Body.SaveToFile(GikoSys.GetSubjectFileName(Board.BBSID));
- GikoSys.ForceDirectoriesEx(ExtractFilePath(Board.GetSubjectFileName));
- Body.SaveToFile(Board.GetSubjectFileName);
finally
Body.Free;
- NewList.Free;
end;
+
+
end;
{procedure TDownloadItem.SaveListFile;
@@ -1045,66 +1175,134 @@ end;
}
procedure TDownloadItem.SaveItemFile;
var
- Body: TStringList;
+ Body, oldBody: TStringList;
Cnt: Integer;
OldCnt: Integer;
FileName: string;
ini: TMemIniFile;
Res: TResRec;
NewRes: Integer;
+ finish : Boolean;
+ loopCnt : Integer;
+// KokoTxt : string;
+// KokoIdx : Integer;
+// NewTxt : string;
+// NewIdx : Integer;
+// LastTxt : string;
+ LastIdx : Integer;
begin
- if Trim(Content) = '' then
- Exit;
FileName := ThreadItem.GetThreadFileName;
- GikoSys.ForceDirectoriesEx(ExtractFilePath(FileName));
-// Cnt := 0;
- Body := TStringList.Create;
- try
-// if FileExists(FileName) and (ResponseCode = 206) then begin
- if FileExists(FileName) and (State = gdsDiffComplete) then begin
-// Body.Text := Content;
-// if Body.Count > 0 then
-// Body.Delete(0);
-// Content := Body.Text;
- Body.LoadFromFile(FileName);
- OldCnt := Body.Count;
- Body.Text := Body.Text + Content;
- Body.SaveToFile(FileName);
- NewRes := Body.Count - OldCnt;
- Cnt := Body.Count;
- end else begin
- Body.Text := Content;
-// if Body.Count > 0 then
-// Body.Delete(0);
- Body.SaveToFile(FileName);
+ if not ThreadItem.IsBoardPlugInAvailable then begin
+ if Trim(Content) = '' then
+ Exit;
+
+ GikoSys.ForceDirectoriesEx(ExtractFilePath(FileName));
- if ThreadItem.Title = '' then begin
- Res := GikoSys.DivideStrLine(Body[0]);
- ThreadItem.Title := Res.FTitle;
+ // Cnt := 0;
+ Body := TStringList.Create;
+ NewRes := 0;
+ OldCnt := 0;
+ try
+ // if FileExists(FileName) and (ResponseCode = 206) then begin
+ if FileExists(FileName) and (State = gdsDiffComplete) then begin
+ loopCnt := 10;
+ repeat
+ finish := true;
+ try
+ Body.LoadFromFile(FileName);
+ OldCnt := Body.Count;
+ Body.Text := Body.Text + Content;
+ Body.SaveToFile(FileName);
+ NewRes := Body.Count - OldCnt;
+ except
+ on E:EFOpenError do begin
+ sleep(10);
+ Dec(loopCnt);
+ if loopCnt > 0 then
+ finish := false;
+ end;
+ end;
+ until finish;
+ //Cnt := Body.Count;
+ end else begin
+ if IsAbone then begin
+ // Ú[ñðoµ½Ìű±ÜÅÇñ¾ÆV
XÔ̯Ȩµ
+ oldBody := TStringList.Create;
+ try
+ loopCnt := 10;
+ repeat
+ finish := true;
+ try
+ oldBody.LoadFromFile(FileName);
+ except
+ on E:EFOpenError do begin
+ sleep(10);
+ Dec(loopCnt);
+ if loopCnt > 0 then
+ finish := false
+ else
+ finish := true;
+ end;
+ end;
+ until finish;
+
+ Body.Text := Content;
+ if (ThreadItem.Kokomade > 0) and (ThreadItem.Kokomade <= oldBody.Count) then begin
+ ThreadItem.Kokomade := Body.IndexOf(oldBody.Strings[ ThreadItem.Kokomade - 1 ]);
+ if ThreadItem.Kokomade <> -1 then ThreadItem.Kokomade := ThreadItem.Kokomade + 1;
+ end;
+
+ LastIdx := oldBody.Count;
+ repeat
+ Dec(LastIdx);
+ OldCnt := Body.IndexOf(oldBody.Strings[ LastIdx ]) + 1;
+ until ( OldCnt <> 0 ) or (LastIdx = 0);
+
+ if OldCnt >= Body.Count then OldCnt := Body.Count - 1;
+ NewRes := Body.Count - OldCnt;
+
+
+ finally
+ oldBody.Free;
+ end;
+
+ end else begin
+ Body.Text := Content;
+ //ThreadItem.Count := 0;
+ OldCnt := 0;
+ NewRes := Body.Count;
+ //Cnt := Body.Count;
+ end;
+ // if Body.Count > 0 then
+ // Body.Delete(0);
+ Body.SaveToFile(FileName);
+
+ if ThreadItem.Title = '' then begin
+ Res := GikoSys.DivideStrLine(Body[0]);
+ ThreadItem.Title := Res.FTitle;
+ end;
+ ThreadItem.Size := 0;
end;
- ThreadItem.Size := 0;
- //ThreadItem.Count := 0;
- ThreadItem.AllResCount := 0;
- ThreadItem.NewResCount := 0;
- OldCnt := 0;
- NewRes := Body.Count;
Cnt := Body.Count;
+ finally
+ Body.Free;
end;
- Cnt := Body.Count;
- finally
- Body.Free;
+
+ ThreadItem.Size := ThreadItem.Size + ContentLength;
+ ThreadItem.LastModified := LastModified;
+ ThreadItem.Count := Cnt;
+ //ThreadItem.AllResCount := Cnt;
+ ThreadItem.NewResCount := NewRes;
+ ThreadItem.NewReceive := OldCnt + 1;
end;
- ThreadItem.RoundDate := Now;
- ThreadItem.Size := ThreadItem.Size + ContentLength;
- ThreadItem.LastModified := LastModified;
- ThreadItem.Count := Cnt;
- ThreadItem.AllResCount := Cnt;
- ThreadItem.NewResCount := NewRes;
+ ThreadItem.AllResCount := ThreadItem.Count;
ThreadItem.IsLogFile := True;
- ThreadItem.NewReceive := OldCnt + 1;
- ThreadItem.UnRead := True;
- ThreadItem.ParentBoard.UnRead := ThreadItem.ParentBoard.UnRead + 1;
+ ThreadItem.RoundDate := Now;
+ if not ThreadItem.UnRead then begin
+ ThreadItem.UnRead := True;
+ ThreadItem.ParentBoard.UnRead := ThreadItem.ParentBoard.UnRead + 1;
+ end;
// if ThreadItem.RoundNo = 6 then
// ThreadItem.RoundNo := 0;