Added controlled fail conditions for for Number

This commit is contained in:
adroslice 2019-11-22 19:18:07 +01:00
parent c6477cb342
commit ab604877be

View File

@ -1,10 +1,12 @@
using System.Xml.Serialization;
using System.Linq;
using System.Xml.Serialization;
using System.Collections.Generic;
using Avalonia;
using BFR.Helpers;
using BFR.DataModels;
using System;
namespace BFR.Operations
{
@ -36,6 +38,16 @@ namespace BFR.Operations
? (StartIndex + Increment * (files.Count - 1)).ToString().Length
: 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)
{
var newName = FullName ? file.FullName : file.Name;