mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 05:59:28 +02:00
lazutils: FindClose in try finally
This commit is contained in:
parent
cd514961b0
commit
df08d02d68
@ -113,20 +113,23 @@ begin
|
||||
Result:=false;
|
||||
CurSrcDir:=CleanAndExpandDirectory(DirectoryName);
|
||||
if FindFirstUTF8(CurSrcDir+GetAllFilesMask,DeleteMask,FileInfo)=0 then begin
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
|
||||
continue;
|
||||
CurFilename:=CurSrcDir+FileInfo.Name;
|
||||
if ((FileInfo.Attr and faDirectory)>0)
|
||||
{$ifdef unix} and ((FileInfo.Attr and faSymLink{%H-})=0) {$endif unix} then begin
|
||||
if not DeleteDirectory(CurFilename,false) then exit;
|
||||
end else begin
|
||||
if not DeleteFileUTF8(CurFilename) then exit;
|
||||
end;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
try
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
|
||||
continue;
|
||||
CurFilename:=CurSrcDir+FileInfo.Name;
|
||||
if ((FileInfo.Attr and faDirectory)>0)
|
||||
{$ifdef unix} and ((FileInfo.Attr and faSymLink{%H-})=0) {$endif unix} then begin
|
||||
if not DeleteDirectory(CurFilename,false) then exit;
|
||||
end else begin
|
||||
if not DeleteFileUTF8(CurFilename) then exit;
|
||||
end;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
finally
|
||||
FindCloseUTF8(FileInfo);
|
||||
end;
|
||||
end;
|
||||
FindCloseUTF8(FileInfo);
|
||||
if (not OnlyChildren) and (not RemoveDirUTF8(CurSrcDir)) then exit;
|
||||
Result:=true;
|
||||
end;
|
||||
@ -562,30 +565,33 @@ begin
|
||||
Ambiguous:=false;
|
||||
if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then
|
||||
begin
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
||||
then
|
||||
continue;
|
||||
if CompareFilenamesIgnoreCase(FileInfo.Name,CurFile)=0 then begin
|
||||
//debugln('FindDiskFilename ',FileInfo.Name,' ',CurFile);
|
||||
if FileInfo.Name=CurFile then begin
|
||||
// file found, has already the correct name
|
||||
AliasFile:='';
|
||||
break;
|
||||
end else begin
|
||||
// alias found, but has not the correct name
|
||||
if AliasFile='' then begin
|
||||
AliasFile:=FileInfo.Name;
|
||||
try
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
||||
then
|
||||
continue;
|
||||
if CompareFilenamesIgnoreCase(FileInfo.Name,CurFile)=0 then begin
|
||||
//debugln('FindDiskFilename ',FileInfo.Name,' ',CurFile);
|
||||
if FileInfo.Name=CurFile then begin
|
||||
// file found, has already the correct name
|
||||
AliasFile:='';
|
||||
break;
|
||||
end else begin
|
||||
// there are more than one candidate
|
||||
Ambiguous:=true;
|
||||
// alias found, but has not the correct name
|
||||
if AliasFile='' then begin
|
||||
AliasFile:=FileInfo.Name;
|
||||
end else begin
|
||||
// there are more than one candidate
|
||||
Ambiguous:=true;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
finally
|
||||
FindCloseUTF8(FileInfo);
|
||||
end;
|
||||
end;
|
||||
FindCloseUTF8(FileInfo);
|
||||
if (AliasFile<>'') and (not Ambiguous) then begin
|
||||
// better filename found -> replace
|
||||
Result:=CurDir+AliasFile+copy(Result,EndPos,length(Result));
|
||||
@ -604,25 +610,28 @@ begin
|
||||
Result:='';
|
||||
CurDir:=ExtractFilePath(ResolveDots(Filename));
|
||||
if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile, FileInfo)=0 then begin
|
||||
ShortFilename:=ExtractFilename(Filename);
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
||||
then
|
||||
continue;
|
||||
if CompareFilenamesIgnoreCase(FileInfo.Name,ShortFilename)<>0 then
|
||||
continue;
|
||||
if FileInfo.Name=ShortFilename then begin
|
||||
// fits exactly
|
||||
//Don't return (unaltered) Filename: otherwise possible changes by ResolveDots get lost
|
||||
try
|
||||
ShortFilename:=ExtractFilename(Filename);
|
||||
repeat
|
||||
// check if special file
|
||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
||||
then
|
||||
continue;
|
||||
if CompareFilenamesIgnoreCase(FileInfo.Name,ShortFilename)<>0 then
|
||||
continue;
|
||||
if FileInfo.Name=ShortFilename then begin
|
||||
// fits exactly
|
||||
//Don't return (unaltered) Filename: otherwise possible changes by ResolveDots get lost
|
||||
Result:=CurDir+FileInfo.Name;
|
||||
break;
|
||||
end;
|
||||
// fits case insensitive
|
||||
Result:=CurDir+FileInfo.Name;
|
||||
break;
|
||||
end;
|
||||
// fits case insensitive
|
||||
Result:=CurDir+FileInfo.Name;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
finally
|
||||
FindCloseUTF8(FileInfo);
|
||||
end;
|
||||
end;
|
||||
FindCloseUTF8(FileInfo);
|
||||
end;
|
||||
|
||||
function FindDefaultExecutablePath(const Executable: string;
|
||||
|
@ -611,11 +611,14 @@ begin
|
||||
Path:=ExtractFilePath(Filename);
|
||||
NameOnly:=ExtractFileNameOnly(Filename);
|
||||
if FindFirstUTF8(Path+GetAllFilesMask,faAnyFile,FileInfo)=0 then
|
||||
repeat
|
||||
if GetPOFilenameParts(FileInfo.Name, CurUnitName, CurLang) and (NameOnly=CurUnitName) then
|
||||
Result.Add(Path+FileInfo.Name);
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
FindCloseUTF8(FileInfo);
|
||||
try
|
||||
repeat
|
||||
if GetPOFilenameParts(FileInfo.Name, CurUnitName, CurLang) and (NameOnly=CurUnitName) then
|
||||
Result.Add(Path+FileInfo.Name);
|
||||
until FindNextUTF8(FileInfo)<>0;
|
||||
finally
|
||||
FindCloseUTF8(FileInfo);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure UpdatePoFileTranslations(const BasePOFilename: string; BasePOFile: TPOFile);
|
||||
|
Loading…
Reference in New Issue
Block a user