Browse Source

Fix merge conflict, cleanup branch, update install script

tags/v1.2^2
Scott Barker 1 year ago
parent
commit
a7ed7c367e

+ 5
- 1
.gitignore View File

@@ -7,4 +7,8 @@ packages/*
*.suo
*.user
*.swp
dist
Dist/*
*.ide
*.ncrunch*
_NCrunch*
.nuget/

+ 1
- 0
.gitkeep View File

@@ -0,0 +1 @@
Dist/

+ 36
- 0
RegexRenamer.Tests/RegexRenamer.Tests.UnitTests/Properties/AssemblyInfo.cs View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RegexRenamer.Tests.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RegexRenamer.Tests.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7ffb3e10-6130-4caa-9f1a-c1c777dfae28")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 108
- 0
RegexRenamer.Tests/RegexRenamer.Tests.UnitTests/RegexRenamer.Tests.UnitTests.csproj View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RegexRenamer.Tests.UnitTests</RootNamespace>
<AssemblyName>RegexRenamer.Tests.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="RegexRenamerCoreUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\RegexRenamer\RegexRenamer.csproj">
<Project>{4086c5e2-518f-4c11-b891-95a36a6e945f}</Project>
<Name>RegexRenamer</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

BIN
RegexRenamer.Tests/RegexRenamer.Tests.UnitTests/RegexRenamer.Tests.UnitTests.v2.ncrunchproject View File


+ 286
- 0
RegexRenamer.Tests/RegexRenamer.Tests.UnitTests/RegexRenamerCoreUnitTests.cs View File

@@ -0,0 +1,286 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Xunit;
namespace RegexRenamer.Tests.UnitTests
{
public class RegexRenamerCoreUnitTests
{
public class Singleton
{
[Fact]
public void IsSingleton()
{
var core = RegexRenamerCore.Instance();
var core2 = RegexRenamerCore.Instance();
Assert.Equal(core, core2);
}
}
public class ScanFiles
{
[Fact]
public void UsesAllPatternForExistingDirectory()
{
var core = RegexRenamerCore.Instance();
core.ScanFiles(".");
Assert.Equal(".", core.CurrentPath);
Assert.Equal("*.*", core.CurrentPattern);
}
[Fact]
public void InterpretsPatternFromPath()
{
var core = RegexRenamerCore.Instance();
core.ScanFiles(@"C:\*.jpg");
Assert.Equal(@"C:\", core.CurrentPath);
Assert.Equal("*.jpg", core.CurrentPattern);
}
[Fact]
public void ReturnsFiles()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
}
}
public class PreviewRename
{
[Fact]
public void CorrectlyGeneratesNewName()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
files = core.PreviewRename(".tmp", ".foo");
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
Assert.EndsWith(".foo", files.First().Renamed);
}
[Fact]
public void ThrowsInvalidRegularExpression()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
var ex = Assert.Throws<ArgumentException>(() => core.PreviewRename("((tmp", ""));
Assert.Contains("expression is invalid", ex.Message);
}
[Fact]
public void ThrowsOnUnabalancedLeftExpressionMarkers()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
var ex = Assert.Throws<ArgumentException>(() => core.PreviewRename(".tmp", ".<<2+2>foo"));
Assert.Contains("balanced expression markers", ex.Message);
}
[Fact]
public void ThrowsOnUnabalancedRightExpressionMarkers()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
var ex = Assert.Throws<ArgumentException>(() => core.PreviewRename(".tmp", ".<2+2>>foo"));
Assert.Contains("balanced expression markers", ex.Message);
}
[Fact]
public void EvaluatesExpressions()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
files = core.PreviewRename(".tmp", ".<2+2>foo");
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
Assert.EndsWith(".4foo", files.First().Renamed);
}
[Fact]
public void EvaluatesExpressionsWithMatchReferences()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
File.Move(tempFile, tempFile + "2");
tempFile = tempFile + "2";
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
files = core.PreviewRename(@".tmp(\d)", ".<2+$1>foo");
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
Assert.EndsWith(".4foo", files.First().Renamed);
}
[Fact]
public void PadsNumbers()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
File.Move(tempFile, tempFile + "2");
tempFile = tempFile + "2";
Debug.Write(tempFile);
var files = core.ScanFiles(tempFile);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
Debug.Print(files.First().DisplayName);
files = core.PreviewRename(@".tmp(\d)", ".<$1:000>foo");
Debug.Print(files.First().Renamed);
Assert.NotNull(files);
Assert.NotEmpty(files);
Assert.Equal(1, files.Count());
Assert.Equal(tempFile, files.First().FullPath);
Assert.EndsWith(".002foo", files.First().Renamed);
}
}
public class RenameFiles
{
[Fact]
public void SkipsNonPreviewItems()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
core.ScanFiles(tempFile);
Assert.True(File.Exists(tempFile));
core.RenameFiles();
Assert.True(File.Exists(tempFile));
}
[Fact]
public void RenamesFile()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
core.ScanFiles(tempFile);
core.PreviewRename(".tmp", "$&.foo");
Assert.True(File.Exists(tempFile));
core.RenameFiles();
Assert.False(File.Exists(tempFile));
Assert.True(File.Exists(tempFile + ".foo"));
}
[Fact]
public void CreatesDestinationNonExistantDirectory()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
var guid = Guid.NewGuid().ToString();
core.ScanFiles(tempFile);
var items = core.PreviewRename("^tmp", $"$&\\{guid}");
Assert.True(File.Exists(tempFile));
core.RenameFiles();
Assert.False(File.Exists(tempFile));
Debug.Print($"Renamed: {items.First().Renamed}");
var renamed = Path.Combine(core.CurrentPath, items.First().Renamed);
Assert.True(File.Exists(renamed));
}
[Fact]
public void DoesNotMoveWhenNotRenamed()
{
var core = RegexRenamerCore.Instance();
var tempFile = Path.GetTempFileName();
var files = core.ScanFiles(tempFile);
core.PreviewRename(@"^", "$&");
Assert.True(File.Exists(tempFile));
core.RenameFiles();
Assert.True(File.Exists(tempFile));
}
}
}
}

+ 9
- 0
RegexRenamer.Tests/RegexRenamer.Tests.UnitTests/packages.config View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
</packages>

+ 10
- 2
RegexRenamer.sln View File

@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexRenamer", "RegexRenamer\RegexRenamer.csproj", "{4086C5E2-518F-4C11-B891-95A36A6E945F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C573B28A-46C1-4FD5-88AF-FD79215035DB}"
@@ -10,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C573B2
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexRenamer.Tests.UnitTests", "RegexRenamer.Tests\RegexRenamer.Tests.UnitTests\RegexRenamer.Tests.UnitTests.csproj", "{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -20,6 +24,10 @@ Global
{4086C5E2-518F-4C11-B891-95A36A6E945F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4086C5E2-518F-4C11-B891-95A36A6E945F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4086C5E2-518F-4C11-B891-95A36A6E945F}.Release|Any CPU.Build.0 = Release|Any CPU
{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FFB3E10-6130-4CAA-9F1A-C1C777DFAE28}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

+ 3
- 5
RegexRenamer/DisabledLabel.cs View File

@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RegexRenamer
{
class DisabledLabel : Label
[ExcludeFromCodeCoverage]
internal class DisabledLabel : Label
{
protected override void OnPaint(PaintEventArgs e)
{

+ 0
- 8
RegexRenamer/ExtensionMethods.cs View File

@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace RegexRenamer
{
@@ -20,10 +17,5 @@ namespace RegexRenamer
}
return true;
}

public static List<ListViewItem> ToList(this ListView.ListViewItemCollection items)
{
return items.Cast<ListViewItem>().ToList();
}
}
}

+ 17
- 0
RegexRenamer/FileItem.cs View File

@@ -0,0 +1,17 @@
namespace RegexRenamer
{
public class FileItem
{
public string DisplayName { get; }

public string FullPath { get; }

public string Renamed { get; set; }

public FileItem(string displayName, string fullPath)
{
DisplayName = displayName;
FullPath = fullPath;
}
}
}

+ 12
- 18
RegexRenamer/Main.Designer.cs View File

@@ -1,4 +1,7 @@
namespace RegexRenamer {
using System.Diagnostics.CodeAnalysis;
namespace RegexRenamer {
[ExcludeFromCodeCoverage]
partial class Main {
/// <summary>
/// Required designer variable.
@@ -39,9 +42,8 @@
this.checkBoxRecursive = new System.Windows.Forms.CheckBox();
this.buttonBrowse = new System.Windows.Forms.Button();
this.pictureIcon = new System.Windows.Forms.PictureBox();
this.checkboxEvaluateExpressions = new System.Windows.Forms.CheckBox();
this.labelCopyright = new RegexRenamer.DisabledLabel();
this.linkViewLog = new System.Windows.Forms.LinkLabel();
this.labelExpressionDescription = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).BeginInit();
this.SuspendLayout();
//
@@ -136,12 +138,6 @@
this.pictureIcon.TabStop = false;
this.pictureIcon.Click += new System.EventHandler(this.pictureIcon_Click);
//
// checkboxEvaluateExpressions
//
resources.ApplyResources(this.checkboxEvaluateExpressions, "checkboxEvaluateExpressions");
this.checkboxEvaluateExpressions.Name = "checkboxEvaluateExpressions";
this.checkboxEvaluateExpressions.UseVisualStyleBackColor = true;
//
// labelCopyright
//
resources.ApplyResources(this.labelCopyright, "labelCopyright");
@@ -149,18 +145,17 @@
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Click += new System.EventHandler(this.labelCopyright_Click);
//
// linkViewLog
// labelExpressionDescription
//
resources.ApplyResources(this.linkViewLog, "linkViewLog");
this.linkViewLog.Name = "linkViewLog";
this.linkViewLog.TabStop = true;
resources.ApplyResources(this.labelExpressionDescription, "labelExpressionDescription");
this.labelExpressionDescription.Name = "labelExpressionDescription";
//
// Main
//
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.linkViewLog);
this.Controls.Add(this.checkboxEvaluateExpressions);
// this.Controls.Add(this.checkboxEvaluateExpressions);
this.Controls.Add(this.labelExpressionDescription);
this.Controls.Add(this.pictureIcon);
this.Controls.Add(this.labelCopyright);
this.Controls.Add(this.buttonBrowse);
@@ -201,8 +196,7 @@
private System.Windows.Forms.Button buttonBrowse;
private DisabledLabel labelCopyright;
private System.Windows.Forms.PictureBox pictureIcon;
private System.Windows.Forms.CheckBox checkboxEvaluateExpressions;
private System.Windows.Forms.LinkLabel linkViewLog;
}
private System.Windows.Forms.Label labelExpressionDescription;
}
}

+ 26
- 32
RegexRenamer/Main.cs View File

@@ -3,15 +3,15 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Linq;
using NCalc;
namespace RegexRenamer
{
public partial class Main : Form
{
private IEnumerable<FileItem> _items;
public Main()
{
InitializeComponent();
@@ -24,64 +24,58 @@ namespace RegexRenamer
if (string.IsNullOrEmpty(textboxFiles.Text))
{
MessageBox.Show(
"You must enter a path to scan for files before scanning.",
"Error: Empty Path",
Strings.Strings.ErrorEmptyPathDescription,
Strings.Strings.ErrorEmptyPathTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return;
}
RegexRenamerCore regexRenamerCore = RegexRenamerCore.Instance();
regexRenamerCore.CurrentPath = textboxFiles.Text;
var regexRenamerCore = RegexRenamerCore.Instance();
listPreviews.Items.Clear();
List<ListViewItem> items = (List<ListViewItem>) regexRenamerCore.ScanForFiles(checkBoxRecursive.Checked);
if (items.Count == 0)
_items = regexRenamerCore.ScanFiles(textboxFiles.Text, checkBoxRecursive.Checked);
if (!_items.Any())
{
MessageBox.Show(
string.Format("No files were found matching '{0}'", Path.Combine(regexRenamerCore.CurrentPath, regexRenamerCore.CurrentPattern)),
"No Files Found",
string.Format(Strings.Strings.ErrorNoMatchingFilesDescription, Path.Combine(regexRenamerCore.CurrentPath, regexRenamerCore.CurrentPattern)),
Strings.Strings.ErrorNoMatchingFilesTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
else
{
listPreviews.Items.AddRange(items.ToArray());
SetListViewItems(_items);
}
}
private void buttonPreview_Click(object sender, EventArgs e)
{
if (!textboxPattern.Text.IsRegularExpression())
{
MessageBox.Show(
string.Format("Invalid regular expression specified for Pattern:\nPattern: {0}", textboxPattern.Text),
"Invalid Regular Expression",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return;
}
var regexRenamerCore = RegexRenamerCore.Instance();
_items = regexRenamerCore.PreviewRename(textboxPattern.Text, textboxReplace.Text);
RegexRenamerCore regexRenamerCore = RegexRenamerCore.Instance();
List<ListViewItem> items = regexRenamerCore.PreviewRename(listPreviews.Items.ToList(), textboxPattern.Text, textboxReplace.Text,
checkboxEvaluateExpressions.Checked);
SetListViewItems(_items);
}
private void SetListViewItems(IEnumerable<FileItem> items)
{
listPreviews.Items.Clear();
listPreviews.Items.AddRange(items.ToArray());
var listItems = _items.Select(item => new ListViewItem(new[] { item.DisplayName, item.Renamed }));
listPreviews.Items.AddRange(listItems.ToArray());
}
private void buttonApply_Click(object sender, EventArgs e)
{
RegexRenamerCore regexRenamerCore = RegexRenamerCore.Instance();
regexRenamerCore.RenameFiles(listPreviews.Items.ToList());
regexRenamerCore.ScanForFiles(checkBoxRecursive.Checked);
var regexRenamerCore = RegexRenamerCore.Instance();
regexRenamerCore.RenameFiles();
var items = regexRenamerCore.ScanFiles(textboxFiles.Text, checkBoxRecursive.Checked);
SetListViewItems(items);
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
FolderBrowserDialog browse = new FolderBrowserDialog();
var browse = new FolderBrowserDialog();
if (browse.ShowDialog() == DialogResult.OK)
{
textboxFiles.Text = browse.SelectedPath;
@@ -106,9 +100,9 @@ namespace RegexRenamer
private string GetExecutingAssemblyVersion()
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
var assembly = Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
var version = fvi.FileVersion;
return version;
}
}

+ 101
- 74
RegexRenamer/Main.resx View File

@@ -127,10 +127,13 @@
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="labelPath.Location" type="System.Drawing.Point, System.Drawing">
<value>10, 14</value>
<value>15, 22</value>
</data>
<data name="labelPath.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
</data>
<data name="labelPath.Size" type="System.Drawing.Size, System.Drawing">
<value>32, 13</value>
<value>46, 20</value>
</data>
<data name="labelPath.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
@@ -151,10 +154,13 @@
<value>15</value>
</data>
<data name="textboxFiles.Location" type="System.Drawing.Point, System.Drawing">
<value>91, 11</value>
<value>136, 17</value>
</data>
<data name="textboxFiles.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="textboxFiles.Size" type="System.Drawing.Size, System.Drawing">
<value>330, 20</value>
<value>493, 26</value>
</data>
<data name="textboxFiles.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
@@ -175,10 +181,13 @@
<value>NoControl</value>
</data>
<data name="buttonScan.Location" type="System.Drawing.Point, System.Drawing">
<value>640, 9</value>
<value>960, 14</value>
</data>
<data name="buttonScan.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="buttonScan.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
<value>112, 35</value>
</data>
<data name="buttonScan.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
@@ -205,7 +214,7 @@
<value>Original</value>
</data>
<data name="columnHeader1.Width" type="System.Int32, mscorlib">
<value>300</value>
<value>513</value>
</data>
<data name="columnHeader2.Text" xml:space="preserve">
<value>Renamed</value>
@@ -214,10 +223,13 @@
<value>265</value>
</data>
<data name="listPreviews.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 92</value>
<value>18, 142</value>
</data>
<data name="listPreviews.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="listPreviews.Size" type="System.Drawing.Size, System.Drawing">
<value>702, 388</value>
<value>1053, 597</value>
</data>
<data name="listPreviews.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
@@ -241,10 +253,13 @@
<value>NoControl</value>
</data>
<data name="buttonApply.Location" type="System.Drawing.Point, System.Drawing">
<value>638, 485</value>
<value>959, 750</value>
</data>
<data name="buttonApply.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="buttonApply.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
<value>112, 35</value>
</data>
<data name="buttonApply.TabIndex" type="System.Int32, mscorlib">
<value>12</value>
@@ -271,10 +286,13 @@
<value>NoControl</value>
</data>
<data name="labelPattern.Location" type="System.Drawing.Point, System.Drawing">
<value>10, 42</value>
<value>15, 65</value>
</data>
<data name="labelPattern.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
</data>
<data name="labelPattern.Size" type="System.Drawing.Size, System.Drawing">
<value>44, 13</value>
<value>65, 20</value>
</data>
<data name="labelPattern.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
@@ -295,10 +313,13 @@
<value>10</value>
</data>
<data name="textboxPattern.Location" type="System.Drawing.Point, System.Drawing">
<value>91, 39</value>
<value>136, 60</value>
</data>
<data name="textboxPattern.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="textboxPattern.Size" type="System.Drawing.Size, System.Drawing">
<value>330, 20</value>
<value>493, 26</value>
</data>
<data name="textboxPattern.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
@@ -319,10 +340,13 @@
<value>NoControl</value>
</data>
<data name="buttonPreview.Location" type="System.Drawing.Point, System.Drawing">
<value>640, 63</value>
<value>960, 97</value>
</data>
<data name="buttonPreview.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="buttonPreview.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
<value>112, 35</value>
</data>
<data name="buttonPreview.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
@@ -349,10 +373,13 @@
<value>NoControl</value>
</data>
<data name="labelReplace.Location" type="System.Drawing.Point, System.Drawing">
<value>10, 68</value>
<value>15, 105</value>
</data>
<data name="labelReplace.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
</data>
<data name="labelReplace.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 13</value>
<value>108, 20</value>
</data>
<data name="labelReplace.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
@@ -373,10 +400,13 @@
<value>7</value>
</data>
<data name="textboxReplace.Location" type="System.Drawing.Point, System.Drawing">
<value>91, 65</value>
<value>136, 100</value>
</data>
<data name="textboxReplace.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="textboxReplace.Size" type="System.Drawing.Size, System.Drawing">
<value>330, 20</value>
<value>493, 26</value>
</data>
<data name="textboxReplace.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
@@ -400,10 +430,13 @@
<value>NoControl</value>
</data>
<data name="checkBoxRecursive.Location" type="System.Drawing.Point, System.Drawing">
<value>427, 13</value>
<value>640, 20</value>
</data>
<data name="checkBoxRecursive.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="checkBoxRecursive.Size" type="System.Drawing.Size, System.Drawing">
<value>102, 17</value>
<value>146, 24</value>
</data>
<data name="checkBoxRecursive.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
@@ -427,10 +460,13 @@
<value>NoControl</value>
</data>
<data name="buttonBrowse.Location" type="System.Drawing.Point, System.Drawing">
<value>559, 9</value>
<value>838, 14</value>
</data>
<data name="buttonBrowse.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="buttonBrowse.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
<value>112, 35</value>
</data>
<data name="buttonBrowse.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
@@ -457,13 +493,10 @@
<value>NoControl</value>
</data>
<data name="pictureIcon.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 485</value>
</data>
<data name="pictureIcon.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 2, 2, 2</value>
<value>18, 748</value>
</data>
<data name="pictureIcon.Size" type="System.Drawing.Size, System.Drawing">
<value>36, 39</value>
<value>54, 60</value>
</data>
<data name="pictureIcon.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>StretchImage</value>
@@ -483,34 +516,25 @@
<data name="&gt;&gt;pictureIcon.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="checkboxEvaluateExpressions.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="checkboxEvaluateExpressions.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="checkboxEvaluateExpressions.Location" type="System.Drawing.Point, System.Drawing">
<value>426, 67</value>
</data>
<data name="checkboxEvaluateExpressions.Size" type="System.Drawing.Size, System.Drawing">
<value>127, 17</value>
<data name="linkViewLog.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="checkboxEvaluateExpressions.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
<data name="linkViewLog.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 23</value>
</data>
<data name="checkboxEvaluateExpressions.Text" xml:space="preserve">
<value>E&amp;valuate Expressions</value>
<data name="linkViewLog.TabIndex" type="System.Int32, mscorlib">
<value>16</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.Name" xml:space="preserve">
<value>checkboxEvaluateExpressions</value>
<data name="&gt;&gt;linkViewLog.Name" xml:space="preserve">
<value>linkViewLog</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="&gt;&gt;linkViewLog.Type" xml:space="preserve">
<value>System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.Parent" xml:space="preserve">
<data name="&gt;&gt;linkViewLog.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.ZOrder" xml:space="preserve">
<data name="&gt;&gt;linkViewLog.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="labelCopyright.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
@@ -520,19 +544,16 @@
<value>NoControl</value>
</data>
<data name="labelCopyright.Location" type="System.Drawing.Point, System.Drawing">
<value>52, 486</value>
</data>
<data name="labelCopyright.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 0, 2, 0</value>
<value>78, 750</value>
</data>
<data name="labelCopyright.Size" type="System.Drawing.Size, System.Drawing">
<value>370, 39</value>
<value>555, 60</value>
</data>
<data name="labelCopyright.TabIndex" type="System.Int32, mscorlib">
<value>13</value>
</data>
<data name="labelCopyright.Text" xml:space="preserve">
<value>Version ${version}. Copyright © 2012-2013 Scott D. Barker
<value>Version ${version}. Copyright © 2012-2016 Scott D. Barker
Licensed under the MIT License, http://license.sdbarker.com/regexrenamer
Source code is available at http://git.sdbarker.com/sdbarker/regexrenamer</value>
</data>
@@ -554,38 +575,41 @@ Source code is available at http://git.sdbarker.com/sdbarker/regexrenamer</value
<data name="linkViewLog.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="linkViewLog.Location" type="System.Drawing.Point, System.Drawing">
<value>655, 512</value>
<data name="labelExpressionDescription.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="linkViewLog.Size" type="System.Drawing.Size, System.Drawing">
<value>51, 13</value>
<data name="labelExpressionDescription.Location" type="System.Drawing.Point, System.Drawing">
<value>640, 105</value>
</data>
<data name="linkViewLog.TabIndex" type="System.Int32, mscorlib">
<value>14</value>
<data name="labelExpressionDescription.Size" type="System.Drawing.Size, System.Drawing">
<value>309, 20</value>
</data>
<data name="linkViewLog.Text" xml:space="preserve">
<value>View &amp;Log</value>
<data name="labelExpressionDescription.TabIndex" type="System.Int32, mscorlib">
<value>15</value>
</data>
<data name="&gt;&gt;linkViewLog.Name" xml:space="preserve">
<value>linkViewLog</value>
<data name="labelExpressionDescription.Text" xml:space="preserve">
<value>Use &lt; and &gt; to evaluate math expressions.</value>
</data>
<data name="&gt;&gt;linkViewLog.Type" xml:space="preserve">
<value>System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="&gt;&gt;labelExpressionDescription.Name" xml:space="preserve">
<value>labelExpressionDescription</value>
</data>
<data name="&gt;&gt;linkViewLog.Parent" xml:space="preserve">
<data name="&gt;&gt;labelExpressionDescription.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;labelExpressionDescription.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;linkViewLog.ZOrder" xml:space="preserve">
<data name="&gt;&gt;labelExpressionDescription.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 13</value>
<value>9, 20</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>722, 531</value>
<value>1085, 819</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@@ -1087,6 +1111,9 @@ Source code is available at http://git.sdbarker.com/sdbarker/regexrenamer</value
AAAmAAAAJgAAACYAAAAmAAAAJgAAACYAAAAmAAAAJgAAACYA
</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>RegexRenamer</value>
</data>
@@ -1108,4 +1135,4 @@ Source code is available at http://git.sdbarker.com/sdbarker/regexrenamer</value
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
</root>

+ 2
- 0
RegexRenamer/Program.cs View File

@@ -1,7 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
namespace RegexRenamer {
[ExcludeFromCodeCoverage]
static class Program {
/// <summary>
/// The main entry point for the application.

+ 3
- 0
RegexRenamer/Properties/Resources.Designer.cs View File

@@ -8,6 +8,8 @@
// </auto-generated>
//------------------------------------------------------------------------------
using System.Diagnostics.CodeAnalysis;
namespace RegexRenamer.Properties {
using System;
@@ -22,6 +24,7 @@ namespace RegexRenamer.Properties {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[ExcludeFromCodeCoverage]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;

+ 3
- 0
RegexRenamer/Properties/Settings.Designer.cs View File

@@ -8,11 +8,14 @@
// </auto-generated>
//------------------------------------------------------------------------------
using System.Diagnostics.CodeAnalysis;
namespace RegexRenamer.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
[ExcludeFromCodeCoverage]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

+ 13
- 3
RegexRenamer/RegexRenamer.csproj View File

@@ -18,6 +18,8 @@
<UpgradeBackupLocation />
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -29,11 +31,9 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -86,6 +86,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FileItem.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
@@ -101,6 +102,11 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
<Compile Include="RegexRenamerCore.cs" />
<Compile Include="Strings\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
@@ -119,6 +125,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Strings\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">

+ 151
- 114
RegexRenamer/RegexRenamerCore.cs View File

@@ -1,116 +1,153 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using NCalc;

namespace RegexRenamer
{
public class RegexRenamerCore
{

private string _currentPath;
public string CurrentPath
{
get { return _currentPath; }
set { _currentPath = value; }
}

private string _currentPattern;
public string CurrentPattern
{
get { return _currentPattern; }
set { _currentPattern = value; }
}

private static RegexRenamerCore _instance;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NCalc;
namespace RegexRenamer
{
public class RegexRenamerCore
{
private IEnumerable<FileItem> _items;
private string _currentPath;
public string CurrentPath => _currentPath;
private string _currentPattern;
public string CurrentPattern => _currentPattern;
private static RegexRenamerCore _instance;
private RegexRenamerCore()
{
}

public static RegexRenamerCore Instance(bool newInstance = false)
{
if (newInstance || _instance == null)
{
_instance = new RegexRenamerCore();
}
return _instance;
}

public IEnumerable<ListViewItem> ScanForFiles(bool recursive = false)
{
if (Directory.Exists(_currentPath))
{
_currentPattern = "*.*";
}
else
{
_currentPath = Path.GetDirectoryName(_currentPath);
_currentPattern = Path.GetFileName(_currentPath);
}

SearchOption option = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

IEnumerable<ListViewItem> items =
new DirectoryInfo(_currentPath).GetFiles(_currentPattern, option).Select(
fi => new ListViewItem(fi.FullName.Replace(_currentPath + @"\", ""))).ToList();
return items;

}

public List<ListViewItem> PreviewRename(List<ListViewItem> items, string pattern, string replacement, bool evaluate)
{
foreach (ListViewItem item in items)
{
string result = item.Text;
result = Regex.Replace(result, pattern, replacement);

if (evaluate)
{
MatchCollection expressions = Regex.Matches(result, "<(.+?)>");
foreach (Match m in expressions)
{
Expression expression = new Expression(m.Groups[1].Value);
var expressionResult = expression.Evaluate();
result = result.Replace(m.Groups[0].Value, Convert.ToString(expressionResult));
}
}
if (item.SubItems.Count > 1)
{
item.SubItems[1].Text = result;
}
else
{
item.SubItems.Add(result);
}
}
return items;
}

public void RenameFiles(List<ListViewItem> items)
{
foreach (ListViewItem item in items)
{
string source = Path.Combine(_currentPath, item.Text);
string dest = item.SubItems[1].Text;
if (!Directory.Exists(Path.GetDirectoryName(dest)))
{
dest = Path.Combine(_currentPath, dest);
}
if (!string.Equals(source, dest))
{
string destinationPath = Path.GetDirectoryName(dest);
if (!Directory.Exists(destinationPath))
{
Directory.CreateDirectory(destinationPath);
}
File.Move(source, dest);
}
}
}
}
}
}
public static RegexRenamerCore Instance(bool newInstance = false)
{
if (newInstance || _instance == null)
{
_instance = new RegexRenamerCore();
}
return _instance;
}
public IEnumerable<FileItem> ScanFiles(string path, bool recursive = false)
{
_currentPath = path;
if (Directory.Exists(_currentPath))
{
_currentPattern = "*.*";
}
else
{
_currentPattern = Path.GetFileName(_currentPath);
_currentPath = Path.GetDirectoryName(_currentPath);
}
var option = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
if (_currentPath != null && _currentPattern != null)
{
_items = new DirectoryInfo(_currentPath).GetFiles(_currentPattern, option)
.Select(fi => new FileItem(fi.FullName.Replace(_currentPath + @"\", ""), fi.FullName));
}
return _items;
}
public IEnumerable<FileItem> PreviewRename(string pattern, string replacement)
{
ValidateRegularExpression(pattern);
var newItems = new List<FileItem>();
foreach (var item in _items)
{
var result = Regex.Replace(item.DisplayName, pattern, replacement);
var leftExpressionMarkers = replacement.ToCharArray().Count(c => c == '<');
var rightExpressionMarkers = replacement.ToCharArray().Count(c => c == '>');
if (leftExpressionMarkers != rightExpressionMarkers)
{
throw new ArgumentException("The replacement string must have balanced expression markers.");
}
if (leftExpressionMarkers > 0)
{
var expressions = Regex.Matches(result, "<(.+?)>");
foreach (Match m in expressions)
{
var match = m.Groups[0].Value;
var expressionMatch = m.Groups[1].Value;
string expressionString;
if (expressionMatch.Contains(":"))
{
var parts = expressionMatch.Split(':');
expressionMatch = parts[0];
var expression = new Expression(expressionMatch);
var format = parts[1];
var expressionResult = Convert.ToInt32(expression.Evaluate());
expressionString = expressionResult.ToString(format);
}
else
{
var expression = new Expression(expressionMatch);
var expressionResult = Convert.ToInt32(expression.Evaluate());
expressionString = expressionResult.ToString();
}
result = result.Replace(match, expressionString);
}
}
item.Renamed = result;
newItems.Add(item);
}
_items = newItems;
return _items;
}
private void ValidateRegularExpression(string pattern)
{
if (!pattern.IsRegularExpression())
{
throw new ArgumentException("The specified regular expression is invalid.");
}
}
public void RenameFiles()
{
if (!_items.Any())
{
return;
}
foreach (var item in _items)
{
if (string.IsNullOrEmpty(item.Renamed))
{
continue;
}
var source = Path.Combine(_currentPath, item.DisplayName);
var dest = Path.Combine(_currentPath, item.Renamed);
if (string.Equals(source, dest))
{
continue;
}
var destinationPath = Path.GetDirectoryName(dest);
if (destinationPath != null)
{
if (!Directory.Exists(destinationPath))
{
Directory.CreateDirectory(destinationPath);
}
File.Move(source, dest);
}
}
}
}
}

+ 3
- 0
RegexRenamer/Resources.Designer.cs View File

@@ -8,6 +8,8 @@
// </auto-generated>
//------------------------------------------------------------------------------
using System.Diagnostics.CodeAnalysis;
namespace RegexRenamer {
using System;
@@ -22,6 +24,7 @@ namespace RegexRenamer {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[ExcludeFromCodeCoverage]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;

+ 99
- 0
RegexRenamer/Strings/Strings.Designer.cs View File

@@ -0,0 +1,99 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace RegexRenamer.Strings {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Strings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RegexRenamer.Strings.Strings", typeof(Strings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to You must enter a path to scan for files before scanning..
/// </summary>
internal static string ErrorEmptyPathDescription {
get {
return ResourceManager.GetString("ErrorEmptyPathDescription", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error: Empty Path.
/// </summary>
internal static string ErrorEmptyPathTitle {
get {
return ResourceManager.GetString("ErrorEmptyPathTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No files were found matching &apos;{0}&apos;.
/// </summary>
internal static string ErrorNoMatchingFilesDescription {
get {
return ResourceManager.GetString("ErrorNoMatchingFilesDescription", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No Files Found.
/// </summary>
internal static string ErrorNoMatchingFilesTitle {
get {
return ResourceManager.GetString("ErrorNoMatchingFilesTitle", resourceCulture);
}
}
}
}

+ 113
- 0
RegexRenamer/Strings/Strings.resx View File

@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 1.3

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ErrorEmptyPathDescription" xml:space="preserve">
<value>You must enter a path to scan for files before scanning.</value>
</data>
<data name="ErrorEmptyPathTitle" xml:space="preserve">
<value>Error: Empty Path</value>
</data>
<data name="ErrorNoMatchingFilesDescription" xml:space="preserve">
<value>No files were found matching '{0}'</value>
</data>
<data name="ErrorNoMatchingFilesTitle" xml:space="preserve">
<value>No Files Found</value>
</data>
</root>

+ 1
- 2
install.nsi View File

@@ -25,8 +25,7 @@ InstallDir "$PROGRAMFILES\${Vendor}\${Title}"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\${Vendor}\${Title}" ""
;Request application privileges for Windows Vista
RequestExecutionLevel user
RequestExecutionLevel admin
;--------------------------------
;Interface Settings

Loading…
Cancel
Save