Fixed some range errors and other error in chm writing

Fixed a bug where reusing a stream would keep the size of the largest file added! Making the chm much bigger than it should be

git-svn-id: trunk@20412 -
This commit is contained in:
andrew 2012-02-23 17:59:01 +00:00
parent 78a930ae03
commit ffa54e73d9
4 changed files with 23 additions and 8 deletions

View File

@ -135,7 +135,7 @@ type
constructor Create(AStream: TStream; AFreeStreamOnDestroy: Boolean);
destructor Destroy; override;
procedure DumpData(AFoundDataEvent: TChmSearchReaderFoundDataEvent);
function LookupWord(AWord: String; out ATitleHits: TChmWLCTopicArray): TChmWLCTopicArray;
function LookupWord(AWord: String; out ATitleHits: TChmWLCTopicArray; AStartsWith: Boolean = True): TChmWLCTopicArray;
property FileIsValid: Boolean read FFileIsValid;
end;
@ -534,7 +534,11 @@ begin
FBlockStream.WriteByte(Length(NewWord)+1);
FBlockStream.WriteByte(Offset);
FBlockStream.Write(NewWord[1], Length(Trim(NewWord)));
// length can be 0 if it is the same word as the last. there is a word entry each for title and content
if Length(NewWord) > 0 then
FBlockStream.Write(NewWord[1], Length(Trim(NewWord)));
FBlockStream.WriteByte(Ord(AWord.IsTitle));
WriteCompressedIntegerBE(FBlockStream, AWord.DocumentCount);
FBlockStream.WriteDWord(NtoLE(DWord(FWriteStream.Position)));
@ -996,7 +1000,7 @@ begin
until False; //FStream.Position - FActiveNodeStart >= FIFTI_NODE_SIZE - FActiveNodeFreeSpace
end;
function TChmSearchReader.LookupWord(AWord: String; out ATitleHits: TChmWLCTopicArray): TChmWLCTopicArray;
function TChmSearchReader.LookupWord(AWord: String; out ATitleHits: TChmWLCTopicArray; AStartsWith: Boolean = True): TChmWLCTopicArray;
var
LastWord: String;
NewWord: String;
@ -1020,7 +1024,7 @@ begin
if ReadIndexNodeEntry(LastWord, NewWord, NewNodePosition) <> False then
begin
//WriteLn('Found Index Entry: ', NewWord, ' Comparing to ', AWord);
if ChmCompareText(NewWord, AWord) >= 0 then
if ChmCompareText(NewWord, AWord) >= 0 then
begin
LastWord := '';
Dec(NodeLevel);
@ -1038,7 +1042,13 @@ begin
begin
//WriteLn('Found Leaf Entry: ', NewWord, ' Comparing to ', AWord);
LastWord := NewWord;
CompareResult := ChmCompareText(AWord, NewWord);
if Length(NewWord) < Length(AWord) then
continue;
if AStartsWith then //it only has to start with the searched term
CompareResult := ChmCompareText(AWord, Copy(NewWord, 1, Length(AWord)))
else // it must match exactly
CompareResult := ChmCompareText(AWord, NewWord);
if CompareResult < 0 then
Exit;
if CompareResult = 0 then

View File

@ -209,6 +209,7 @@ begin
FSpareString.Free;
FTotalFileList.FreeAndClear;
FTotalFileList.Free;
fAllowedExtensions.Free;
inherited Destroy;
end;
@ -1052,8 +1053,8 @@ begin
Writer.FullTextSearch := MakeSearchable;
Writer.HasBinaryTOC := MakeBinaryTOC;
Writer.HasBinaryIndex := MakeBinaryIndex;
Writer.IndexName := IndexFileName;
Writer.TocName := TableOfContentsFileName;
Writer.IndexName := ExtractFileName(IndexFileName);
Writer.TocName := ExtractFileName(TableOfContentsFileName);
Writer.ReadmeMessage := ReadmeMessage;
for i:=0 to files.count-1 do
begin

View File

@ -647,6 +647,7 @@ begin
then begin
// the current file has been read. move to the next file in the list
FCurrentStream.Position := 0;
FCurrentStream.Size:=0;
Inc(FCurrentIndex);
ForceExit := OnGetFileData(FFileNames[FCurrentIndex], FileEntry.Path, FileEntry.Name, FCurrentStream);
FileEntry.DecompressedSize := FCurrentStream.Size;

View File

@ -421,7 +421,10 @@ begin
Inc(pathlength);
end;
leaves[i].code := cur_code;
Inc(cur_code);
{$PUSH}
{$R-}
Inc(cur_code); // range error but i = 0 so it's harmless
{$POP}
end;
//#endif