mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-02 00:50:17 +02:00
* attempt to fix mantis #28321. Use path of project file as base of chm.
git-svn-id: trunk@49125 -
This commit is contained in:
parent
e4cc8af8fc
commit
aead0528cf
@ -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;
|
FileName := expandfilename(AFileName);
|
||||||
FBasePath:=extractfilepath(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;
|
MakeBinaryIndex:=True;
|
||||||
FBasePath:=extractfilepath(expandfilename(afilename));
|
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);
|
newfiles.add(vl);
|
||||||
Error(ChmNote,'Found file '+vn+' while scanning '+fn,1);
|
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;
|
||||||
@ -1198,10 +1203,10 @@ begin
|
|||||||
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;
|
||||||
@ -1252,39 +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;
|
|
||||||
FullFileName := IncludeTrailingPathDelimiter(ProjectDir()) + ExtractFileName(FIndexFileName);
|
|
||||||
if FileExists(FullFileName) then
|
|
||||||
begin
|
|
||||||
if fileexists(FIndexFileName) 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 '+FIndexFileName);
|
|
||||||
freeandnil(findex); freeandnil(findexstream);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
error(chmerror,'Can''t find index file '+FIndexFileName);
|
|
||||||
end;
|
end;
|
||||||
|
if FIndexFileName<>'' then
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user