Develop and Download Open Source Software

Browse CVS Repository

Diff of /gikonavigoeson/gikonavi/ItemDownload.pas

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

revision 1.29 by yoffy, Mon Jul 12 02:02:02 2004 UTC revision 1.30 by yoffy, Mon Aug 2 16:36:52 2004 UTC
# Line 59  type Line 59  type
59                  property Item: TDownloadItem read FItem write FItem;                  property Item: TDownloadItem read FItem write FItem;
60                  property Number: Integer read FNumber write FNumber;                  property Number: Integer read FNumber write FNumber;
61                  constructor Create(CreateSuspended: Boolean);                  constructor Create(CreateSuspended: Boolean);
62          destructor Destroy; override;                                  destructor Destroy; override;
63                  procedure Abort;                  procedure Abort;
64                  property OnWork: TGikoWorkEvent read FOnWork write FOnWork;                  property OnWork: TGikoWorkEvent read FOnWork write FOnWork;
65                  property OnWorkBegin: TGikoWorkBeginEvent read FOnWorkBegin write FOnWorkBegin;                  property OnWorkBegin: TGikoWorkBeginEvent read FOnWorkBegin write FOnWorkBegin;
# Line 81  type Line 81  type
81                  FState: TGikoDownloadState;                  FState: TGikoDownloadState;
82                  FErrText: string;                  FErrText: string;
83                  FForceDownload: Boolean;                  FForceDownload: Boolean;
84                    FIsAbone : Boolean;
85          public          public
86                  procedure SaveListFile;                  procedure SaveListFile;
87                  procedure SaveItemFile;                  procedure SaveItemFile;
# Line 96  type Line 97  type
97                  property State: TGikoDownloadState read FState write FState;                  property State: TGikoDownloadState read FState write FState;
98                  property ErrText: string read FErrText write FErrText;                  property ErrText: string read FErrText write FErrText;
99                  property ForceDownload: Boolean read FForceDownload write FForceDownload;                  property ForceDownload: Boolean read FForceDownload write FForceDownload;
100                    property IsAbone : Boolean read FIsAbone write FIsAbone;
101          end;          end;
102    
103  implementation  implementation
# Line 153  var Line 155  var
155          Idx: Integer;          Idx: Integer;
156          ATitle: string;          ATitle: string;
157          DownloadResult: Boolean;          DownloadResult: Boolean;
         Abone: Boolean;  
