From 05e011f1621752b967d4cb07a2e93c0a543c4d68 Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 28 Jul 2019 07:36:10 +0000 Subject: [PATCH] IDE: using PathIsInPath instead of FileIsInPath where path=path is allowed git-svn-id: trunk@61635 - --- ide/environmentopts.pp | 3 +-- ide/ideprocs.pp | 20 ++++++++++++++++---- ide/main.pp | 18 ++++++++++-------- ide/sourcefilemanager.pas | 6 +++--- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/ide/environmentopts.pp b/ide/environmentopts.pp index 0b46d1a3cb..9f52598596 100644 --- a/ide/environmentopts.pp +++ b/ide/environmentopts.pp @@ -2740,8 +2740,7 @@ begin CurLazDir:=ChompPathDelim(LazarusDirectory); if not TTransferMacroList.StrHasMacros(CurLazDir) then begin BaseDir:=ExtractFilePath(ChompPathDelim(GetPrimaryConfigPath)); - if (CompareFilenames(BaseDir,CurLazDir)=0) - or FileIsInPath(CurLazDir,BaseDir) then begin + if PathIsInPath(CurLazDir,BaseDir) then begin // 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 // examples: diff --git a/ide/ideprocs.pp b/ide/ideprocs.pp index d90d263697..8ef30fcd4b 100644 --- a/ide/ideprocs.pp +++ b/ide/ideprocs.pp @@ -61,6 +61,7 @@ function CreateEmptyFile(const Filename: string): boolean; function FilenameIsPascalSource(const Filename: string): boolean; function ChompEndNumber(const s: string): string; function ShortDisplayFilename(const aFileName: string): string; +function PathIsInPath(const Path, Directory: string): boolean; // find file function FindFilesCaseInsensitive(const Directory, @@ -516,10 +517,7 @@ function GetNextUsedDirectoryInSearchPath(const SearchPath, begin while (NextStartPos<=length(SearchPath)) do begin Result:=GetNextDirectoryInSearchPath(SearchPath,NextStartPos); - if (Result<>'') - and ((CompareFilenames(Result,FilterDir)=0) - or FileIsInPath(Result,FilterDir)) - then + if (Result<>'') and PathIsInPath(Result,FilterDir) then exit; end; Result:='' @@ -750,6 +748,20 @@ begin Result := aFileName; end; +function PathIsInPath(const Path, Directory: string): boolean; +var + ExpPath: String; + ExpDir: String; + l: integer; +begin + if Path='' then exit(false); + ExpPath:=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; var FileInfo: TSearchRec; diff --git a/ide/main.pp b/ide/main.pp index 37f7896285..684dfaf8fe 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -1411,7 +1411,7 @@ begin and (CheckFPCExeQuality(EnvironmentOptions.GetParsedCompilerFilename,Note, CodeToolBoss.CompilerDefinesCache.TestFilename)=sddqInvalid) then begin - debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]); + debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename,' ',Note]); ShowSetupDialog:=true; end; @@ -1423,7 +1423,7 @@ begin if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note, CfgCache.GetFPCVer)=sddqInvalid then begin - debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]); + debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory,' ',Note]); ShowSetupDialog:=true; end; end; @@ -1434,6 +1434,7 @@ begin RegisterDebugger(TGDBMIDebugger); // make sure we can read the config // Todo: add LldbFpDebugger for Mac // If the default debugger is of a class that is not yet Registered, then the dialog is not shown + Note:=''; if ( (EnvironmentOptions.CurrentDebuggerPropertiesConfig = nil) and // no debugger at all (not EnvironmentOptions.HasActiveDebuggerEntry) ) // not even with unknown class or ( (EnvironmentOptions.CurrentDebuggerClass <> nil) // Debugger with known class @@ -1441,7 +1442,7 @@ begin and (CheckDebuggerQuality(EnvironmentOptions.GetParsedDebuggerFilename, Note)<>sddqCompatible) ) then begin - debugln(['Warning: (lazarus) missing GDB exe',EnvironmentOptions.GetParsedLazarusDirectory]); + debugln(['Warning: (lazarus) missing GDB exe ',EnvironmentOptions.GetParsedLazarusDirectory,' ',Note]); ShowSetupDialog:=true; end; end; @@ -7023,7 +7024,7 @@ begin UnitOutputDirectory:=TrimFilename(WorkingDir+PathDelim+UnitOutputDirectory); if FilenameIsAbsolute(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, Format(lisTheOutputDirectoryIsMissing, [UnitOutputDirectory]), mtConfirmation, [mrYes, lisCreateIt, @@ -7037,7 +7038,8 @@ begin end; end; if Project1.IsVirtual - and (FileIsInPath(UnitOutputDirectory,EnvironmentOptions.GetParsedTestBuildDirectory)) + and (PathIsInPath(UnitOutputDirectory, + EnvironmentOptions.GetParsedTestBuildDirectory)) then begin // clean up test units Result:=CleanUpTestUnitOutputDir(UnitOutputDirectory); @@ -7059,7 +7061,7 @@ begin if Result<>mrIgnore then exit(mrCancel); end; end else begin - if not FileIsInPath(AppendPathDelim(TargetExeDirectory)+'dummy',WorkingDir) + if not PathIsInPath(TargetExeDirectory,WorkingDir) then begin Result:=IDEQuestionDialog(lisCreateDirectory, Format(lisTheOutputDirectoryIsMissing, [TargetExeDirectory]), @@ -12011,12 +12013,12 @@ begin SaveDialog.FileName:=SaveAsFilename; // if this is a project file, start in project directory 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; // if this is a package file, then start in package directory PkgDefaultDirectory:=PkgBoss.GetDefaultSaveDirectoryForFile(AnUnitInfo.Filename); if (PkgDefaultDirectory<>'') - and (not FileIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then + and (not PathIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then SaveDialog.InitialDir:=PkgDefaultDirectory; // show save dialog if (not SaveDialog.Execute) or (ExtractFileName(SaveDialog.Filename)='') then diff --git a/ide/sourcefilemanager.pas b/ide/sourcefilemanager.pas index 83c30631a0..4aadedbe9c 100644 --- a/ide/sourcefilemanager.pas +++ b/ide/sourcefilemanager.pas @@ -4606,13 +4606,13 @@ begin // if this is a project file, start in project directory if (AnUnitInfo=nil) or (AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual) - and (not FileIsInPath(SaveDialog.InitialDir,Project1.Directory))) + and (not PathIsInPath(SaveDialog.InitialDir,Project1.Directory))) then begin SaveDialog.InitialDir:=Project1.Directory; end; // if this is a package file, then start in package directory 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; repeat @@ -5387,7 +5387,7 @@ begin OldLRSFilePath:=ExtractFilePath(LRSCode.Filename); NewLRSFilePath:=OldLRSFilePath; 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 // -> try to keep this relationship NewLRSFilePath:=NewFilePath