lazutils: FindClose in try finally

This commit is contained in:
mattias 2024-01-15 15:21:41 +01:00
parent cd514961b0
commit df08d02d68
2 changed files with 67 additions and 55 deletions

View File

@ -113,6 +113,7 @@ begin
Result:=false; Result:=false;
CurSrcDir:=CleanAndExpandDirectory(DirectoryName); CurSrcDir:=CleanAndExpandDirectory(DirectoryName);
if FindFirstUTF8(CurSrcDir+GetAllFilesMask,DeleteMask,FileInfo)=0 then begin if FindFirstUTF8(CurSrcDir+GetAllFilesMask,DeleteMask,FileInfo)=0 then begin
try
repeat repeat
// check if special file // check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
@ -125,8 +126,10 @@ begin
if not DeleteFileUTF8(CurFilename) then exit; if not DeleteFileUTF8(CurFilename) then exit;
end; end;
until FindNextUTF8(FileInfo)<>0; until FindNextUTF8(FileInfo)<>0;
end; finally
FindCloseUTF8(FileInfo); FindCloseUTF8(FileInfo);
end;
end;
if (not OnlyChildren) and (not RemoveDirUTF8(CurSrcDir)) then exit; if (not OnlyChildren) and (not RemoveDirUTF8(CurSrcDir)) then exit;
Result:=true; Result:=true;
end; end;
@ -562,6 +565,7 @@ begin
Ambiguous:=false; Ambiguous:=false;
if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then
begin begin
try
repeat repeat
// check if special file // check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
@ -584,8 +588,10 @@ begin
end; end;
end; end;
until FindNextUTF8(FileInfo)<>0; until FindNextUTF8(FileInfo)<>0;
end; finally
FindCloseUTF8(FileInfo); FindCloseUTF8(FileInfo);
end;
end;
if (AliasFile<>'') and (not Ambiguous) then begin if (AliasFile<>'') and (not Ambiguous) then begin
// better filename found -> replace // better filename found -> replace
Result:=CurDir+AliasFile+copy(Result,EndPos,length(Result)); Result:=CurDir+AliasFile+copy(Result,EndPos,length(Result));
@ -604,6 +610,7 @@ begin
Result:=''; Result:='';
CurDir:=ExtractFilePath(ResolveDots(Filename)); CurDir:=ExtractFilePath(ResolveDots(Filename));
if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile, FileInfo)=0 then begin if FindFirstUTF8(CurDir+GetAllFilesMask,faAnyFile, FileInfo)=0 then begin
try
ShortFilename:=ExtractFilename(Filename); ShortFilename:=ExtractFilename(Filename);
repeat repeat
// check if special file // check if special file
@ -621,8 +628,10 @@ begin
// fits case insensitive // fits case insensitive
Result:=CurDir+FileInfo.Name; Result:=CurDir+FileInfo.Name;
until FindNextUTF8(FileInfo)<>0; until FindNextUTF8(FileInfo)<>0;
end; finally
FindCloseUTF8(FileInfo); FindCloseUTF8(FileInfo);
end;
end;
end; end;
function FindDefaultExecutablePath(const Executable: string; function FindDefaultExecutablePath(const Executable: string;

View File

@ -611,11 +611,14 @@ begin
Path:=ExtractFilePath(Filename); Path:=ExtractFilePath(Filename);
NameOnly:=ExtractFileNameOnly(Filename); NameOnly:=ExtractFileNameOnly(Filename);
if FindFirstUTF8(Path+GetAllFilesMask,faAnyFile,FileInfo)=0 then if FindFirstUTF8(Path+GetAllFilesMask,faAnyFile,FileInfo)=0 then
try
repeat repeat
if GetPOFilenameParts(FileInfo.Name, CurUnitName, CurLang) and (NameOnly=CurUnitName) then if GetPOFilenameParts(FileInfo.Name, CurUnitName, CurLang) and (NameOnly=CurUnitName) then
Result.Add(Path+FileInfo.Name); Result.Add(Path+FileInfo.Name);
until FindNextUTF8(FileInfo)<>0; until FindNextUTF8(FileInfo)<>0;
finally
FindCloseUTF8(FileInfo); FindCloseUTF8(FileInfo);
end;
end; end;
procedure UpdatePoFileTranslations(const BasePOFilename: string; BasePOFile: TPOFile); procedure UpdatePoFileTranslations(const BasePOFilename: string; BasePOFile: TPOFile);