158          foundPos: Integer;          foundPos: Integer;
159          boardPlugIn     : TBoardPlugIn;          boardPlugIn     : TBoardPlugIn;
160          listContent     : string;          listContent     : string;
# Line 338  begin Line 339  begin
339                                                  end;                                                  end;
340                                          end;                                          end;
341                                  end;                                  end;
342                                  Abone := False;                                  Item.IsAbone := False;
343                                  DownloadResult := DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen);                                  DownloadResult := DatDownload(Item.DownType, URL, Modified, RangeStart, AdjustLen);
344                                  {$IFDEF DEBUG}                                  {$IFDEF DEBUG}
345                                  Writeln('ResponseCode: ' + IntToStr(FIndy.ResponseCode));                                  Writeln('ResponseCode: ' + IntToStr(FIndy.ResponseCode));
346                                  {$ENDIF}                                  {$ENDIF}
347                                  if Item.DownType = gdtThread then begin                                  if Item.DownType = gdtThread then begin
348                                          if Item.ResponseCode = 416 then begin                                          if Item.ResponseCode = 416 then begin
349                                                  Abone := True;                                                  Item.IsAbone := True;
350                                                  DownloadResult := True;                                                  DownloadResult := True;
351                                          end else if DownloadResult and (AdjustLen < 0) then begin                                          end else if DownloadResult and (AdjustLen < 0) then begin
352                                                  if Copy( Item.Content, 1, adjustMargin ) <> lastContent then                                                  if Copy( Item.Content, 1, adjustMargin ) <> lastContent then
353                                                          Abone := True;                                                          Item.IsAbone := True;
354                                          end;                                          end;
355                                  end;                                  end;
356    
# Line 364  begin Line 365  begin
365                                          {$IFDEF DEBUG}                                          {$IFDEF DEBUG}
366                                          Writeln('Date:' + FIndy.Response.RawHeaders.Values['Date']);                                          Writeln('Date:' + FIndy.Response.RawHeaders.Values['Date']);
367                                          {$ENDIF}                                          {$ENDIF}
368                                          if Abone then begin                                          if Item.IsAbone then begin
369                                                  {$IFDEF DEBUG}                                                  {$IFDEF DEBUG}
370                                                  Writeln('あぼーん検出');                                                  Writeln('あぼーん検出');
371                                                  {$ENDIF}                                                  {$ENDIF}
# Line 1172  var Line 1173  var
1173          ini: TMemIniFile;          ini: TMemIniFile;
1174          Res: TResRec;          Res: TResRec;
1175          NewRes: Integer;          NewRes: Integer;
1176      finish : Boolean;          finish : Boolean;
1177      loopCnt : Integer;          loopCnt : Integer;
1178            KokoTxt : string;
1179            KokoIdx : Integer;
1180            NewTxt  : string;
1181            NewIdx  : Integer;
1182            LastTxt : string;
1183            LastIdx : Integer;
1184  begin  begin
1185          FileName := ThreadItem.GetThreadFileName;          FileName := ThreadItem.GetThreadFileName;
1186    
1187          if not ThreadItem.IsBoardPlugInAvailable then begin          if not ThreadItem.IsBoardPlugInAvailable then begin
1188                  if Trim(Content) = '' then                  if Trim(Content) = '' then
1189                          Exit;                          Exit;
1190    
1191                  GikoSys.ForceDirectoriesEx(ExtractFilePath(FileName));                  GikoSys.ForceDirectoriesEx(ExtractFilePath(FileName));
1192    
1193          //      Cnt := 0;                  //      Cnt := 0;
1194                  Body := TStringList.Create;                  Body := TStringList.Create;
1195          NewRes := 0;                  NewRes := 0;
1196          OldCnt := 0;                  OldCnt := 0;
1197                  try                  try
1198          //              if FileExists(FileName) and (ResponseCode = 206) then begin                  //              if FileExists(FileName) and (ResponseCode = 206) then begin
1199                          if FileExists(FileName) and (State = gdsDiffComplete) then begin                          if FileExists(FileName) and (State = gdsDiffComplete) then begin
1200          //                      Body.Text := Content;                  //                      Body.Text := Content;
1201          //                      if Body.Count > 0 then                  //                      if Body.Count > 0 then
1202          //                              Body.Delete(0);                  //                              Body.Delete(0);
1203          //                      Content := Body.Text;                  //                      Content := Body.Text;
1204                  loopCnt := 10;                                  loopCnt := 10;
1205                                  repeat                                  repeat
1206                      finish := true;                                          finish := true;
1207                          try                                          try
1208                                                  Body.LoadFromFile(FileName);                                                  Body.LoadFromFile(FileName);
1209                                                  OldCnt := Body.Count;                                                  OldCnt := Body.Count;
1210                                                  Body.Text := Body.Text + Content;                                                  Body.Text := Body.Text + Content;
1211                                                  Body.SaveToFile(FileName);                                                  Body.SaveToFile(FileName);
1212                                                  NewRes := Body.Count - OldCnt;                                                  NewRes := Body.Count - OldCnt;
1213                          except                                          except
1214                                  on E:EFOpenError do begin                                                  on E:EFOpenError do begin
1215                              sleep(10);                                                          sleep(10);
1216                                  finish := false;                                                          finish := false;
1217                              Dec(loopCnt);                                                          Dec(loopCnt);
1218                          end;                                                  end;
1219                          end;                                          end;
1220                  until finish and ( loopCnt > 0 );                                  until finish and ( loopCnt > 0 );
1221                                  //Cnt := Body.Count;                                  //Cnt := Body.Count;
1222                          end else begin                          end else begin
1223                                  Body.Text := Content;                                  if IsAbone then begin
1224                                            // あぼーんを検出したのでここまで読んだと新着レス番のつけなおし
1225                                            loopCnt := 10;
1226                                            repeat
1227                                                    finish := true;
1228                                                    try
1229                                                            Body.LoadFromFile(FileName);
1230                                                    except
1231                                                            on E:EFOpenError do begin
1232                                                                    sleep(10);
1233                                                                    finish := false;
1234                                                                    Dec(loopCnt);
1235                                                            end;
1236                                                    end;
1237                                            until finish and ( loopCnt > 0 );
1238                                            LastTxt := Body.Strings[ ThreadItem.Count - 1 ];
1239                                            if ThreadItem.Kokomade > 0 then begin
1240                                                    KokoTxt := Body.Strings[ ThreadItem.Kokomade - 1 ];
1241                                            end;
1242                                            if ThreadItem.NewReceive > 0 then begin
1243                                                    NewTxt := Body.Strings[ ThreadItem.NewReceive - 1 ];
1244                                            end;
1245    
1246                                            Body.Text := Content;
1247                                            ThreadItem.AllResCount := 0;
1248                                            ThreadItem.NewResCount := 0;
1249                                            NewRes := Body.Count;
1250    
1251                                            Body.Find( LastTxt, LastIdx );
1252                                            OldCnt := LastIdx + 1;
1253                                            if ThreadItem.Kokomade > 0 then begin
1254                                                    Body.Find( KokoTxt, KokoIdx );
1255                                                    ThreadItem.Kokomade := KokoIdx + 1;
1256                                            end;
1257                                            if ThreadItem.NewReceive > 0 then begin
1258                                                    Body.Find( NewTxt, NewIdx );
1259                                                    Inc( NewIdx );
1260                                                    ThreadItem.AllResCount := NewIdx;
1261                                                    if OldCnt >= NewIdx then
1262                                                            NewRes := Body.Count - OldCnt
1263                                                    else
1264                                                            NewRes := Body.Count - NewIdx;
1265                                            end;
1266                                    end else begin
1267                                            Body.Text := Content;
1268                                            //ThreadItem.Count := 0;
1269                                            ThreadItem.AllResCount := 0;
1270                                            ThreadItem.NewResCount := 0;
1271                                            OldCnt := 0;
1272                                            NewRes := Body.Count;
1273                                            //Cnt := Body.Count;
1274                                    end;
1275          //                      if Body.Count > 0 then          //                      if Body.Count > 0 then
1276          //                              Body.Delete(0);          //                              Body.Delete(0);
1277                                  Body.SaveToFile(FileName);                                  Body.SaveToFile(FileName);
# Line 1222  begin Line 1281  begin
1281                                          ThreadItem.Title := Res.FTitle;                                          ThreadItem.Title := Res.FTitle;
1282                                  end;                                  end;
1283                                  ThreadItem.Size := 0;                                  ThreadItem.Size := 0;
                                 //ThreadItem.Count := 0;  
                                 ThreadItem.AllResCount := 0;  
                                 ThreadItem.NewResCount := 0;  
                                 OldCnt := 0;  
                                 NewRes := Body.Count;  
                                 //Cnt := Body.Count;  
