|
@@ -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,6 +78,12 @@ type
|
|
|
property OnProgress: TChmProgressCB read FOnProgress write FOnProgress;
|
|
|
end;
|
|
|
|
|
|
+ TChmContextNode = Class
|
|
|
+ URLName : AnsiString;
|
|
|
+ ContextNumber : Integer;
|
|
|
+ ContextName : AnsiString;
|
|
|
+ End;
|
|
|
+
|
|
|
implementation
|
|
|
|
|
|
uses XmlCfg, chmsitemap;
|
|
@@ -122,7 +129,7 @@ begin
|
|
|
IndexSitemap := TChmSiteMap.Create(stIndex);
|
|
|
indexSitemap.LoadFromStream(IndexStream);
|
|
|
Writer.AppendBinaryIndexFromSiteMap(IndexSitemap,False);
|
|
|
- IndexSitemap.Free;
|
|
|
+ IndexSitemap.Free;
|
|
|
end;
|
|
|
IndexStream.Free;
|
|
|
end;
|
|
@@ -148,8 +155,11 @@ begin
|
|
|
end;
|
|
|
|
|
|
destructor TChmProject.Destroy;
|
|
|
+var i : integer;
|
|
|
begin
|
|
|
- FFIles.Free;
|
|
|
+ for i:=0 to ffiles.count -1 do
|
|
|
+ ffiles.objects[i].free;
|
|
|
+ FFiles.Free;
|
|
|
inherited Destroy;
|
|
|
end;
|
|
|
|
|
@@ -157,7 +167,8 @@ procedure TChmProject.LoadFromFile(AFileName: String);
|
|
|
var
|
|
|
Cfg: TXMLConfig;
|
|
|
FileCount: Integer;
|
|
|
- I: Integer;
|
|
|
+ I : Integer;
|
|
|
+ nd : TChmContextNode;
|
|
|
begin
|
|
|
Cfg := TXMLConfig.Create(nil);
|
|
|
Cfg.Filename := AFileName;
|
|
@@ -165,9 +176,14 @@ begin
|
|
|
|
|
|
Files.Clear;
|
|
|
FileCount := Cfg.GetValue('Files/Count/Value', 0);
|
|
|
- for I := 0 to FileCount-1 do begin
|
|
|
- Files.Add(Cfg.GetValue('Files/FileName'+IntToStr(I)+'/Value',''));
|
|
|
- end;
|
|
|
+ for I := 0 to FileCount-1 do
|
|
|
+ begin
|
|
|
+ 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','');
|
|
|
+ Files.AddObject(nd.urlname,nd);
|
|
|
+ end;
|
|
|
IndexFileName := Cfg.GetValue('Files/IndexFile/Value','');
|
|
|
TableOfContentsFileName := Cfg.GetValue('Files/TOCFile/Value','');
|
|
|
// For chm file merging, bintoc must be false and binindex true. Change defaults in time?
|
|
@@ -182,19 +198,53 @@ 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;
|
|
|
- I: Integer;
|
|
|
-
|
|
|
+ I : Integer;
|
|
|
+ nd : TChmContextNode;
|
|
|
begin
|
|
|
Cfg := TXMLConfig.Create(nil);
|
|
|
Cfg.StartEmpty := True;
|
|
|
Cfg.Filename := FileName;
|
|
|
Cfg.Clear;
|
|
|
Cfg.SetValue('Files/Count/Value', Files.Count);
|
|
|
- for I := 0 to Files.Count-1 do begin
|
|
|
+ for I := 0 to Files.Count-1 do
|
|
|
+ begin
|
|
|
+ nd:=TChmContextNode(files.objects[i]);
|
|
|
Cfg.SetValue('Files/FileName'+IntToStr(I)+'/Value', Files.Strings[I]);
|
|
|
+ if assigned(nd) then
|
|
|
+ begin
|
|
|
+ Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextNumber', nd.contextnumber);
|
|
|
+ Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextName', nd.contextname);
|
|
|
+ end;
|
|
|
end;
|
|
|
Cfg.SetValue('Files/IndexFile/Value', IndexFileName);
|
|
|
Cfg.SetValue('Files/TOCFile/Value', TableOfContentsFileName);
|
|
@@ -217,10 +267,11 @@ end;
|
|
|
|
|
|
procedure TChmProject.WriteChm(AOutStream: TStream);
|
|
|
var
|
|
|
- Writer: TChmWriter;
|
|
|
+ Writer : TChmWriter;
|
|
|
TOCStream,
|
|
|
IndexStream: TFileStream;
|
|
|
-
|
|
|
+ nd : TChmContextNode;
|
|
|
+ I : Integer;
|
|
|
begin
|
|
|
IndexStream := nil;
|
|
|
TOCStream := nil;
|
|
@@ -242,6 +293,13 @@ begin
|
|
|
Writer.HasBinaryTOC := MakeBinaryTOC;
|
|
|
Writer.HasBinaryIndex := MakeBinaryIndex;
|
|
|
|
|
|
+ for i:=0 to files.count-1 do
|
|
|
+ begin
|
|
|
+ nd:=TChmContextNode(files.objects[i]);
|
|
|
+ if assigned(nd) and (nd.contextnumber<>0) then
|
|
|
+ Writer.AddContext(nd.ContextNumber,files[i]);
|
|
|
+ end;
|
|
|
+
|
|
|
// and write!
|
|
|
Writer.Execute;
|
|
|
|