* Added support for binary toc and index support from fpc

git-svn-id: trunk@22097 -
This commit is contained in:
andrew 2009-10-11 16:36:22 +00:00
parent 1f47e04ef2
commit b7d39f719c
3 changed files with 40 additions and 30 deletions

View File

@ -5,9 +5,15 @@ unit chmcontentprovider;
//{$if (fpc_version=2) and (fpc_release>2) ((fpc_version=2) and (fpc_release=2) and (fpc_patch>2))}
{$Note Compiling lhelp with search support}
{$DEFINE CHM_SEARCH}
//{$else}
//{$Note Compiling lhelp *without* search support since your fpc version is not new enough}
//{$endif}
{$if (fpc_version=2) and (fpc_release>5) ((fpc_version=2) and (fpc_release=5) and (fpc_patch>0))}
{$Note Compiling lhelp *with* binary index and toc support}
{$DEFINE CHM_BINARY_INDEX_TOC}
{$endif}
{off $DEFINE CHM_DEBUG_TIME}
{off $DEFINE CHM_SEARCH}
@ -96,7 +102,7 @@ type
implementation
uses ChmSpecialParser{$IFDEF CHM_SEARCH}, chmFIftiMain{$ENDIF}, LCLType;
uses ChmSpecialParser{$IFDEF CHM_SEARCH}, chmFIftiMain{$ENDIF}, chmsitemap, LCLType;
function GetURIFileName(AURI: String): String;
var
@ -289,6 +295,7 @@ var
fChm: TChmReader;
ParentNode: TTreeNode;
i: Integer;
SM: TChmSiteMap;
HasSearchIndex: Boolean = False;
begin
if fFillingToc = True then begin
@ -307,17 +314,26 @@ begin
ParentNode := fContentsTree.Items.AddChildObject(nil, fChm.Title, fChm);
ParentNode.ImageIndex := 0;
ParentNode.SelectedIndex := 0;
{$IFDEF CHM_BINARY_INDEX_TOC}
SM := fChm.GetTOCSitemap;
{$ELSE}
Stream := TMemoryStream(fchm.GetObject(fChm.TOCFile));
if Stream <> nil then begin
Stream.position := 0;
SM := TChmSiteMap.Create(stTOC);
SM.LoadFromStream(Stream);
Stream.Free;
end;
{$ENDIF}
if SM <> nil then begin
{$IFDEF CHM_DEBUG_TIME}
writeln('Stream read: ',FormatDateTime('hh:nn:ss.zzz', Now));
{$ENDIF}
with TContentsFiller.Create(fContentsTree, Stream, @fStopTimer, fChm) do begin
with TContentsFiller.Create(fContentsTree, SM, @fStopTimer, fChm) do begin
DoFill(ParentNode);
Free;
end;
Stream.Free;
SM.Free;
if (fContentsTree.Selected = nil) and (fHistory.Count > 0) then
SelectTreeItemFromURL(fHistory.Strings[fHistoryIndex]);
end;
@ -326,14 +342,22 @@ begin
// we fill the index here too but only for the main file
if fChms.IndexOfObject(fChm) < 1 then
begin
Stream := fchms.GetObject(fChm.IndexFile);
{$IFDEF CHM_BINARY_INDEX_TOC}
SM := fChm.GetTOCSitemap;
{$ELSE}
Stream := TMemoryStream(fchm.GetObject(fChm.TOCFile));
if Stream <> nil then begin
Stream.position := 0;
with TIndexFiller.Create(fIndexView, Stream, fChm) do begin;
SM := TChmSiteMap.Create(stTOC);
SM.LoadFromStream(Stream);
Stream.Free;
end;
{$ENDIF}
if SM <> nil then begin
with TIndexFiller.Create(fIndexView, SM, fChm) do begin
DoFill;
Free;
end;
Stream.Free;
SM.Free;
end;
end;
end;

View File

@ -56,8 +56,7 @@ type
procedure CustomCreateContentTreeItem(Sender: TCustomTreeView; var ATreeNode: TTreenode);
procedure AddItem(AItem: TChmSiteMapItem; AParentNode: TTreeNode);
public
constructor Create(ATreeView: TTreeView; AStream: TStream; StopBoolean: PBoolean; AChm: TObject);
destructor Destroy; override;
constructor Create(ATreeView: TTreeView; ASitemap: TChmSiteMap; StopBoolean: PBoolean; AChm: TObject);
procedure DoFill(ParentNode: TTreeNode);
end;
@ -70,8 +69,7 @@ type
fChm: Tobject;
procedure AddItem(Item: TChmSiteMapItem; ASubItem: Boolean);
public
constructor Create(AListView: TListView; AStream: TStream; AChm: TObject);
destructor Destroy; override;
constructor Create(AListView: TListView; ASiteMap: TChmSiteMap; AChm: TObject);
procedure DoFill;
end;
@ -123,22 +121,15 @@ begin
AddItem(AItem.Children.Item[X], NewNode);
end;
constructor TContentsFiller.Create(ATreeView: TTreeView; AStream: TStream; StopBoolean: PBoolean; AChm: TObject);
constructor TContentsFiller.Create(ATreeView: TTreeView; ASitemap: TChmSiteMap; StopBoolean: PBoolean; AChm: TObject);
begin
inherited Create;
fTreeView := ATreeView;
fSitemap := TChmSiteMap.Create(stTOC);
fSitemap.LoadFromStream(AStream);
fSitemap := ASitemap;
fStop := StopBoolean;
fChm := AChm;
end;
destructor TContentsFiller.Destroy;
begin
fSitemap.Free;
inherited Destroy;
end;
procedure TContentsFiller.DoFill(ParentNode: TTreeNode);
var
OrigEvent: TTVCustomCreateNodeEvent;
@ -178,19 +169,13 @@ begin
end;
constructor TIndexFiller.Create(AListView: TListView; AStream: TStream; AChm: TObject);
constructor TIndexFiller.Create(AListView: TListView; ASiteMap: TChmSiteMap; AChm: TObject);
begin
inherited Create;
fListView := AListView;
fSitemap := TChmSiteMap.Create(stIndex);
fSitemap.LoadFromStream(AStream);
fSitemap := ASiteMap;
fChm := AChm;
end;
destructor TIndexFiller.Destroy;
begin
fSitemap.Free;
inherited Destroy;
end;
procedure TIndexFiller.DoFill;

View File

@ -254,7 +254,8 @@ begin
//WriteLn('LeftLoop');
Result:= fHttpClient.Stream;
Result.Position := 0;
if Result <> nil then
Result.Position := 0;
//fDataStream.SaveToFile('temp.txt');
//Application.Terminate;
fHttpClient.Free;