1284                          end;                          end;
1285                          Cnt := Body.Count;                          Cnt := Body.Count;
1286                  finally                  finally
1287                          Body.Free;                          Body.Free;
1288                  end;                  end;
1289            
1290                  ThreadItem.Size := ThreadItem.Size + ContentLength;                  ThreadItem.Size := ThreadItem.Size + ContentLength;
1291                  ThreadItem.LastModified := LastModified;                  ThreadItem.LastModified := LastModified;
1292                  ThreadItem.Count := Cnt;                  ThreadItem.Count := Cnt;
# Line 1241  begin Line 1294  begin
1294                  ThreadItem.NewResCount := NewRes;                  ThreadItem.NewResCount := NewRes;
1295                  ThreadItem.NewReceive := OldCnt + 1;                  ThreadItem.NewReceive := OldCnt + 1;
1296          end;          end;
1297      ThreadItem.AllResCount := ThreadItem.Count;          ThreadItem.AllResCount := ThreadItem.Count;
1298          ThreadItem.IsLogFile := True;          ThreadItem.IsLogFile := True;
1299          ThreadItem.RoundDate := Now;          ThreadItem.RoundDate := Now;
1300          ThreadItem.UnRead := True;          ThreadItem.UnRead := True;
# Line 1264  begin Line 1317  begin
1317  //              ini.WriteInteger('Setting', 'RoundNo', ThreadItem.RoundNo);  //              ini.WriteInteger('Setting', 'RoundNo', ThreadItem.RoundNo);
1318                  ini.WriteBool('Setting', 'Round', ThreadItem.Round);                  ini.WriteBool('Setting', 'Round', ThreadItem.Round);
1319                  ini.WriteBool('Setting', 'UnRead', ThreadItem.UnRead);                  ini.WriteBool('Setting', 'UnRead', ThreadItem.UnRead);
1320          ini.UpdateFile;                  ini.UpdateFile;
1321          finally          finally
1322                  ini.Free;                  ini.Free;
1323          end;          end;

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

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