|
@@ -155,7 +155,6 @@ function TChmProject.GetData(const DataName: String; out PathInChm: String; out
|
|
FileName: String; var Stream: TStream): Boolean;
|
|
FileName: String; var Stream: TStream): Boolean;
|
|
begin
|
|
begin
|
|
Result := False; // Return true to abort compressing files
|
|
Result := False; // Return true to abort compressing files
|
|
-
|
|
|
|
TMemoryStream(Stream).LoadFromFile(ProjectDir+DataName);
|
|
TMemoryStream(Stream).LoadFromFile(ProjectDir+DataName);
|
|
// clean up the filename
|
|
// clean up the filename
|
|
FileName := StringReplace(ExtractFileName(DataName), '\', '/', [rfReplaceAll]);
|
|
FileName := StringReplace(ExtractFileName(DataName), '\', '/', [rfReplaceAll]);
|
|
@@ -353,8 +352,8 @@ var
|
|
begin
|
|
begin
|
|
Cfg := TXMLConfig.Create(nil);
|
|
Cfg := TXMLConfig.Create(nil);
|
|
Cfg.Filename := AFileName;
|
|
Cfg.Filename := AFileName;
|
|
- FileName := AFileName;
|
|
|
|
- FBasePath:=extractfilepath(expandfilename(afilename));
|
|
|
|
|
|
+ FileName := expandfilename(AFileName);
|
|
|
|
+ FBasePath:=extractfilepath(FileName);
|
|
|
|
|
|
Files.Clear;
|
|
Files.Clear;
|
|
FileCount := Cfg.GetValue('Files/Count/Value', 0);
|
|
FileCount := Cfg.GetValue('Files/Count/Value', 0);
|
|
@@ -580,8 +579,9 @@ var
|
|
|
|
|
|
begin
|
|
begin
|
|
{ Defaults other than global }
|
|
{ Defaults other than global }
|
|
- MakeBinaryIndex:=True;
|
|
|
|
- FBasePath:=extractfilepath(expandfilename(afilename));
|
|
|
|
|
|
+ MakeBinaryIndex:=True;
|
|
|
|
+ filename:=expandfilename(afilename);
|
|
|
|
+ FBasePath:=extractfilepath(filename);
|
|
Fini:=TMeminiFile.Create(AFileName);
|
|
Fini:=TMeminiFile.Create(AFileName);
|
|
secs := TStringList.create;
|
|
secs := TStringList.create;
|
|
strs := TStringList.create;
|
|
strs := TStringList.create;
|
|
@@ -758,7 +758,6 @@ begin
|
|
inc(i);
|
|
inc(i);
|
|
end;
|
|
end;
|
|
outstring:=localpath+instring;
|
|
outstring:=localpath+instring;
|
|
-
|
|
|
|
i:=pos('#',outstring);
|
|
i:=pos('#',outstring);
|
|
if i<>0 then begin
|
|
if i<>0 then begin
|
|
if i<>length(outstring) then // trims lone '#' at end of url.
|
|
if i<>length(outstring) then // trims lone '#' at end of url.
|
|
@@ -777,7 +776,7 @@ begin
|
|
delete(outstring,i,length(outstring)-i+1);
|
|
delete(outstring,i,length(outstring)-i+1);
|
|
end;
|
|
end;
|
|
|
|
|
|
- outstring:=expandfilename(StringReplace(outstring,'%20',' ',[rfReplaceAll]));// expandfilename(instring));
|
|
|
|
|
|
+ outstring:=expandfilename(includetrailingpathdelimiter(fbasepath)+StringReplace(outstring,'%20',' ',[rfReplaceAll]));// expandfilename(instring));
|
|
|
|
|
|
outstring:=extractrelativepath(basepath,outstring);
|
|
outstring:=extractrelativepath(basepath,outstring);
|
|
outstring:=StringReplace(outstring,'\','/',[rfReplaceAll]);
|
|
outstring:=StringReplace(outstring,'\','/',[rfReplaceAll]);
|
|
@@ -937,14 +936,14 @@ var
|
|
fn,reffn : string;
|
|
fn,reffn : string;
|
|
tmplst : Tstringlist;
|
|
tmplst : Tstringlist;
|
|
|
|
|
|
-function trypath(const vn:string):boolean;
|
|
|
|
|
|
+function trypath(const vn:string;const vl:string):boolean;
|
|
var vn2: String;
|
|
var vn2: String;
|
|
strrec : TStringIndex;
|
|
strrec : TStringIndex;
|
|
begin
|
|
begin
|
|
vn2:=uppercase(vn);
|
|
vn2:=uppercase(vn);
|
|
if FileInTotalList(vn2) then
|
|
if FileInTotalList(vn2) then
|
|
begin
|
|
begin
|
|
- Error(ChmNote,'Found duplicate file '+vn+' while scanning '+fn,1);
|
|
|
|
|
|
+ Error(ChmNote,'Found duplicate file '+vl+' while scanning '+fn,1);
|
|
exit(true);
|
|
exit(true);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -956,11 +955,13 @@ begin
|
|
StrRec.TheString:=vn2;
|
|
StrRec.TheString:=vn2;
|
|
StrRec.Strid :=0;
|
|
StrRec.Strid :=0;
|
|
fTotalFileList.Add(StrRec);
|
|
fTotalFileList.Add(StrRec);
|
|
- newfiles.add(vn);
|
|
|
|
- Error(ChmNote,'Found file '+vn+' while scanning '+fn,1);
|
|
|
|
|
|
+ newfiles.add(vl);
|
|
|
|
+ Error(ChmNote,'Found file '+vl+' while scanning '+fn,1);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+var efn : string;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
localfilelist:=TStringList.Create;
|
|
localfilelist:=TStringList.Create;
|
|
for j:=0 to toscan.count-1 do
|
|
for j:=0 to toscan.count-1 do
|
|
@@ -969,12 +970,16 @@ begin
|
|
localfilelist.clear;
|
|
localfilelist.clear;
|
|
if (FAllowedExtensions.Indexof(uppercase(extractfileext(fn)))<>-1) then
|
|
if (FAllowedExtensions.Indexof(uppercase(extractfileext(fn)))<>-1) then
|
|
begin
|
|
begin
|
|
- if fileexists(fn) then
|
|
|
|
|
|
+ if fbasepath<>'' then
|
|
|
|
+ efn:=IncludeTrailingPathDelimiter(FBasePath)+fn
|
|
|
|
+ else
|
|
|
|
+ efn:=fn;
|
|
|
|
+ if fileexists(efn) then
|
|
begin
|
|
begin
|
|
domdoc:=THtmlDocument.Create;
|
|
domdoc:=THtmlDocument.Create;
|
|
try
|
|
try
|
|
Error(chmnote,'Scanning file '+fn+'.',5);
|
|
Error(chmnote,'Scanning file '+fn+'.',5);
|
|
- ReadHtmlFile(domdoc,fn);
|
|
|
|
|
|
+ ReadHtmlFile(domdoc,efn);
|
|
localpath:=extractfilepath(fn);
|
|
localpath:=extractfilepath(fn);
|
|
if (length(localpath)>0) and not (localpath[length(localpath)] in ['/','\']) then
|
|
if (length(localpath)>0) and not (localpath[length(localpath)] in ['/','\']) then
|
|
localpath:=localpath+pathsep;
|
|
localpath:=localpath+pathsep;
|
|
@@ -982,7 +987,7 @@ begin
|
|
for i:=0 to localFilelist.count-1 do
|
|
for i:=0 to localFilelist.count-1 do
|
|
begin
|
|
begin
|
|
reffn:=localfilelist[i];
|
|
reffn:=localfilelist[i];
|
|
- if not trypath(reffn) then // if not trypath(localpath+s) then
|
|
|
|
|
|
+ if not trypath(IncludeTrailingPathDelimiter(fbasepath)+reffn,reffn) then // if not trypath(localpath+s) then
|
|
Error(ChmWarning,'Found file '+reffn+' while scanning '+fn+', but couldn''t find it on disk',2);
|
|
Error(ChmWarning,'Found file '+reffn+' while scanning '+fn+', but couldn''t find it on disk',2);
|
|
end;
|
|
end;
|
|
except
|
|
except
|
|
@@ -1011,7 +1016,7 @@ begin
|
|
begin
|
|
begin
|
|
delete(reffn,1,pos('url(''', reffn)+4);
|
|
delete(reffn,1,pos('url(''', reffn)+4);
|
|
reffn:=trim(copy(reffn,1,pos('''',reffn)-1));
|
|
reffn:=trim(copy(reffn,1,pos('''',reffn)-1));
|
|
- if not trypath(reffn) then
|
|
|
|
|
|
+ if not trypath(IncludeTrailingPathDelimiter(fbasepath)+reffn,reffn) then
|
|
// if not trypath(localpath+s) then
|
|
// if not trypath(localpath+s) then
|
|
Error(ChmWarning,'Found file '+reffn+' while scanning '+fn+', but couldn''t find it on disk',2);
|
|
Error(ChmWarning,'Found file '+reffn+' while scanning '+fn+', but couldn''t find it on disk',2);
|
|
end;
|
|
end;
|
|
@@ -1190,18 +1195,18 @@ begin
|
|
Writer.FullTextSearch := MakeSearchable;
|
|
Writer.FullTextSearch := MakeSearchable;
|
|
Writer.HasBinaryTOC := MakeBinaryTOC;
|
|
Writer.HasBinaryTOC := MakeBinaryTOC;
|
|
Writer.HasBinaryIndex := MakeBinaryIndex;
|
|
Writer.HasBinaryIndex := MakeBinaryIndex;
|
|
- Writer.IndexName := ExtractFileName(IndexFileName);
|
|
|
|
- Writer.TocName := ExtractFileName(TableOfContentsFileName);
|
|
|
|
|
|
+ Writer.IndexName := IndexFileName;
|
|
|
|
+ Writer.TocName := TableOfContentsFileName;
|
|
Writer.ReadmeMessage := ReadmeMessage;
|
|
Writer.ReadmeMessage := ReadmeMessage;
|
|
Writer.DefaultWindow := FDefaultWindow;
|
|
Writer.DefaultWindow := FDefaultWindow;
|
|
Writer.LocaleID := FLocaleID;
|
|
Writer.LocaleID := FLocaleID;
|
|
for i:=0 to files.count-1 do
|
|
for i:=0 to files.count-1 do
|
|
begin
|
|
begin
|
|
nd:=TChmContextNode(files.objects[i]);
|
|
nd:=TChmContextNode(files.objects[i]);
|
|
- if not fileexists(files[i]) then
|
|
|
|
|
|
+ if not fileexists(IncludeTrailingPathDelimiter(FBasePath)+files[i]) then
|
|
Error(chmWarning,'File '+Files[i]+' does not exist');
|
|
Error(chmWarning,'File '+Files[i]+' does not exist');
|
|
if assigned(nd) and (nd.contextnumber<>0) then
|
|
if assigned(nd) and (nd.contextnumber<>0) then
|
|
- Writer.AddContext(nd.ContextNumber,files[i]);
|
|
|
|
|
|
+ Writer.AddContext(nd.ContextNumber,IncludeTrailingPathDelimiter(FBasePath)+files[i]);
|
|
end;
|
|
end;
|
|
if FWIndows.Count>0 then
|
|
if FWIndows.Count>0 then
|
|
Writer.Windows:=FWIndows;
|
|
Writer.Windows:=FWIndows;
|
|
@@ -1231,16 +1236,19 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TChmProject.LoadSitemaps;
|
|
procedure TChmProject.LoadSitemaps;
|
|
|
|
+var
|
|
|
|
+ FullFileName: string;
|
|
// #IDXHDR (merged files) goes into the system file, and need to keep TOC sitemap around
|
|
// #IDXHDR (merged files) goes into the system file, and need to keep TOC sitemap around
|
|
begin
|
|
begin
|
|
if FTableOfContentsFileName<>'' then
|
|
if FTableOfContentsFileName<>'' then
|
|
begin
|
|
begin
|
|
- if fileexists(FTableOfContentsFileName) then
|
|
|
|
|
|
+ FullFileName := IncludeTrailingPathDelimiter(ProjectDir()) + ExtractFileName(FTableOfContentsFileName);
|
|
|
|
+ if FileExists(FullFileName) then
|
|
begin
|
|
begin
|
|
FreeAndNil(FTocStream);
|
|
FreeAndNil(FTocStream);
|
|
FTocStream:=TMemoryStream.Create;
|
|
FTocStream:=TMemoryStream.Create;
|
|
try
|
|
try
|
|
- FTocStream.loadfromfile(FTableOfContentsFilename);
|
|
|
|
|
|
+ FTocStream.loadfromfile(FullFileName);
|
|
//writeln(ftableofcontentsfilename, ' ' ,ftocstream.size);
|
|
//writeln(ftableofcontentsfilename, ' ' ,ftocstream.size);
|
|
FTocStream.Position:=0;
|
|
FTocStream.Position:=0;
|
|
FreeAndNil(FToc);
|
|
FreeAndNil(FToc);
|
|
@@ -1249,38 +1257,39 @@ begin
|
|
except
|
|
except
|
|
on e:exception do
|
|
on e:exception do
|
|
begin
|
|
begin
|
|
- error(chmerror,'Error loading TOC file '+FTableOfContentsFileName);
|
|
|
|
|
|
+ error(chmerror,'Error loading TOC file '+FullFileName);
|
|
freeandnil(ftoc); freeandnil(FTocStream);
|
|
freeandnil(ftoc); freeandnil(FTocStream);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
- error(chmerror,'Can''t find TOC file'+FTableOfContentsFileName);
|
|
|
|
|
|
+ error(chmerror,'Can''t find TOC file '+FullFileName);
|
|
end;
|
|
end;
|
|
if FIndexFileName<>'' then
|
|
if FIndexFileName<>'' then
|
|
- begin
|
|
|
|
- if fileexists(FIndexFileName) then
|
|
|
|
- begin
|
|
|
|
- FreeAndNil(FIndexStream);
|
|
|
|
- FIndexStream:=TMemoryStream.Create;
|
|
|
|
- try
|
|
|
|
- FIndexStream.LoadFromFile(FIndexFileName);
|
|
|
|
- FIndexStream.Position:=0;
|
|
|
|
- FreeAndNil(FIndex);
|
|
|
|
- FIndex:=TChmSiteMap.Create(stindex);
|
|
|
|
- FIndex.loadfromfile(FIndexFileName);
|
|
|
|
- Error(chmnote,'Index items:'+inttostr(findex.Items.count));
|
|
|
|
- except
|
|
|
|
- on e: Exception do
|
|
|
|
- begin
|
|
|
|
- error(chmerror,'Error loading index file '+FIndexFileName);
|
|
|
|
- freeandnil(findex); freeandnil(findexstream);
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- error(chmerror,'Can''t find index file '+FIndexFileName);
|
|
|
|
- end;
|
|
|
|
|
|
+ begin
|
|
|
|
+ FullFileName := IncludeTrailingPathDelimiter(ProjectDir()) + ExtractFileName(FIndexFileName);
|
|
|
|
+ if FileExists(FullFileName) then
|
|
|
|
+ begin
|
|
|
|
+ FreeAndNil(FIndexStream);
|
|
|
|
+ FIndexStream:=TMemoryStream.Create;
|
|
|
|
+ try
|
|
|
|
+ FIndexStream.LoadFromFile(FullFileName);
|
|
|
|
+ FIndexStream.Position:=0;
|
|
|
|
+ FreeAndNil(FIndex);
|
|
|
|
+ FIndex:=TChmSiteMap.Create(stindex);
|
|
|
|
+ FIndex.loadfromfile(FullFileName);
|
|
|
|
+ Error(chmnote,'Index items:'+inttostr(findex.Items.count));
|
|
|
|
+ except
|
|
|
|
+ on e: Exception do
|
|
|
|
+ begin
|
|
|
|
+ error(chmerror,'Error loading index file '+FullFileName);
|
|
|
|
+ freeandnil(findex); freeandnil(findexstream);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ error(chmerror,'Can''t find index file '+FullFileName);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|