From d5c9ca6f4fa6031fb507c555b829f0c6e56a4c6f Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 10 Jan 2011 20:40:59 +0000 Subject: [PATCH] IDE: fixed wrong CleanAndExpandFile/Dir use git-svn-id: trunk@28940 - --- components/codetools/definetemplates.pas | 10 ++++++---- components/codetools/fileprocs.pas | 20 ++++++++++++++++++-- ide/checkcompileropts.pas | 4 ++-- ide/codebrowser.pas | 3 ++- ide/findinfilesdlg.pas | 5 ++--- ide/fpdoceditwindow.pas | 2 +- ide/helpmanager.pas | 4 ++-- ide/ideprocs.pp | 4 ++-- ide/main.pp | 13 ++++++------- ide/outputfilter.pas | 1 - ide/sourceeditprocs.pas | 3 ++- packager/adddirtopkgdlg.pas | 6 +++--- 12 files changed, 46 insertions(+), 29 deletions(-) diff --git a/components/codetools/definetemplates.pas b/components/codetools/definetemplates.pas index db27290dc2..87a7f0b75a 100644 --- a/components/codetools/definetemplates.pas +++ b/components/codetools/definetemplates.pas @@ -1070,7 +1070,8 @@ begin Abort:=false; try FileCount:=0; - Directory:=CleanAndExpandDirectory(Directory); + Directory:=TrimAndExpandDirectory(Directory); + if Directory='' then exit; Search('',0); finally if not Abort then @@ -1541,7 +1542,8 @@ begin FileCount:=0; Abort:=false; for i:=SearchPaths.Count-1 downto 0 do begin - Directory:=CleanAndExpandDirectory(SearchPaths[i]); + Directory:=TrimAndExpandDirectory(SearchPaths[i]); + if (Directory='') then continue; if FindFirstUTF8(Directory+FileMask,faAnyFile,FileInfo)=0 then begin repeat inc(FileCount); @@ -8572,7 +8574,7 @@ procedure TFPCUnitSetCache.SetCompilerFilename(const AValue: string); var NewFilename: String; begin - NewFilename:=CleanAndExpandFilename(AValue); + NewFilename:=TrimAndExpandFilename(AValue); if FCompilerFilename=NewFilename then exit; FCompilerFilename:=NewFilename; ClearConfigCache; @@ -8589,7 +8591,7 @@ procedure TFPCUnitSetCache.SetFPCSourceDirectory(const AValue: string); var NewValue: String; begin - NewValue:=CleanAndExpandDirectory(AValue); + NewValue:=TrimAndExpandDirectory(AValue); if FFPCSourceDirectory=NewValue then exit; FFPCSourceDirectory:=NewValue; ClearSourceCache; diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index d9e0622b7b..62f790b3e9 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -90,8 +90,10 @@ function FileIsText(const AFilename: string; out FileReadable: boolean): boolean function FilenameIsTrimmed(const TheFilename: string): boolean; function FilenameIsTrimmed(StartPos: PChar; NameLen: integer): boolean; function TrimFilename(const AFilename: string): string; -function CleanAndExpandFilename(const Filename: string): string; -function CleanAndExpandDirectory(const Filename: string): string; +function CleanAndExpandFilename(const Filename: string): string; // empty string returns current directory +function CleanAndExpandDirectory(const Filename: string): string; // empty string returns current directory +function TrimAndExpandFilename(const Filename: string): string; // empty string returns empty string +function TrimAndExpandDirectory(const Filename: string): string; // empty string returns empty string function CreateRelativePath(const Filename, BaseDirectory: string; UsePointDirectory: boolean = false): string; function FileIsInPath(const Filename, Path: string): boolean; @@ -1376,6 +1378,20 @@ begin Result:=AppendPathDelim(CleanAndExpandFilename(Filename)); end; +function TrimAndExpandFilename(const Filename: string): string; +begin + Result:=ChompPathDelim(TrimFilename(Filename)); + if Result='' then exit; + Result:=TrimFilename(ExpandFileNameUTF8(Result)); +end; + +function TrimAndExpandDirectory(const Filename: string): string; +begin + Result:=TrimFilename(Filename); + if Result='' then exit; + Result:=TrimFilename(AppendPathDelim(ExpandFileNameUTF8(Result))); +end; + function CreateRelativePath(const Filename, BaseDirectory: string; UsePointDirectory: boolean): string; var diff --git a/ide/checkcompileropts.pas b/ide/checkcompileropts.pas index c5e88f3ef9..ee43147ac9 100644 --- a/ide/checkcompileropts.pas +++ b/ide/checkcompileropts.pas @@ -630,7 +630,7 @@ begin p:=1; while p<=length(FPCCfgUnitPath) do begin - Directory:=CleanAndExpandDirectory(GetNextDirectoryInSearchPath(FPCCfgUnitPath,p)); + Directory:=TrimAndExpandDirectory(GetNextDirectoryInSearchPath(FPCCfgUnitPath,p)); if Directory<>'' then begin if FindFirstUTF8(Directory+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin @@ -846,7 +846,7 @@ begin while p<=length(FPCCfgUnitPath) do begin Directory:=TrimFilename(GetNextDirectoryInSearchPath(FPCCfgUnitPath,p)); if (Directory<>'') then begin - Directory:=CleanAndExpandDirectory(GetNextDirectoryInSearchPath(FPCCfgUnitPath,p)); + Directory:=TrimAndExpandDirectory(GetNextDirectoryInSearchPath(FPCCfgUnitPath,p)); if (Directory<>'') and (FilenameIsAbsolute(Directory)) and (WarnedDirectories.IndexOf(Directory)<0) then begin //DebugLn(['TCheckCompilerOptsDlg.CheckFPCUnitPathsContainSources Directory="',Directory,'"']); diff --git a/ide/codebrowser.pas b/ide/codebrowser.pas index d749aef73e..7b5cb7c2ba 100644 --- a/ide/codebrowser.pas +++ b/ide/codebrowser.pas @@ -2783,7 +2783,8 @@ function TCodeBrowserView.ExportTreeAsText(Filename: String): TModalResult; var List: TStrings; begin - Filename:=CleanAndExpandFilename(Filename); + Filename:=TrimAndExpandFilename(Filename); + if Filename='' then exit(mrCancel); Result:=CheckCreatingFile(Filename,true,true,true); if Result<>mrOk then exit; List:=TStringList.Create; diff --git a/ide/findinfilesdlg.pas b/ide/findinfilesdlg.pas index 43a3eaafd1..5128f7d1a8 100644 --- a/ide/findinfilesdlg.pas +++ b/ide/findinfilesdlg.pas @@ -24,7 +24,7 @@ interface uses Classes, SysUtils, LCLProc, LCLIntf, Controls, StdCtrls, Forms, Buttons, - ExtCtrls, FileUtil, LazarusIDEStrConsts, Dialogs, SynEditTypes, MacroIntf, + ExtCtrls, FileProcs, LazarusIDEStrConsts, Dialogs, SynEditTypes, MacroIntf, IDEDialogs, IDEWindowIntf, InputHistory, IDEContextHelpEdit, ButtonPanel, SrcEditorIntf, EditorOptions, SearchFrm, Project, SynEdit, SearchResultView; @@ -415,8 +415,7 @@ function TLazFindInFilesDialog.GetResolvedDirectory: string; begin Result:=DirectoryComboBox.Text; IDEMacros.SubstituteMacros(Result); - if Result<>'' then - Result:=CleanAndExpandDirectory(Result); + Result:=TrimAndExpandDirectory(Result); end; end. diff --git a/ide/fpdoceditwindow.pas b/ide/fpdoceditwindow.pas index 55af39d643..08f80149ef 100644 --- a/ide/fpdoceditwindow.pas +++ b/ide/fpdoceditwindow.pas @@ -1126,7 +1126,7 @@ begin // check if visible if not IsVisible then exit; - NewSrcFilename:=CleanAndExpandFilename(SrcFilename); + NewSrcFilename:=TrimAndExpandFilename(SrcFilename); if (NewSrcFilename=SourceFilename) and (CompareCaret(Caret,CaretXY)=0) and (fChain<>nil) and fChain.IsValid and (not LazarusIDE.NeedSaveSourceEditorChangesToCodeCache(nil)) then diff --git a/ide/helpmanager.pas b/ide/helpmanager.pas index ba41c9f3ea..a8c53ca229 100644 --- a/ide/helpmanager.pas +++ b/ide/helpmanager.pas @@ -35,7 +35,7 @@ interface uses // FCL+LCL Classes, SysUtils, AVL_Tree, LCLProc, LCLIntf, LCLType, Forms, Controls, Buttons, - StdCtrls, Dialogs, ExtCtrls, FileUtil, Graphics, + StdCtrls, Dialogs, ExtCtrls, FileProcs, Graphics, // CodeTools BasicCodeTools, CodeToolManager, CodeAtom, CodeCache, CustomCodeTool, CodeTree, PascalParserTool, FindDeclarationTool, @@ -854,7 +854,7 @@ procedure TIDEHelpManager.UpdateFPCDocsHTMLDirectory; var NewDir: String; begin - NewDir:=CleanAndExpandDirectory(Directory); + NewDir:=TrimAndExpandDirectory(Directory); if not IsFPCDocsHTMDirectory(NewDir) then exit(false); HelpOpts.FPCDocsHTMLDirectory:=NewDir; DebugLn(['TryDirectory Changing FPCDocsHTMLDirectory to "',HelpOpts.FPCDocsHTMLDirectory,'"']); diff --git a/ide/ideprocs.pp b/ide/ideprocs.pp index 5141e28eec..dfa15ca9b3 100644 --- a/ide/ideprocs.pp +++ b/ide/ideprocs.pp @@ -2336,8 +2336,8 @@ var begin Result:=true; - SrcDir:=AppendPathDelim(CleanAndExpandDirectory(SrcDirectory)); - DestDir:=AppendPathDelim(CleanAndExpandDirectory(DestDirectory)); + SrcDir:=AppendPathDelim(TrimAndExpandDirectory(SrcDirectory)); + DestDir:=AppendPathDelim(TrimAndExpandDirectory(DestDirectory)); if CompareFilenames(SrcDir,DestDir)=0 then exit; if (not DirPathExists(SrcDir)) diff --git a/ide/main.pp b/ide/main.pp index a9555dd0b7..a4e0600da2 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -5044,8 +5044,8 @@ begin AnUnitInfo:=Project1.UnitInfoWithFilename(AFilename); if AnUnitInfo = nil then begin - AFilename:=CleanAndExpandFilename(UnitFilename); - if not FileExistsInIDE(AFilename,[]) then begin + AFilename:=TrimAndExpandFilename(UnitFilename); + if (AFilename='') or (not FileExistsInIDE(AFilename,[])) then begin DebugLn(['TMainIDE.DoOpenComponent file not found ',AFilename]); exit(mrCancel); end; @@ -12546,8 +12546,8 @@ begin Result:=mrCancel; // do not delete project files - DestDir:=TrimFilename(AppendPathDelim(DestDirectory)); - SrcDir:=TrimFilename(AppendPathDelim(SrcDirectory)); + DestDir:=TrimAndExpandDirectory(DestDirectory); + SrcDir:=TrimAndExpandDirectory(SrcDirectory); if (DestDir='') then begin MessageDlg('Invalid publishing Directory', 'Destination directory for publishing is empty.',mtError, @@ -12556,8 +12556,7 @@ begin exit; end; //DebugLn('TMainIDE.DoPublishModule A SrcDir="',SrcDir,'" DestDir="',DestDir,'"'); - if CompareFilenames(CleanAndExpandDirectory(SrcDir), - CleanAndExpandDirectory(DestDir))=0 + if CompareFilenames(SrcDir,DestDir)=0 then begin MessageDlg(lisInvalidPublishingDirectory, Format(lisSourceDirectoryAndDestinationDirectoryAreTheSameMa, ['"', @@ -14339,7 +14338,7 @@ var CodeBuffer: TCodeBuffer; begin Result:=mrCancel; - CodeBuffer:=CodeToolBoss.LoadFile(CleanAndExpandFilename(Filename),true,false); + CodeBuffer:=CodeToolBoss.LoadFile(TrimAndExpandFilename(Filename),true,false); if CodeBuffer=nil then exit; Result:=DoJumpToCodePos(nil,nil,CodeBuffer,NewX,NewY,NewTopLine,AddJumpPoint, True, MarkLine); end; diff --git a/ide/outputfilter.pas b/ide/outputfilter.pas index d87db10fba..83db8cdad4 100644 --- a/ide/outputfilter.pas +++ b/ide/outputfilter.pas @@ -1395,7 +1395,6 @@ begin Result:=FullDir+ShortIncFilename; if FileExistsUTF8(Result) then begin // file found in search dir - Result:=CleanAndExpandFilename(Result); exit; end; AlreadySearchedPaths:=MergeSearchPaths(AlreadySearchedPaths,FullDir); diff --git a/ide/sourceeditprocs.pas b/ide/sourceeditprocs.pas index d0034454e9..393c82f8d1 100644 --- a/ide/sourceeditprocs.pas +++ b/ide/sourceeditprocs.pas @@ -799,7 +799,8 @@ var CodeBuf: TCodeBuffer; TargetCodeBuffer: TCodeBuffer; begin - TheFilename:=CleanAndExpandFilename(AFilename); + TheFilename:=TrimAndExpandFilename(AFilename); + if TheFilename='' then exit(false); CodeBuf:=CodeToolBoss.FindFile(TheFilename); if CodeBuf=nil then begin // it is not in cache diff --git a/packager/adddirtopkgdlg.pas b/packager/adddirtopkgdlg.pas index a36f0408a8..88a39e1892 100644 --- a/packager/adddirtopkgdlg.pas +++ b/packager/adddirtopkgdlg.pas @@ -27,7 +27,7 @@ interface uses Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, ButtonPanel, - SynRegExpr, FileUtil, + SynRegExpr, FileProcs, // IDE IDEWindowIntf, InputHistory, IDEProcs, LazarusIDEStrConsts, PackageDefs; @@ -206,13 +206,13 @@ function TAddDirToPkgDialog.GatherFiles(Directory: string; CurFilename: String; begin Result:=false; - CurDir:=CleanAndExpandDirectory(CurDir); + CurDir:=TrimAndExpandDirectory(CurDir); if not DirPathExists(CurDir) then begin MessageDlg(lisEnvOptDlgDirectoryNotFound, Format(lisTheDirectoryWasNotFound, [CurDir]), mtError, [mbCancel], 0); exit; end; - if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin + if FindFirstUTF8(CurDir+FileMask,faAnyFile,FileInfo)=0 then begin repeat // check if special file if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then