mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 08:59:10 +02:00
Converter: fix a memory-leak in ChgEncodingDlg
git-svn-id: trunk@30982 -
This commit is contained in:
parent
dfe29b10e2
commit
e41d0bfaf5
@ -277,69 +277,73 @@ begin
|
|||||||
|
|
||||||
// find files
|
// find files
|
||||||
IncludeFilterRegExpr:=TRegExpr.Create;
|
IncludeFilterRegExpr:=TRegExpr.Create;
|
||||||
Expr:=FileFilterCombobox.Text;
|
|
||||||
if not RegExprCheckBox.Checked then
|
|
||||||
Expr:=SimpleSyntaxToRegExpr(Expr);
|
|
||||||
ok:=false;
|
|
||||||
try
|
try
|
||||||
IncludeFilterRegExpr.Expression:=Expr;
|
Expr:=FileFilterCombobox.Text;
|
||||||
ok:=true;
|
if not RegExprCheckBox.Checked then
|
||||||
except
|
Expr:=SimpleSyntaxToRegExpr(Expr);
|
||||||
on E: Exception do begin
|
ok:=false;
|
||||||
DebugLn('Invalid Include File Expression ',Expr,' ',E.Message);
|
try
|
||||||
MessageDlg('Error in regular expression',
|
IncludeFilterRegExpr.Expression:=Expr;
|
||||||
E.Message,mtError,[mbCancel],0);
|
ok:=true;
|
||||||
|
except
|
||||||
|
on E: Exception do begin
|
||||||
|
DebugLn('Invalid Include File Expression ',Expr,' ',E.Message);
|
||||||
|
MessageDlg('Error in regular expression',
|
||||||
|
E.Message,mtError,[mbCancel],0);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
if not ok then exit;
|
||||||
if not ok then exit;
|
|
||||||
|
|
||||||
NewEncoding:=NormalizeEncoding(NewEncodingComboBox.Text);
|
NewEncoding:=NormalizeEncoding(NewEncodingComboBox.Text);
|
||||||
Tree:=TFilenameToStringTree.Create(FilenamesCaseSensitive);
|
Tree:=TFilenameToStringTree.Create(FilenamesCaseSensitive);
|
||||||
p:=1;
|
p:=1;
|
||||||
repeat
|
repeat
|
||||||
Dir:=GetNextDirectoryInSearchPath(SearchPath,p);
|
Dir:=GetNextDirectoryInSearchPath(SearchPath,p);
|
||||||
if p>length(SearchPath) then break;
|
if p>length(SearchPath) then break;
|
||||||
Dir:=AppendPathDelim(Dir);
|
Dir:=AppendPathDelim(Dir);
|
||||||
DebugLn(['TChgEncodingDialog.GetFiles Dir=',Dir]);
|
DebugLn(['TChgEncodingDialog.GetFiles Dir=',Dir]);
|
||||||
if FindFirstUTF8(Dir+FileMask,faAnyFile,FileInfo)=0 then begin
|
if FindFirstUTF8(Dir+FileMask,faAnyFile,FileInfo)=0 then begin
|
||||||
repeat
|
repeat
|
||||||
// check if special file
|
// check if special file
|
||||||
//DebugLn(['TChgEncodingDialog.GetFiles ',FileInfo.Name,' ... ']);
|
//DebugLn(['TChgEncodingDialog.GetFiles ',FileInfo.Name,' ... ']);
|
||||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
|
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
|
||||||
continue;
|
continue;
|
||||||
CurFilename:=Dir+FileInfo.Name;
|
CurFilename:=Dir+FileInfo.Name;
|
||||||
if Tree.Contains(CurFilename) then continue;
|
if Tree.Contains(CurFilename) then continue;
|
||||||
if not IncludeFilterRegExpr.Exec(CurFilename) then begin
|
if not IncludeFilterRegExpr.Exec(CurFilename) then begin
|
||||||
DebugLn(['TChgEncodingDialog.GetFiles not matching filter: ',CurFilename]);
|
DebugLn(['TChgEncodingDialog.GetFiles not matching filter: ',CurFilename]);
|
||||||
continue;
|
continue;
|
||||||
end;
|
|
||||||
if not FileIsTextCached(CurFilename) then begin
|
|
||||||
DebugLn(['TChgEncodingDialog.GetFiles not a text file: ',CurFilename]);
|
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (FileInfo.Attr and faDirectory)>0 then begin
|
|
||||||
// skip directory
|
|
||||||
end else begin
|
|
||||||
Buf:=CodeToolBoss.LoadFile(CurFilename,true,false);
|
|
||||||
if Buf<>nil then begin
|
|
||||||
//DebugLn(['TChgEncodingDialog.GetFiles Filename=',CurFilename,' Encoding=',NormalizeEncoding(Buf.DiskEncoding)]);
|
|
||||||
CurEncoding:=NormalizeEncoding(Buf.DiskEncoding);
|
|
||||||
if CurEncoding=NewEncoding then
|
|
||||||
continue;
|
|
||||||
if (CurEncoding=EncodingUTF8) and (not UTF8FilesCheckBox.Checked) then
|
|
||||||
continue;
|
|
||||||
if (CurEncoding<>EncodingUTF8) and (not NonUTF8FilesCheckBox.Checked) then
|
|
||||||
continue;
|
|
||||||
Tree[CurFilename]:=Buf.DiskEncoding;
|
|
||||||
end else begin
|
|
||||||
DebugLn(['TChgEncodingDialog.UpdatePreview read error: ',CurFilename]);
|
|
||||||
end;
|
end;
|
||||||
end;
|
if not FileIsTextCached(CurFilename) then begin
|
||||||
until FindNextUTF8(FileInfo)<>0;
|
DebugLn(['TChgEncodingDialog.GetFiles not a text file: ',CurFilename]);
|
||||||
end;
|
continue;
|
||||||
FindCloseUTF8(FileInfo);
|
end;
|
||||||
until false;
|
|
||||||
|
if (FileInfo.Attr and faDirectory)>0 then begin
|
||||||
|
// skip directory
|
||||||
|
end else begin
|
||||||
|
Buf:=CodeToolBoss.LoadFile(CurFilename,true,false);
|
||||||
|
if Buf<>nil then begin
|
||||||
|
//DebugLn(['TChgEncodingDialog.GetFiles Filename=',CurFilename,' Encoding=',NormalizeEncoding(Buf.DiskEncoding)]);
|
||||||
|
CurEncoding:=NormalizeEncoding(Buf.DiskEncoding);
|
||||||
|
if CurEncoding=NewEncoding then
|
||||||
|
continue;
|
||||||
|
if (CurEncoding=EncodingUTF8) and (not UTF8FilesCheckBox.Checked) then
|
||||||
|
continue;
|
||||||
|
if (CurEncoding<>EncodingUTF8) and (not NonUTF8FilesCheckBox.Checked) then
|
||||||
|
continue;
|
||||||
|
Tree[CurFilename]:=Buf.DiskEncoding;
|
||||||
|
end else begin
|
||||||
|
DebugLn(['TChgEncodingDialog.UpdatePreview read error: ',CurFilename]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until FindNextUTF8(FileInfo)<>0;
|
||||||
|
end;
|
||||||
|
FindCloseUTF8(FileInfo);
|
||||||
|
until false;
|
||||||
|
finally
|
||||||
|
IncludeFilterRegExpr.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChgEncodingDialog.UpdatePreview;
|
procedure TChgEncodingDialog.UpdatePreview;
|
||||||
|
Loading…
Reference in New Issue
Block a user