Skip to content

Commit 04745d6

Browse files
committed
Implement CopyOverwrite as action
Closes #14
1 parent 9a3de5e commit 04745d6

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.IO;
2+
using System.Windows.Forms;
3+
4+
namespace PatternFileMover.Action
5+
{
6+
internal class CopyOverwrite : AbstractAction
7+
{
8+
public bool DoCopyOverwrite()
9+
{
10+
File.Copy(
11+
this.GetSourcePath(),
12+
this.GetTargetPath() +
13+
Path.DirectorySeparatorChar +
14+
Path.GetFileName(this.GetCurrent().Cells[0].Value.ToString()
15+
),
16+
true
17+
);
18+
19+
return true;
20+
}
21+
22+
public override bool ExecuteAction()
23+
{
24+
return base.ExecuteAction();
25+
}
26+
27+
public override bool Matches(DataGridViewRow row)
28+
{
29+
if (!base.Matches(row))
30+
{
31+
return false;
32+
}
33+
34+
if (
35+
(
36+
this.GetFileExtension() == "*.*" &&
37+
Path.GetFileNameWithoutExtension(
38+
this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString()
39+
).Contains(this.GetSearchPattern())
40+
) ||
41+
(
42+
Path.GetFileNameWithoutExtension(
43+
this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString()
44+
).Contains(this.GetSearchPattern()) &&
45+
this.GetFileExtension() == Path.GetExtension(this.GetCurrent().Cells[(int)NameAssociationCellIndex.Name].Value.ToString())
46+
) &&
47+
(
48+
Directory.Exists(this.GetTargetPath() + Path.DirectorySeparatorChar)
49+
)
50+
)
51+
{
52+
return true;
53+
}
54+
55+
return false;
56+
}
57+
}
58+
}

PatternFileMover/Actions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public enum AvailableActions
1414
Move = 0,
1515
[Description("grid.Action.Copy")]
1616
Copy = 1,
17+
[Description("grid.Action.CopyOverwrite")]
18+
CopyOverwrite = 2,
1719
}
1820

1921
public class AvailableAction

PatternFileMover/NameAssociationsForm.de.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,7 @@
177177
<data name="grid.Action.Copy" xml:space="preserve">
178178
<value>Kopieren</value>
179179
</data>
180+
<data name="grid.Action.CopyOverwrite" xml:space="preserve">
181+
<value>Kopieren (Überschreiben)</value>
182+
</data>
180183
</root>

PatternFileMover/NameAssociationsForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,7 @@
366366
<data name="grid.Action.Copy" xml:space="preserve">
367367
<value>Copy</value>
368368
</data>
369+
<data name="grid.Action.CopyOverwrite" xml:space="preserve">
370+
<value>Copy (Overwrite)</value>
371+
</data>
369372
</root>

PatternFileMover/PatternFileMover.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<ItemGroup>
5252
<Compile Include="Actions.cs" />
5353
<Compile Include="Action\Copy.cs" />
54+
<Compile Include="Action\CopyOverwrite.cs" />
5455
<Compile Include="Action\IAction.cs" />
5556
<Compile Include="Action\Move.cs" />
5657
<Compile Include="Form2.cs">

0 commit comments

Comments
 (0)