Added controlled fail conditions for for Number
This commit is contained in:
parent
c6477cb342
commit
ab604877be
|
@ -1,10 +1,12 @@
|
||||||
using System.Xml.Serialization;
|
using System.Linq;
|
||||||
|
using System.Xml.Serialization;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
|
||||||
using BFR.Helpers;
|
using BFR.Helpers;
|
||||||
using BFR.DataModels;
|
using BFR.DataModels;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace BFR.Operations
|
namespace BFR.Operations
|
||||||
{
|
{
|
||||||
|
@ -36,6 +38,16 @@ namespace BFR.Operations
|
||||||
? (StartIndex + Increment * (files.Count - 1)).ToString().Length
|
? (StartIndex + Increment * (files.Count - 1)).ToString().Length
|
||||||
: Padding;
|
: Padding;
|
||||||
|
|
||||||
|
// Fail conditions: Out of bounds insert
|
||||||
|
var shortestLength = files.Min(x => FullName ? x.FullName.Length : x.Name.Length);
|
||||||
|
if (Mode == NumberMode.Insert && InsertPosition > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength}).");
|
||||||
|
|
||||||
|
// Regex Failure
|
||||||
|
if (Mode == NumberMode.Replace && UseRegex)
|
||||||
|
try { "".Replace(Pattern, "", true, false); }
|
||||||
|
catch (Exception) { throw new OperationException("Invalid Regex Pattern."); }
|
||||||
|
|
||||||
|
// Apply operation
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
var newName = FullName ? file.FullName : file.Name;
|
var newName = FullName ? file.FullName : file.Name;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user