Skip to content

Commit eb92011

Browse files
committed
Implement Copy as action
Closes #12
1 parent bab3c75 commit eb92011

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

PatternFileMover/Action/Copy.cs

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

PatternFileMover/Actions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public enum AvailableActions
1212
{
1313
[Description("grid.Action.Move")]
1414
Move = 0,
15+
[Description("grid.Action.Copy")]
16+
Copy = 1,
1517
}
1618

1719
public class AvailableAction

PatternFileMover/NameAssociationsForm.de.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,7 @@
174174
<data name="grid.Action.Move" xml:space="preserve">
175175
<value>Verschieben</value>
176176
</data>
177+
<data name="grid.Action.Copy" xml:space="preserve">
178+
<value>Kopieren</value>
179+
</data>
177180
</root>

PatternFileMover/NameAssociationsForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,7 @@
363363
<data name="grid.Action.Move" xml:space="preserve">
364364
<value>Move</value>
365365
</data>
366+
<data name="grid.Action.Copy" xml:space="preserve">
367+
<value>Copy</value>
368+
</data>
366369
</root>

PatternFileMover/PatternFileMover.csproj

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

0 commit comments

Comments
 (0)