IDE: clean directory: fixed checking reguar expression, bug #20382

git-svn-id: trunk@32574 -
This commit is contained in:
mattias 2011-09-30 18:48:38 +00:00
parent 8dc1234b17
commit 173b64a12c
4 changed files with 22 additions and 15 deletions

View File

@ -155,12 +155,9 @@ object CleanDirectoryDialog: TCleanDirectoryDialog
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.Caption = '&ОК' OKButton.Caption = '&ОК'
HelpButton.Name = 'HelpButton' HelpButton.Name = 'HelpButton'
HelpButton.Caption = '&Справка'
CloseButton.Name = 'CloseButton' CloseButton.Name = 'CloseButton'
CloseButton.Caption = '&Закрыть'
CloseButton.Enabled = False CloseButton.Enabled = False
CancelButton.Name = 'CancelButton' CancelButton.Name = 'CancelButton'
CancelButton.Caption = 'Отмена'
TabOrder = 3 TabOrder = 3
ShowButtons = [pbOK, pbCancel, pbHelp] ShowButtons = [pbOK, pbCancel, pbHelp]
ShowBevel = False ShowBevel = False

View File

@ -100,6 +100,7 @@ procedure TCleanDirectoryDialog.OkButtonClick(Sender: TObject);
var var
List: TStrings; List: TStrings;
begin begin
ModalResult:=mrNone;
SaveSettings; SaveSettings;
if not SearchFilesToDelete(List) then exit; if not SearchFilesToDelete(List) then exit;
try try
@ -325,6 +326,7 @@ var
const FilterAsText: string): boolean; const FilterAsText: string): boolean;
var var
Expr: String; Expr: String;
s: String;
begin begin
Result:=false; Result:=false;
if FilterAsText='' then begin if FilterAsText='' then begin
@ -339,12 +341,16 @@ var
Expr:=FilterAsText; Expr:=FilterAsText;
try try
Filter.Expression:=Expr; Filter.Expression:=Expr;
// do a simple test
Filter.Exec('test.file');
Result:=true; Result:=true;
except except
on E: Exception do begin on E: Exception do begin
MessageDlg('Invalid Mask', if SimpleSyntax then
'The mask "'+FilterAsText+'" is not a valid expression.', s:=Format(lisTheFileMaskIsInvalid, [FilterAsText])
mtError,[mbCancel],0); else
s:=Format(lisTheFileMaskIsNotAValidRegularExpression, [FilterAsText]);
MessageDlg(lisInvalidMask, s, mtError, [mbCancel], 0);
end; end;
end; end;
end; end;
@ -364,10 +370,10 @@ begin
Directory:=AppendPathDelim(Directory); Directory:=AppendPathDelim(Directory);
// setup filters // setup filters
SetupFilter(RemoveFilterRegExpr,SimpleSyntaxRemoveCheckbox.Checked, if not SetupFilter(RemoveFilterRegExpr,SimpleSyntaxRemoveCheckbox.Checked,
RemoveCombobox.Text); RemoveCombobox.Text) then exit;
SetupFilter(KeepFilterRegExpr,SimpleSyntaxKeepCheckbox.Checked, if not SetupFilter(KeepFilterRegExpr,SimpleSyntaxKeepCheckbox.Checked,
KeepCombobox.Text); KeepCombobox.Text) then exit;
// search files // search files
List:=TStringList.Create; List:=TStringList.Create;

View File

@ -2515,12 +2515,12 @@ end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
function SimpleSyntaxToRegExpr(const Src: string): string; function SimpleSyntaxToRegExpr(const Src: string): string;
. -> \.
* -> .* * -> .*
? -> . ? -> .
, -> | , -> |
; -> | ; -> |
Backslash characters .+
Finally enclose by ^( )$ Finally enclose by ^( )$
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function SimpleSyntaxToRegExpr(const Src: string): string; function SimpleSyntaxToRegExpr(const Src: string): string;
@ -2538,7 +2538,7 @@ begin
c:=Src[SrcPos]; c:=Src[SrcPos];
case c of case c of
'\': inc(SrcPos); '\': inc(SrcPos);
'*','.': '*','.','+':
inc(DestLen); inc(DestLen);
end; end;
inc(SrcPos); inc(SrcPos);
@ -2559,11 +2559,11 @@ begin
Result[DestPos]:=Src[SrcPos]; Result[DestPos]:=Src[SrcPos];
inc(DestPos); inc(DestPos);
end; end;
'.': '.','+':
begin begin
Result[DestPos]:='\'; Result[DestPos]:='\';
inc(DestPos); inc(DestPos);
Result[DestPos]:='.'; Result[DestPos]:=c;
inc(DestPos); inc(DestPos);
end; end;
'*': '*':

View File

@ -3316,6 +3316,10 @@ resourcestring
lisUnableToReadFile = 'Unable to read file'; lisUnableToReadFile = 'Unable to read file';
lisUnableToReadFilename = 'Unable to read file %s%s%s.'; lisUnableToReadFilename = 'Unable to read file %s%s%s.';
lisErrorDeletingFile = 'Error deleting file'; lisErrorDeletingFile = 'Error deleting file';
lisInvalidMask = 'Invalid Mask';
lisTheFileMaskIsNotAValidRegularExpression = 'The file mask "%s" is not a '
+'valid regular expression.';
lisTheFileMaskIsInvalid = 'The file mask "%s" is invalid.';
lisUnableToDeleteAmbiguousFile = 'Unable to delete ambiguous file %s%s%s'; lisUnableToDeleteAmbiguousFile = 'Unable to delete ambiguous file %s%s%s';
lisErrorRenamingFile = 'Error renaming file'; lisErrorRenamingFile = 'Error renaming file';
lisUnableToRenameAmbiguousFileTo = 'Unable to rename ambiguous file %s%s%s%' lisUnableToRenameAmbiguousFileTo = 'Unable to rename ambiguous file %s%s%s%'