diff --git a/BFR/Operations/Replace.cs b/BFR/Operations/Replace.cs index 35b62ff..d57a6c9 100644 --- a/BFR/Operations/Replace.cs +++ b/BFR/Operations/Replace.cs @@ -38,14 +38,14 @@ namespace BFR.Operations { // Fail conditions: Various out-of-bounds var shortestLength = files.Min(x => FullName ? x.FullName.Length : x.Name.Length); - if (FirstN > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength})."); - if (LastN > shortestLength) throw new OperationException($"Last N can't be greater than the shortest file name length ({shortestLength})."); - if (FromN > shortestLength) throw new OperationException($"From N can't be greater than the shortest file name length ({shortestLength})."); - if (ToN > shortestLength) throw new OperationException($"To N can't be greater than the shortest file name length ({shortestLength})."); - if (FromN > ToN) throw new OperationException("From N can't be greater than To N."); + if (Mode == ReplaceMode.FirstN && FirstN > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength})."); + if (Mode == ReplaceMode.LastN && LastN > shortestLength) throw new OperationException($"Last N can't be greater than the shortest file name length ({shortestLength})."); + if (Mode == ReplaceMode.FromNToN && FromN > shortestLength) throw new OperationException($"From N can't be greater than the shortest file name length ({shortestLength})."); + if (Mode == ReplaceMode.FromNToN && ToN > shortestLength) throw new OperationException($"To N can't be greater than the shortest file name length ({shortestLength})."); + if (Mode == ReplaceMode.FromNToN && FromN > ToN) throw new OperationException("From N can't be greater than To N."); // Regex Failure - if(Modes[(int)Mode].IsPattern && UseRegex) + if(Mode == ReplaceMode.Pattern && UseRegex) try { "".Replace(Pattern, Replacement, true, false); } catch(Exception) { throw new OperationException("Invalid Regex Pattern."); }