mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 09:21:10 +02:00
IDE: using PathIsInPath instead of FileIsInPath where path=path is allowed
git-svn-id: branches/fixes_2_0@61637 -
This commit is contained in:
parent
351d1ed8a2
commit
c88691c16e
@ -2299,8 +2299,7 @@ begin
|
|||||||
CurLazDir:=ChompPathDelim(LazarusDirectory);
|
CurLazDir:=ChompPathDelim(LazarusDirectory);
|
||||||
if not TTransferMacroList.StrHasMacros(CurLazDir) then begin
|
if not TTransferMacroList.StrHasMacros(CurLazDir) then begin
|
||||||
BaseDir:=ExtractFilePath(ChompPathDelim(GetPrimaryConfigPath));
|
BaseDir:=ExtractFilePath(ChompPathDelim(GetPrimaryConfigPath));
|
||||||
if (CompareFilenames(BaseDir,CurLazDir)=0)
|
if PathIsInPath(CurLazDir,BaseDir) then begin
|
||||||
or FileIsInPath(CurLazDir,BaseDir) then begin
|
|
||||||
// the pcp directory is in the lazarus directory
|
// the pcp directory is in the lazarus directory
|
||||||
// or the lazarus directory is a sibling or a sub dir of a sibling of the pcp
|
// or the lazarus directory is a sibling or a sub dir of a sibling of the pcp
|
||||||
// examples:
|
// examples:
|
||||||
|
@ -50,6 +50,7 @@ function CreateEmptyFile(const Filename: string): boolean;
|
|||||||
function FilenameIsPascalSource(const Filename: string): boolean;
|
function FilenameIsPascalSource(const Filename: string): boolean;
|
||||||
function ChompEndNumber(const s: string): string;
|
function ChompEndNumber(const s: string): string;
|
||||||
function ShortDisplayFilename(const aFileName: string): string;
|
function ShortDisplayFilename(const aFileName: string): string;
|
||||||
|
function PathIsInPath(const Path, Directory: string): boolean;
|
||||||
|
|
||||||
// find file
|
// find file
|
||||||
function FindFilesCaseInsensitive(const Directory,
|
function FindFilesCaseInsensitive(const Directory,
|
||||||
@ -505,10 +506,7 @@ function GetNextUsedDirectoryInSearchPath(const SearchPath,
|
|||||||
begin
|
begin
|
||||||
while (NextStartPos<=length(SearchPath)) do begin
|
while (NextStartPos<=length(SearchPath)) do begin
|
||||||
Result:=GetNextDirectoryInSearchPath(SearchPath,NextStartPos);
|
Result:=GetNextDirectoryInSearchPath(SearchPath,NextStartPos);
|
||||||
if (Result<>'')
|
if (Result<>'') and PathIsInPath(Result,FilterDir) then
|
||||||
and ((CompareFilenames(Result,FilterDir)=0)
|
|
||||||
or FileIsInPath(Result,FilterDir))
|
|
||||||
then
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Result:=''
|
Result:=''
|
||||||
@ -723,6 +721,20 @@ begin
|
|||||||
Result := aFileName;
|
Result := aFileName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function PathIsInPath(const Path, Directory: string): boolean;
|
||||||
|
var
|
||||||
|
ExpPath: String;
|
||||||
|
ExpDir: String;
|
||||||
|
l: integer;
|
||||||
|
begin
|
||||||
|
if Path='' then exit(false);
|
||||||
|
ExpPath:=AppendPathDelim(ResolveDots(Path));
|
||||||
|
ExpDir:=AppendPathDelim(ResolveDots(Directory));
|
||||||
|
l:=length(ExpDir);
|
||||||
|
Result:=(l>0) and (length(ExpPath)>=l) and (ExpPath[l]=PathDelim)
|
||||||
|
and (CompareFilenames(ExpDir,LeftStr(ExpPath,l))=0);
|
||||||
|
end;
|
||||||
|
|
||||||
function FindFirstFileWithExt(const Directory, Ext: string): string;
|
function FindFirstFileWithExt(const Directory, Ext: string): string;
|
||||||
var
|
var
|
||||||
FileInfo: TSearchRec;
|
FileInfo: TSearchRec;
|
||||||
|
15
ide/main.pp
15
ide/main.pp
@ -1409,7 +1409,7 @@ begin
|
|||||||
and (CheckFPCExeQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
|
and (CheckFPCExeQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
|
||||||
CodeToolBoss.CompilerDefinesCache.TestFilename)=sddqInvalid)
|
CodeToolBoss.CompilerDefinesCache.TestFilename)=sddqInvalid)
|
||||||
then begin
|
then begin
|
||||||
debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]);
|
debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename,' ',Note]);
|
||||||
ShowSetupDialog:=true;
|
ShowSetupDialog:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1421,7 +1421,7 @@ begin
|
|||||||
if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
|
if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
|
||||||
CfgCache.GetFPCVer)=sddqInvalid
|
CfgCache.GetFPCVer)=sddqInvalid
|
||||||
then begin
|
then begin
|
||||||
debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]);
|
debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory,' ',Note]);
|
||||||
ShowSetupDialog:=true;
|
ShowSetupDialog:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -6763,7 +6763,7 @@ begin
|
|||||||
UnitOutputDirectory:=TrimFilename(WorkingDir+PathDelim+UnitOutputDirectory);
|
UnitOutputDirectory:=TrimFilename(WorkingDir+PathDelim+UnitOutputDirectory);
|
||||||
if FilenameIsAbsolute(UnitOutputDirectory) then begin
|
if FilenameIsAbsolute(UnitOutputDirectory) then begin
|
||||||
if (not DirPathExistsCached(UnitOutputDirectory)) then begin
|
if (not DirPathExistsCached(UnitOutputDirectory)) then begin
|
||||||
if not FileIsInPath(UnitOutputDirectory,WorkingDir) then begin
|
if not PathIsInPath(UnitOutputDirectory,WorkingDir) then begin
|
||||||
Result:=IDEQuestionDialog(lisCreateDirectory,
|
Result:=IDEQuestionDialog(lisCreateDirectory,
|
||||||
Format(lisTheOutputDirectoryIsMissing, [UnitOutputDirectory]),
|
Format(lisTheOutputDirectoryIsMissing, [UnitOutputDirectory]),
|
||||||
mtConfirmation, [mrYes, lisCreateIt,
|
mtConfirmation, [mrYes, lisCreateIt,
|
||||||
@ -6777,7 +6777,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if Project1.IsVirtual
|
if Project1.IsVirtual
|
||||||
and (FileIsInPath(UnitOutputDirectory,EnvironmentOptions.GetParsedTestBuildDirectory))
|
and (PathIsInPath(UnitOutputDirectory,
|
||||||
|
EnvironmentOptions.GetParsedTestBuildDirectory))
|
||||||
then begin
|
then begin
|
||||||
// clean up test units
|
// clean up test units
|
||||||
Result:=CleanUpTestUnitOutputDir(UnitOutputDirectory);
|
Result:=CleanUpTestUnitOutputDir(UnitOutputDirectory);
|
||||||
@ -6799,7 +6800,7 @@ begin
|
|||||||
if Result<>mrIgnore then exit(mrCancel);
|
if Result<>mrIgnore then exit(mrCancel);
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
if not FileIsInPath(AppendPathDelim(TargetExeDirectory)+'dummy',WorkingDir)
|
if not PathIsInPath(TargetExeDirectory,WorkingDir)
|
||||||
then begin
|
then begin
|
||||||
Result:=IDEQuestionDialog(lisCreateDirectory,
|
Result:=IDEQuestionDialog(lisCreateDirectory,
|
||||||
Format(lisTheOutputDirectoryIsMissing, [TargetExeDirectory]),
|
Format(lisTheOutputDirectoryIsMissing, [TargetExeDirectory]),
|
||||||
@ -11734,12 +11735,12 @@ begin
|
|||||||
SaveDialog.FileName:=SaveAsFilename;
|
SaveDialog.FileName:=SaveAsFilename;
|
||||||
// if this is a project file, start in project directory
|
// if this is a project file, start in project directory
|
||||||
if AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
|
if AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
|
||||||
and (not FileIsInPath(SaveDialog.InitialDir,Project1.Directory)) then
|
and (not PathIsInPath(SaveDialog.InitialDir,Project1.Directory)) then
|
||||||
SaveDialog.InitialDir:=Project1.Directory;
|
SaveDialog.InitialDir:=Project1.Directory;
|
||||||
// if this is a package file, then start in package directory
|
// if this is a package file, then start in package directory
|
||||||
PkgDefaultDirectory:=PkgBoss.GetDefaultSaveDirectoryForFile(AnUnitInfo.Filename);
|
PkgDefaultDirectory:=PkgBoss.GetDefaultSaveDirectoryForFile(AnUnitInfo.Filename);
|
||||||
if (PkgDefaultDirectory<>'')
|
if (PkgDefaultDirectory<>'')
|
||||||
and (not FileIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then
|
and (not PathIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then
|
||||||
SaveDialog.InitialDir:=PkgDefaultDirectory;
|
SaveDialog.InitialDir:=PkgDefaultDirectory;
|
||||||
// show save dialog
|
// show save dialog
|
||||||
if (not SaveDialog.Execute) or (ExtractFileName(SaveDialog.Filename)='') then
|
if (not SaveDialog.Execute) or (ExtractFileName(SaveDialog.Filename)='') then
|
||||||
|
@ -4602,13 +4602,13 @@ begin
|
|||||||
// if this is a project file, start in project directory
|
// if this is a project file, start in project directory
|
||||||
if (AnUnitInfo=nil)
|
if (AnUnitInfo=nil)
|
||||||
or (AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
|
or (AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
|
||||||
and (not FileIsInPath(SaveDialog.InitialDir,Project1.Directory)))
|
and (not PathIsInPath(SaveDialog.InitialDir,Project1.Directory)))
|
||||||
then begin
|
then begin
|
||||||
SaveDialog.InitialDir:=Project1.Directory;
|
SaveDialog.InitialDir:=Project1.Directory;
|
||||||
end;
|
end;
|
||||||
// if this is a package file, then start in package directory
|
// if this is a package file, then start in package directory
|
||||||
APath:=PkgBoss.GetDefaultSaveDirectoryForFile(AFilename);
|
APath:=PkgBoss.GetDefaultSaveDirectoryForFile(AFilename);
|
||||||
if (APath<>'') and (not FileIsInPath(SaveDialog.InitialDir,APath)) then
|
if (APath<>'') and (not PathIsInPath(SaveDialog.InitialDir,APath)) then
|
||||||
SaveDialog.InitialDir:=APath;
|
SaveDialog.InitialDir:=APath;
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
@ -5382,7 +5382,7 @@ begin
|
|||||||
OldLRSFilePath:=ExtractFilePath(LRSCode.Filename);
|
OldLRSFilePath:=ExtractFilePath(LRSCode.Filename);
|
||||||
NewLRSFilePath:=OldLRSFilePath;
|
NewLRSFilePath:=OldLRSFilePath;
|
||||||
if FilenameIsAbsolute(OldFilePath)
|
if FilenameIsAbsolute(OldFilePath)
|
||||||
and FileIsInPath(OldLRSFilePath,OldFilePath) then begin
|
and PathIsInPath(OldLRSFilePath,OldFilePath) then begin
|
||||||
// resource code was in the same or in a sub directory of source
|
// resource code was in the same or in a sub directory of source
|
||||||
// -> try to keep this relationship
|
// -> try to keep this relationship
|
||||||
NewLRSFilePath:=NewFilePath
|
NewLRSFilePath:=NewFilePath
|
||||||
|
Loading…
Reference in New Issue
Block a user