Browse Source

Initial commit for supporting mathematical expression evaluation in replacements

tags/v1.1
Scott Barker 6 years ago
parent
commit
3d9e64c1a9

+ 9
- 0
RegexRenamer/Main.Designer.cs View File

@@ -39,6 +39,7 @@
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();
((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).BeginInit();
this.SuspendLayout();
@@ -134,6 +135,12 @@
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");
@@ -145,6 +152,7 @@
//
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkboxEvaluateExpressions);
this.Controls.Add(this.pictureIcon);
this.Controls.Add(this.labelCopyright);
this.Controls.Add(this.buttonBrowse);
@@ -185,6 +193,7 @@
private System.Windows.Forms.Button buttonBrowse;
private DisabledLabel labelCopyright;
private System.Windows.Forms.PictureBox pictureIcon;
private System.Windows.Forms.CheckBox checkboxEvaluateExpressions;
}
}

+ 17
- 0
RegexRenamer/Main.cs View File

@@ -6,12 +6,18 @@ using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using RegexRenamer.Properties;
using System.Reflection;
using NCalc;
namespace RegexRenamer {
public partial class Main : Form {
static string currentPath = null;
public Main() {
InitializeComponent();
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
labelCopyright.Text = labelCopyright.Text.Replace("${version}", version);
}
private void buttonScan_Click(object sender, EventArgs e)
@@ -80,6 +86,17 @@ namespace RegexRenamer {
{
string result = item.Text;
result = Regex.Replace(result, textboxPattern.Text, textboxReplace.Text);
if (checkboxEvaluateExpressions.Checked)
{
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;

+ 91
- 97
RegexRenamer/Main.resx View File

@@ -127,13 +127,10 @@
</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>13, 13</value>
</data>
<data name="labelPath.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
<value>10, 14</value>
</data>
<data name="labelPath.Size" type="System.Drawing.Size, System.Drawing">
<value>41, 17</value>
<value>32, 13</value>
</data>
<data name="labelPath.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
@@ -151,16 +148,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;labelPath.ZOrder" xml:space="preserve">
<value>13</value>
<value>14</value>
</data>
<data name="textboxFiles.Location" type="System.Drawing.Point, System.Drawing">
<value>71, 13</value>
</data>
<data name="textboxFiles.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>91, 11</value>
</data>
<data name="textboxFiles.Size" type="System.Drawing.Size, System.Drawing">
<value>489, 22</value>
<value>330, 20</value>
</data>
<data name="textboxFiles.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
@@ -175,22 +169,19 @@
<value>$this</value>
</data>
<data name="&gt;&gt;textboxFiles.ZOrder" xml:space="preserve">
<value>12</value>
<value>13</value>
</data>
<data name="buttonScan.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="buttonScan.Location" type="System.Drawing.Point, System.Drawing">
<value>813, 10</value>
</data>
<data name="buttonScan.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>640, 9</value>
</data>
<data name="buttonScan.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 28</value>
<value>75, 23</value>
</data>
<data name="buttonScan.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
<value>4</value>
</data>
<data name="buttonScan.Text" xml:space="preserve">
<value>&amp;Scan</value>
@@ -205,7 +196,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;buttonScan.ZOrder" xml:space="preserve">
<value>11</value>
<value>12</value>
</data>
<data name="listPreviews.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
@@ -223,16 +214,13 @@
<value>265</value>
</data>
<data name="listPreviews.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 82</value>
</data>
<data name="listPreviews.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>12, 92</value>
</data>
<data name="listPreviews.Size" type="System.Drawing.Size, System.Drawing">
<value>897, 507</value>
<value>702, 388</value>
</data>
<data name="listPreviews.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
<value>11</value>
</data>
<data name="&gt;&gt;listPreviews.Name" xml:space="preserve">
<value>listPreviews</value>
@@ -244,7 +232,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;listPreviews.ZOrder" xml:space="preserve">
<value>10</value>
<value>11</value>
</data>
<data name="buttonApply.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
@@ -253,16 +241,13 @@
<value>NoControl</value>
</data>
<data name="buttonApply.Location" type="System.Drawing.Point, System.Drawing">
<value>813, 597</value>
</data>
<data name="buttonApply.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>638, 485</value>
</data>
<data name="buttonApply.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 28</value>
<value>75, 23</value>
</data>
<data name="buttonApply.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
<value>12</value>
</data>
<data name="buttonApply.Text" xml:space="preserve">
<value>&amp;Apply</value>
@@ -277,7 +262,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;buttonApply.ZOrder" xml:space="preserve">
<value>9</value>
<value>10</value>
</data>
<data name="labelPattern.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -286,13 +271,10 @@
<value>NoControl</value>
</data>
<data name="labelPattern.Location" type="System.Drawing.Point, System.Drawing">
<value>13, 52</value>
</data>
<data name="labelPattern.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
<value>10, 42</value>
</data>
<data name="labelPattern.Size" type="System.Drawing.Size, System.Drawing">
<value>58, 17</value>
<value>44, 13</value>
</data>
<data name="labelPattern.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
@@ -310,16 +292,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;labelPattern.ZOrder" xml:space="preserve">
<value>8</value>
<value>9</value>
</data>
<data name="textboxPattern.Location" type="System.Drawing.Point, System.Drawing">
<value>71, 49</value>
</data>
<data name="textboxPattern.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>91, 39</value>
</data>
<data name="textboxPattern.Size" type="System.Drawing.Size, System.Drawing">
<value>303, 22</value>
<value>330, 20</value>
</data>
<data name="textboxPattern.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
@@ -334,22 +313,19 @@
<value>$this</value>
</data>
<data name="&gt;&gt;textboxPattern.ZOrder" xml:space="preserve">
<value>7</value>
<value>8</value>
</data>
<data name="buttonPreview.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="buttonPreview.Location" type="System.Drawing.Point, System.Drawing">
<value>813, 46</value>
</data>
<data name="buttonPreview.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>640, 63</value>
</data>
<data name="buttonPreview.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 28</value>
<value>75, 23</value>
</data>
<data name="buttonPreview.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
<value>10</value>
</data>
<data name="buttonPreview.Text" xml:space="preserve">
<value>&amp;Preview</value>
@@ -364,7 +340,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;buttonPreview.ZOrder" xml:space="preserve">
<value>6</value>
<value>7</value>
</data>
<data name="labelReplace.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -373,13 +349,10 @@
<value>NoControl</value>
</data>
<data name="labelReplace.Location" type="System.Drawing.Point, System.Drawing">
<value>400, 52</value>
</data>
<data name="labelReplace.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
<value>10, 68</value>
</data>
<data name="labelReplace.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 17</value>
<value>75, 13</value>
</data>
<data name="labelReplace.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
@@ -397,16 +370,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;labelReplace.ZOrder" xml:space="preserve">
<value>5</value>
<value>6</value>
</data>
<data name="textboxReplace.Location" type="System.Drawing.Point, System.Drawing">
<value>502, 49</value>
</data>
<data name="textboxReplace.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>91, 65</value>
</data>
<data name="textboxReplace.Size" type="System.Drawing.Size, System.Drawing">
<value>303, 22</value>
<value>330, 20</value>
</data>
<data name="textboxReplace.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
@@ -421,28 +391,22 @@
<value>$this</value>
</data>
<data name="&gt;&gt;textboxReplace.ZOrder" xml:space="preserve">
<value>4</value>
<value>5</value>
</data>
<data name="checkBoxRecursive.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="checkBoxRecursive.CheckAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleRight</value>
</data>
<data name="checkBoxRecursive.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="checkBoxRecursive.Location" type="System.Drawing.Point, System.Drawing">
<value>676, 15</value>
</data>
<data name="checkBoxRecursive.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>427, 13</value>
</data>
<data name="checkBoxRecursive.Size" type="System.Drawing.Size, System.Drawing">
<value>129, 21</value>
<value>102, 17</value>
</data>
<data name="checkBoxRecursive.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
<value>2</value>
</data>
<data name="checkBoxRecursive.Text" xml:space="preserve">
<value>&amp;Recursive Scan</value>
@@ -457,22 +421,19 @@
<value>$this</value>
</data>
<data name="&gt;&gt;checkBoxRecursive.ZOrder" xml:space="preserve">
<value>3</value>
<value>4</value>
</data>
<data name="buttonBrowse.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="buttonBrowse.Location" type="System.Drawing.Point, System.Drawing">
<value>568, 10</value>
</data>
<data name="buttonBrowse.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<value>559, 9</value>
</data>
<data name="buttonBrowse.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 28</value>
<value>75, 23</value>
</data>
<data name="buttonBrowse.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
<value>3</value>
</data>
<data name="buttonBrowse.Text" xml:space="preserve">
<value>&amp;Browse</value>
@@ -487,7 +448,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;buttonBrowse.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<data name="pictureIcon.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
@@ -496,10 +457,13 @@
<value>NoControl</value>
</data>
<data name="pictureIcon.Location" type="System.Drawing.Point, System.Drawing">
<value>16, 597</value>
<value>12, 485</value>
</data>
<data name="pictureIcon.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 2, 2, 2</value>
</data>
<data name="pictureIcon.Size" type="System.Drawing.Size, System.Drawing">
<value>48, 48</value>
<value>36, 39</value>
</data>
<data name="pictureIcon.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>StretchImage</value>
@@ -517,51 +481,81 @@
<value>$this</value>
</data>
<data name="&gt;&gt;pictureIcon.ZOrder" xml:space="preserve">
<value>1</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>
<data name="checkboxEvaluateExpressions.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
</data>
<data name="checkboxEvaluateExpressions.Text" xml:space="preserve">
<value>E&amp;valuate Expressions</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.Name" xml:space="preserve">
<value>checkboxEvaluateExpressions</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>
<data name="&gt;&gt;checkboxEvaluateExpressions.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;checkboxEvaluateExpressions.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="labelCopyright.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="labelCopyright.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="labelCopyright.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="labelCopyright.Location" type="System.Drawing.Point, System.Drawing">
<value>69, 598</value>
<value>52, 486</value>
</data>
<data name="labelCopyright.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 0, 2, 0</value>
</data>
<data name="labelCopyright.Size" type="System.Drawing.Size, System.Drawing">
<value>480, 51</value>
<value>370, 39</value>
</data>
<data name="labelCopyright.TabIndex" type="System.Int32, mscorlib">
<value>12</value>
<value>13</value>
</data>
<data name="labelCopyright.Text" xml:space="preserve">
<value>Copyright © 2012 Scott D. Barker
<value>Version ${version}. Copyright © 2012-2013 Scott D. Barker
Licensed under the MIT License, http://license.sdbarker.com/regexrenamer
Source code is available at http://git.sdbarker.com/projects/regexrenamer</value>
Source code is available at http://git.sdbarker.com/sdbarker/regexrenamer</value>
</data>
<data name="&gt;&gt;labelCopyright.Name" xml:space="preserve">
<value>labelCopyright</value>
</data>
<data name="&gt;&gt;labelCopyright.Type" xml:space="preserve">
<value>RegexRenamer.DisabledLabel, RegexRenamer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>RegexRenamer.DisabledLabel, RegexRenamer, Version=1.1.4919.38106, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;labelCopyright.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;labelCopyright.ZOrder" xml:space="preserve">
<value>1</value>
<value>2</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>8, 16</value>
<value>6, 13</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>926, 653</value>
<value>722, 531</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@@ -1063,8 +1057,8 @@ Source code is available at http://git.sdbarker.com/projects/regexrenamer</value
AAAmAAAAJgAAACYAAAAmAAAAJgAAACYAAAAmAAAAJgAAACYA
</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
<data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>RegexRenamer</value>

+ 0
- 2
RegexRenamer/Program.cs View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace RegexRenamer {

+ 3
- 4
RegexRenamer/Properties/AssemblyInfo.cs View File

@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Scott D. Barker")]
[assembly: AssemblyProduct("RegexRenamer")]
[assembly: AssemblyCopyright("Copyright © Scott D. Barker 2012")]
[assembly: AssemblyCopyright("Copyright © Scott D. Barker 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -31,6 +31,5 @@ using System.Runtime.InteropServices;
//
// 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")]
[assembly: AssemblyVersion("1.1.*")]
// [assembly: AssemblyVersion("1.0.0.0")]

+ 4
- 0
RegexRenamer/RegexRenamer.csproj View File

@@ -60,6 +60,9 @@
<ApplicationIcon>RegexRenamer.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="NCalc">
<HintPath>..\packages\ncalc.1.3.8\lib\NCalc.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -113,6 +116,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

+ 4
- 0
RegexRenamer/packages.config View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ncalc" version="1.3.8" targetFramework="net40" />
</packages>

+ 4
- 0
packages/repositories.config View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\RegexRenamer\packages.config" />
</repositories>

Loading…
Cancel
Save