From b7d39f719ce1a4675aeed7f92bedf31564890ffc Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 11 Oct 2009 16:36:22 +0000 Subject: [PATCH] * Added support for binary toc and index support from fpc git-svn-id: trunk@22097 - --- .../chmhelp/lhelp/chmcontentprovider.pas | 40 +++++++++++++++---- components/chmhelp/lhelp/chmspecialparser.pas | 27 +++---------- .../chmhelp/lhelp/lnethttpdataprovider.pas | 3 +- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/components/chmhelp/lhelp/chmcontentprovider.pas b/components/chmhelp/lhelp/chmcontentprovider.pas index c13a76725b..05ec7baf50 100644 --- a/components/chmhelp/lhelp/chmcontentprovider.pas +++ b/components/chmhelp/lhelp/chmcontentprovider.pas @@ -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; diff --git a/components/chmhelp/lhelp/chmspecialparser.pas b/components/chmhelp/lhelp/chmspecialparser.pas index a42dc94251..89b49525f2 100644 --- a/components/chmhelp/lhelp/chmspecialparser.pas +++ b/components/chmhelp/lhelp/chmspecialparser.pas @@ -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; diff --git a/components/chmhelp/lhelp/lnethttpdataprovider.pas b/components/chmhelp/lhelp/lnethttpdataprovider.pas index 1cc353764c..2192b57637 100644 --- a/components/chmhelp/lhelp/lnethttpdataprovider.pas +++ b/components/chmhelp/lhelp/lnethttpdataprovider.pas @@ -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;