mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 23:00:15 +02:00
lazutils: FindDefaultExecutablePath: fixed using env PATH with quotes under Windows
git-svn-id: branches/fixes_2_0@63368 -
This commit is contained in:
parent
ded3842a35
commit
55770eb7c7
@ -200,8 +200,8 @@ begin
|
|||||||
Result:=LazFileUtils.CreateAbsolutePath(Filename, BaseDirectory);
|
Result:=LazFileUtils.CreateAbsolutePath(Filename, BaseDirectory);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CopyFile(const SrcFilename, DestFilename: String;
|
function CopyFile(const SrcFilename, DestFilename: string;
|
||||||
Flags: TCopyFileFlags=[cffOverwriteFile]; ExceptionOnError: Boolean=False): Boolean;
|
Flags: TCopyFileFlags; ExceptionOnError: Boolean): boolean;
|
||||||
var
|
var
|
||||||
SrcHandle: THandle;
|
SrcHandle: THandle;
|
||||||
DestHandle: THandle;
|
DestHandle: THandle;
|
||||||
@ -269,7 +269,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: Boolean; ExceptionOnError: Boolean): boolean;
|
function CopyFile(const SrcFilename, DestFilename: string;
|
||||||
|
PreserveTime: boolean; ExceptionOnError: Boolean): boolean;
|
||||||
// Flags parameter can be used for the same thing.
|
// Flags parameter can be used for the same thing.
|
||||||
var
|
var
|
||||||
Flags: TCopyFileFlags;
|
Flags: TCopyFileFlags;
|
||||||
@ -354,7 +355,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ReadFileToString(const Filename: String): String;
|
function ReadFileToString(const Filename: string): string;
|
||||||
var
|
var
|
||||||
SrcHandle: THandle;
|
SrcHandle: THandle;
|
||||||
ReadCount: LongInt;
|
ReadCount: LongInt;
|
||||||
@ -381,10 +382,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SearchFileInPath(const Filename, BasePath, SearchPath,
|
function SearchFileInPath(const Filename, BasePath: string; SearchPath: string;
|
||||||
Delimiter: string; Flags: TSearchFileInPathFlags): string;
|
const Delimiter: string; Flags: TSearchFileInPathFlags): string;
|
||||||
var
|
var
|
||||||
p, StartPos, l: integer;
|
p, StartPos, l, QuoteStart: integer;
|
||||||
CurPath, Base: string;
|
CurPath, Base: string;
|
||||||
begin
|
begin
|
||||||
//debugln('[SearchFileInPath] Filename="',Filename,'" BasePath="',BasePath,'" SearchPath="',SearchPath,'" Delimiter="',Delimiter,'"');
|
//debugln('[SearchFileInPath] Filename="',Filename,'" BasePath="',BasePath,'" SearchPath="',SearchPath,'" Delimiter="',Delimiter,'"');
|
||||||
@ -411,8 +412,27 @@ begin
|
|||||||
l:=length(SearchPath);
|
l:=length(SearchPath);
|
||||||
while StartPos<=l do begin
|
while StartPos<=l do begin
|
||||||
p:=StartPos;
|
p:=StartPos;
|
||||||
while (p<=l) and (pos(SearchPath[p],Delimiter)<1) do inc(p);
|
while (p<=l) and (pos(SearchPath[p],Delimiter)<1) do
|
||||||
CurPath:=TrimFilename(copy(SearchPath,StartPos,p-StartPos));
|
begin
|
||||||
|
if (SearchPath[p]='"') and (sffDequoteSearchPath in Flags) then
|
||||||
|
begin
|
||||||
|
// For example: Windows allows set path=C:\"a;b c"\d;%path%
|
||||||
|
QuoteStart:=p;
|
||||||
|
repeat
|
||||||
|
inc(p);
|
||||||
|
until (p>l) or (SearchPath[p]='"');
|
||||||
|
if p<=l then
|
||||||
|
begin
|
||||||
|
system.delete(SearchPath,p,1);
|
||||||
|
system.delete(SearchPath,QuoteStart,1);
|
||||||
|
dec(l,2);
|
||||||
|
dec(p,2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
|
CurPath:=copy(SearchPath,StartPos,p-StartPos);
|
||||||
|
CurPath:=TrimFilename(CurPath);
|
||||||
if CurPath<>'' then begin
|
if CurPath<>'' then begin
|
||||||
if not FilenameIsAbsolute(CurPath) then
|
if not FilenameIsAbsolute(CurPath) then
|
||||||
CurPath:=Base+CurPath;
|
CurPath:=Base+CurPath;
|
||||||
@ -584,8 +604,6 @@ end;
|
|||||||
|
|
||||||
function FindDefaultExecutablePath(const Executable: string;
|
function FindDefaultExecutablePath(const Executable: string;
|
||||||
const BaseDir: string): string;
|
const BaseDir: string): string;
|
||||||
const
|
|
||||||
Flags : TSearchFileInPathFlags = [{$IFDEF Unix}sffDontSearchInBasePath{$ENDIF}];
|
|
||||||
var
|
var
|
||||||
Env: string;
|
Env: string;
|
||||||
begin
|
begin
|
||||||
@ -600,11 +618,11 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end else begin
|
end else begin
|
||||||
Env:=GetEnvironmentVariableUTF8('PATH');
|
Env:=GetEnvironmentVariableUTF8('PATH');
|
||||||
Result:=SearchFileInPath(Executable, BaseDir, Env, PathSeparator, Flags);
|
Result:=SearchFileInPath(Executable, BaseDir, Env, PathSeparator, sffFindProgramInPath);
|
||||||
if Result<>'' then exit;
|
if Result<>'' then exit;
|
||||||
{$IFDEF Windows}
|
{$IFDEF Windows}
|
||||||
if ExtractFileExt(Executable)='' then begin
|
if ExtractFileExt(Executable)='' then begin
|
||||||
Result:=SearchFileInPath(Executable+'.exe', BaseDir, Env, PathSeparator, Flags);
|
Result:=SearchFileInPath(Executable+'.exe', BaseDir, Env, PathSeparator, sffFindProgramInPath);
|
||||||
if Result<>'' then exit;
|
if Result<>'' then exit;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
@ -77,12 +77,23 @@ function ReadFileToString(const Filename: string): string;
|
|||||||
type
|
type
|
||||||
TSearchFileInPathFlag = (
|
TSearchFileInPathFlag = (
|
||||||
sffDontSearchInBasePath, // do not search in BasePath, search only in SearchPath.
|
sffDontSearchInBasePath, // do not search in BasePath, search only in SearchPath.
|
||||||
sffSearchLoUpCase
|
sffSearchLoUpCase,
|
||||||
|
sffFile, // must be file, not directory
|
||||||
|
sffExecutable, // file must be executable
|
||||||
|
sffDequoteSearchPath // ansi dequote
|
||||||
);
|
);
|
||||||
TSearchFileInPathFlags = set of TSearchFileInPathFlag;
|
TSearchFileInPathFlags = set of TSearchFileInPathFlag;
|
||||||
|
const
|
||||||
|
sffFindProgramInPath = [
|
||||||
|
{$IFDEF Unix}sffDontSearchInBasePath,{$ENDIF}
|
||||||
|
{$IFDEF Windows}sffDequoteSearchPath,{$ENDIF}
|
||||||
|
sffFile,
|
||||||
|
sffExecutable
|
||||||
|
];
|
||||||
|
|
||||||
function SearchFileInPath(const Filename, BasePath, SearchPath,
|
function SearchFileInPath(const Filename, BasePath: string;
|
||||||
Delimiter: string; Flags: TSearchFileInPathFlags): string; overload;
|
SearchPath: string; const Delimiter: string;
|
||||||
|
Flags: TSearchFileInPathFlags): string; overload;
|
||||||
function SearchAllFilesInPath(const Filename, BasePath, SearchPath,
|
function SearchAllFilesInPath(const Filename, BasePath, SearchPath,
|
||||||
Delimiter: string; Flags: TSearchFileInPathFlags): TStrings;
|
Delimiter: string; Flags: TSearchFileInPathFlags): TStrings;
|
||||||
function FindDiskFilename(const Filename: string): string;
|
function FindDiskFilename(const Filename: string): string;
|
||||||
|
Loading…
Reference in New Issue
Block a user