* Am now able to generate helpfiles with contextids from xml via chmfilewriter. XML format needs some rethinking though.

git-svn-id: trunk@14499 -
This commit is contained in:
marco 2009-12-29 23:33:34 +00:00
parent c8f3925944
commit 9efa49b468
2 changed files with 50 additions and 20 deletions

View File

@ -59,6 +59,7 @@ type
procedure SaveToFile(AFileName: String);
procedure WriteChm(AOutStream: TStream);
function ProjectDir: String;
procedure AddFileWithContext(contextid:integer;filename:ansistring;contextname:ansistring='');
// though stored in the project file, it is only there for the program that uses the unit
// since we actually write to a stream
property OutputFileName: String read FOutputFileName write FOutputFileName;
@ -77,17 +78,16 @@ type
property OnProgress: TChmProgressCB read FOnProgress write FOnProgress;
end;
implementation
uses XmlCfg, chmsitemap;
Type
TChmContextNode = Class
URLName : AnsiString;
ContextNumber : Integer;
ContextName : AnsiString;
End;
implementation
uses XmlCfg, chmsitemap;
{ TChmProject }
function TChmProject.GetData(const DataName: String; out PathInChm: String; out
@ -129,7 +129,7 @@ begin
IndexSitemap := TChmSiteMap.Create(stIndex);
indexSitemap.LoadFromStream(IndexStream);
Writer.AppendBinaryIndexFromSiteMap(IndexSitemap,False);
IndexSitemap.Free;
IndexSitemap.Free;
end;
IndexStream.Free;
end;
@ -162,12 +162,13 @@ begin
FFiles.Free;
inherited Destroy;
end;
procedure TChmProject.LoadFromFile(AFileName: String);
var
Cfg: TXMLConfig;
FileCount: Integer;
I : Integer;
nd : TChmContextNode;
nd : TChmContextNode;
begin
Cfg := TXMLConfig.Create(nil);
Cfg.Filename := AFileName;
@ -175,12 +176,12 @@ begin
Files.Clear;
FileCount := Cfg.GetValue('Files/Count/Value', 0);
for I := 0 to FileCount-1 do
for I := 0 to FileCount-1 do
begin
nd:=TChmContextNode.Create;
nd:=TChmContextNode.Create;
nd.urlname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/Value','');
nd.contextnumber:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextNumber',0);
nd.contextname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextName','');
nd.contextname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextName','');
Files.AddObject(nd.urlname,nd);
end;
IndexFileName := Cfg.GetValue('Files/IndexFile/Value','');
@ -197,6 +198,33 @@ begin
Cfg.Free;
end;
procedure TChmProject.AddFileWithContext(contextid:integer;filename:ansistring;contextname:ansistring='');
var x : integer;
nd : TChmContextNode;
begin
x:=files.indexof(filename);
if x=-1 then
begin
nd:=TChmContextNode.Create;
nd.urlname:=filename;
nd.contextnumber:=contextid;
nd.contextname:=contextname;
Files.AddObject(nd.urlname,nd);
end
else
begin
nd:=TChmContextNode(files.objects[x]);
if not assigned(nd) then
begin
nd:=TChmContextNode.Create;
nd.urlname:=filename;
files.objects[x]:=nd;
end;
nd.contextnumber:=contextid;
nd.contextname:=contextname;
end;
end;
procedure TChmProject.SaveToFile(AFileName: String);
var
Cfg: TXMLConfig;
@ -208,7 +236,7 @@ begin
Cfg.Filename := FileName;
Cfg.Clear;
Cfg.SetValue('Files/Count/Value', Files.Count);
for I := 0 to Files.Count-1 do
for I := 0 to Files.Count-1 do
begin
nd:=TChmContextNode(files.objects[i]);
Cfg.SetValue('Files/FileName'+IntToStr(I)+'/Value', Files.Strings[I]);
@ -216,7 +244,7 @@ begin
begin
Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextNumber', nd.contextnumber);
Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextName', nd.contextname);
end;
end;
end;
Cfg.SetValue('Files/IndexFile/Value', IndexFileName);
Cfg.SetValue('Files/TOCFile/Value', TableOfContentsFileName);
@ -268,7 +296,8 @@ begin
for i:=0 to files.count-1 do
begin
nd:=TChmContextNode(files.objects[i]);
Writer.AddContext(nd.ContextNumber,files[i]);
if assigned(nd) and (nd.contextnumber<>0) then
Writer.AddContext(nd.ContextNumber,files[i]);
end;
// and write!

View File

@ -204,7 +204,7 @@ const
procedure logentry(s:string);
begin
Writeln(s);
flush(stdout);
flush(stdout);
end;
{$endif}
{$I chmobjinstconst.inc}
@ -1883,17 +1883,17 @@ Var i : Integer;
EntryBytes : Integer;
Hdr : TBTreeHeader;
TreeDepth : Integer;
{$ifdef binindex}
procedure printloopvars(i:integer);
begin
begin
Writeln('location :' ,i, ' blocknr :', blocknr,' level:',TreeDepth);
Writeln('blockn length: ',length(blockn),' indexblocknr: ',indexblocknr,' blockind ',blockind);
Writeln('blocknplus1 length: ',length(blocknplus1),' blocknplusindex:',blocknplusindex,' entries:',blocknplusentries);
flush(stdout);
end;
{$endif}
{$endif}
begin
IndexStream:=TMemoryStream.Create;
indexstream.size:=sizeof(TBTreeHeader);
@ -1955,7 +1955,7 @@ begin
{$endif}
FinalizeIndexBlockN(@blockn[indexblocknr][0],blockind,blockentries); // also increasing indexblocknr
inc(IndexBlockNr);
end;
end;
{$ifdef binindex}
writeln('binindex: listingblocks : '+inttostr(listingblocks),' indexblocks: ',indexblocknr,' entries:',blockentries);
{$endif}
@ -2058,11 +2058,11 @@ procedure stadd(fn:string;stream:TStream);
begin
Stream.Position:=0;
if CHW then
if CHW then
fn:=uppercase(fn);
{$ifdef binindex}
logentry('before append '+fn);
{$endif}
{$endif}
AddStreamToArchive(fn,'/$WWKeywordLinks/',stream,True);
end;
@ -2090,6 +2090,7 @@ var
Offset: DWord;
begin
if FContextStream = nil then begin
FContextStream:=TMemoryStream.Create;
// #IVB starts with a dword which is the size of the stream - sizeof(dword)
FContextStream.WriteDWord(0);
// we will update this when we write the file to the final stream