OSDN Git Service

初回Tabファイル保存時にエラーメッセージが出るのを修正
[gikonavigoeson/gikonavi.git] / ItemDownload.pas
index 0035ce8..fe0fb18 100644 (file)
@@ -156,9 +156,7 @@ var
        Idx: Integer;
        ATitle: string;
        DownloadResult: Boolean;
        Idx: Integer;
        ATitle: string;
        DownloadResult: Boolean;
-       foundPos: Integer;
        boardPlugIn     : TBoardPlugIn;
        boardPlugIn     : TBoardPlugIn;
-       listContent     : string;
        lastContent             : string;
        logFile                         : TFileStream;
        adjustMargin    : Integer;
        lastContent             : string;
        logFile                         : TFileStream;
        adjustMargin    : Integer;
@@ -1177,7 +1175,7 @@ end;
 }
 procedure TDownloadItem.SaveItemFile;
 var
 }
 procedure TDownloadItem.SaveItemFile;
 var
-       Body: TStringList;
+       Body, oldBody: TStringList;
        Cnt: Integer;
        OldCnt: Integer;
        FileName: string;
        Cnt: Integer;
        OldCnt: Integer;
        FileName: string;
@@ -1186,11 +1184,11 @@ var
        NewRes: Integer;
        finish : Boolean;
        loopCnt : Integer;
        NewRes: Integer;
        finish : Boolean;
        loopCnt : Integer;
-       KokoTxt : string;
-       KokoIdx : Integer;
-       NewTxt  : string;
-       NewIdx  : Integer;
-       LastTxt : string;
+//     KokoTxt : string;
+//     KokoIdx : Integer;
+//     NewTxt  : string;
+//     NewIdx  : Integer;
+//     LastTxt : string;
        LastIdx : Integer;
 begin
        FileName := ThreadItem.GetThreadFileName;
        LastIdx : Integer;
 begin
        FileName := ThreadItem.GetThreadFileName;
@@ -1208,10 +1206,6 @@ begin
                try
                //              if FileExists(FileName) and (ResponseCode = 206) then begin
                        if FileExists(FileName) and (State = gdsDiffComplete) then begin
                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;
                                loopCnt := 10;
                                repeat
                                        finish := true;
                                loopCnt := 10;
                                repeat
                                        finish := true;
@@ -1224,61 +1218,58 @@ begin
                                        except
                                                on E:EFOpenError do begin
                                                        sleep(10);
                                        except
                                                on E:EFOpenError do begin
                                                        sleep(10);
-                                                       finish := false;
                                                        Dec(loopCnt);
                                                        Dec(loopCnt);
+                                                       if loopCnt > 0 then
+                                                               finish := false;
                                                end;
                                        end;
                                                end;
                                        end;
-                               until finish and ( loopCnt > 0 );
+                               until finish;
                                //Cnt := Body.Count;
                        end else begin
                                if IsAbone then begin
                                        // \82 \82Ú\81[\82ñ\82ð\8c\9f\8fo\82µ\82½\82Ì\82Å\82±\82±\82Ü\82Å\93Ç\82ñ\82¾\82Æ\90V\92\85\83\8c\83X\94Ô\82Ì\82Â\82¯\82È\82¨\82µ
                                //Cnt := Body.Count;
                        end else begin
                                if IsAbone then begin
                                        // \82 \82Ú\81[\82ñ\82ð\8c\9f\8fo\82µ\82½\82Ì\82Å\82±\82±\82Ü\82Å\93Ç\82ñ\82¾\82Æ\90V\92\85\83\8c\83X\94Ô\82Ì\82Â\82¯\82È\82¨\82µ
-                                       loopCnt := 10;
-                                       repeat
-                                               finish := true;
-                                               try
-                                                       Body.LoadFromFile(FileName);
-                                               except
-                                                       on E:EFOpenError do begin
-                                                               sleep(10);
-                                                               finish := false;
-                                                               Dec(loopCnt);
+                                       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;
                                                        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;
                                                end;
-                                       until finish and ( loopCnt > 0 );
-                                       LastTxt := Body.Strings[ ThreadItem.Count - 1 ];
-                                       if ThreadItem.Kokomade > 0 then begin
-                                               KokoTxt := Body.Strings[ ThreadItem.Kokomade - 1 ];
-                                       end;
-                                       if ThreadItem.NewReceive > 0 then begin
-                                               NewTxt := Body.Strings[ ThreadItem.NewReceive - 1 ];
-                                       end;
 
 
-                                       Body.Text := Content;
-                                       ThreadItem.AllResCount := 0;
-                                       ThreadItem.NewResCount := 0;
-                                       NewRes := Body.Count;
+                                               LastIdx := oldBody.Count;
+                                               repeat
+                                                       Dec(LastIdx);
+                                                       OldCnt := Body.IndexOf(oldBody.Strings[ LastIdx ]) + 1;
+                                               until ( OldCnt <> 0 ) or (LastIdx = 0);
 
 
-                                       Body.Find( LastTxt, LastIdx );
-                                       OldCnt := LastIdx + 1;
-                                       if ThreadItem.Kokomade > 0 then begin
-                                               Body.Find( KokoTxt, KokoIdx );
-                                               ThreadItem.Kokomade := KokoIdx + 1;
-                                       end;
-                                       if ThreadItem.NewReceive > 0 then begin
-                                               Body.Find( NewTxt, NewIdx );
-                                               Inc( NewIdx );
-                                               ThreadItem.AllResCount := NewIdx;
-                                               if OldCnt >= NewIdx then
-                                                       NewRes := Body.Count - OldCnt
-                                               else
-                                                       NewRes := Body.Count - NewIdx;
+                                               if OldCnt >= Body.Count then OldCnt := Body.Count - 1;
+                                               NewRes := Body.Count - OldCnt;
+
+
+                                       finally
+                                               oldBody.Free;
                                        end;
                                        end;
+
                                end else begin
                                        Body.Text := Content;
                                        //ThreadItem.Count := 0;
                                end else begin
                                        Body.Text := Content;
                                        //ThreadItem.Count := 0;
-                                       ThreadItem.AllResCount := 0;
-                                       ThreadItem.NewResCount := 0;
                                        OldCnt := 0;
                                        NewRes := Body.Count;
                                        //Cnt := Body.Count;
                                        OldCnt := 0;
                                        NewRes := Body.Count;
                                        //Cnt := Body.Count;
@@ -1308,8 +1299,10 @@ begin
        ThreadItem.AllResCount := ThreadItem.Count;
        ThreadItem.IsLogFile := True;
        ThreadItem.RoundDate := Now;
        ThreadItem.AllResCount := ThreadItem.Count;
        ThreadItem.IsLogFile := True;
        ThreadItem.RoundDate := Now;
-       ThreadItem.UnRead := True;
-       ThreadItem.ParentBoard.UnRead := ThreadItem.ParentBoard.UnRead + 1;
+       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;
 
 //     if ThreadItem.RoundNo = 6 then
 //             ThreadItem.RoundNo := 0;