* Changed FileSearch to handle a set of options instead of boolean.

Options now include stripquotes
* Changed ExeSearch so dirlist is optional and PATH is used if omitted. 
  It uses stripQuotes on windows. (bug 19282)

git-svn-id: trunk@17717 -
This commit is contained in:
michael 2011-06-11 11:36:51 +00:00
parent 2f7525f26a
commit 6b42ee69a9
2 changed files with 35 additions and 8 deletions

View File

@ -71,6 +71,10 @@ Const
{ File errors }
feInvalidHandle : THandle = THandle(-1); //return value on FileOpen error
Type
TFileSearchOption = (sfoImplicitCurrentDir,sfoStripQuotes);
TFileSearchOptions = set of TFileSearchOption;
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
Function FileCreate (Const FileName : String) : THandle;
Function FileCreate (Const FileName : String; Rights : Integer) : THandle;
@ -96,8 +100,10 @@ Function FileGetAttr (Const FileName : String) : Longint;
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
Function DeleteFile (Const FileName : String) : Boolean;
Function RenameFile (Const OldName, NewName : String) : Boolean;
Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
Function ExeSearch (Const Name, DirList : String) : String;
Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = []) : String;
Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
Function ExeSearch (Const Name : String; Const DirList : String = '') : String;
Function FileIsReadOnly(const FileName: String): Boolean;
Function GetFileHandle(var f : File):THandle;

View File

@ -18,7 +18,7 @@
{ variant error codes }
{$i varerror.inc}
Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = []) : String;
Var
I : longint;
Temp : String;
@ -27,7 +27,7 @@
Result:=Name;
temp:=SetDirSeparators(DirList);
// Start with checking the file in the current directory
If ImplicitCurrentDir and (Result <> '') and FileExists(Result) Then
If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
exit;
while True do begin
If Temp = '' then
@ -44,21 +44,42 @@
Temp:='';
end;
If Result<>'' then
Result:=IncludeTrailingPathDelimiter(Result)+name;
begin
If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
Result:=Copy(Result,2,Length(Result)-2);
if (Result<>'') then
Result:=IncludeTrailingPathDelimiter(Result)+name;
end;
If (Result <> '') and FileExists(Result) Then
exit;
end;
result:='';
end;
Function ExeSearch (Const Name, DirList : String) : String;
Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
begin
if ImplicitCurrentDir then
Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
else
Result:=FileSearch(Name,DirList,[]);
end;
Function ExeSearch (Const Name : String; Const DirList : String ='' ) : String;
Var
D : String;
O : TFileSearchOptions;
begin
D:=DirList;
if (D='') then
D:=GetEnvironmentVariable('PATH');
{$ifdef unix}
Result := FileSearch(Name, DirList, False);
O:=[];
{$else unix}
Result := FileSearch(Name, DirList, True);
O:=(sfoImplicitCurrentDir,sfoStripQuotes);
{$endif unix}
Result := FileSearch(Name, D, False);
end;
{$ifndef OS_FILEISREADONLY}