anchor.diff:  implementation
   
   uses
  -  FileUtil,
  -  mUtility;
  +  FileUtil, LazFileUtils,
  +  mUtility, mMathUtility;
   
   { TmConsolePublisher }
   
  
positive.code: procedure TmFilePublisher.Publish(aContext, aLevel, aMessage: string; aDate: TDateTime);
  var
    s: RawByteString;
  begin
    if FFileName <> '' then
    begin
      if not Assigned(FFileStream) then
      begin
        if FileExists(FFileName) then
        begin
          (*
          if (FMaxFileSizeInMb > 0) and ((FileUtil.FileSize(FFileName) div 1024) > FMaxFileSizeInMb) then
          begin
            RenameFile(FFileName, FFileName + '.bak');
          end;
          *)
          FFileStream := TFileStream.Create(FFileName, fmOpenWrite);
          FFileStream.Seek(0, soFromEnd);
        end
        else
        begin
          FFileStream := TFileStream.Create(FFileName, fmCreate);
          AddUTF8BOMToStream(FFileStream);
        end;
      end;
  
negative.code:   Result := false;
  end;
  
  function TmFilePublisher.EncodeFileName(const aDay: integer): String;
  begin
    if FFileFolder = '' then
      FFileFolder := ExtractFileDir(FFileName);
    if FFileNameTemplate = '' then
      FFileNameTemplate:= LazFileUtils.ExtractFileNameOnly(FFileName);
    Result := IncludeTrailingPathDelimiter(FFileFolder) + mUtility.GetTimeStampForFileName(aDay, false) + FFileNameTemplate;
  end;
  
  function TmFilePublisher.DecodeFileName(const aFileName: String): integer;
  var
    tmp : String;
  begin
    Result := -1;
    tmp := LazFileUtils.ExtractFileNameOnly(aFileName);
    if Length(tmp) >= 8 then
    begin
      tmp := Copy(tmp, 1, 8);
      if IsNumeric(tmp, false) then
        Result := round(DecodeTimeStampForFileName(tmp));
    end;
  end;
  
  procedure TmFilePublisher.ClearOldLogFiles;
  var
    tmpFiles : TStringList;
    i, curDay : integer;
  begin
    if FCycleEveryDay and (FKeepDays > 0) then
    begin
      tmpFiles := TStringList.Create;
      try
        FindAllFiles(tmpFiles, FFileFolder, '*' + FFileNameTemplate);
        for i := 0 to tmpFiles.Count - 1 do
        begin
          curDay := DecodeFileName(tmpFiles.Strings[i]);
          if curDay > 0 then
          begin
            if (round(Date) - curDay) > FKeepDays then
              DeleteFile(tmpFiles.Strings[i]);
          end;
        end;
      finally
        tmpFiles.Free;
      end;
    end;
  end;
  
  procedure TmFilePublisher.AfterCreate;
  begin
    FFileName := '';
    FFileFolder:= '';
    FFileNameTemplate:= '';
    FFileStream := nil;
    FCycleEveryDay := false;
    FKeepDays := 0;
    FFileDay := 0;
  end;
  
  destructor TmFilePublisher.Destroy;
  