Skip to content

Commit 4fa16ad

Browse files
committed
Updated to new Version with logs
1 parent 7fdd330 commit 4fa16ad

File tree

3 files changed

+102
-33
lines changed

3 files changed

+102
-33
lines changed

CopyFolderTool/MainWindow.xaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:CopyFolderTool"
77
mc:Ignorable="d"
8-
Title="CopyFolderTool" Height="400" MaxHeight="400" Width="420" MaxWidth="550" Background="#FFD1D1D1" Icon="Icon-CopyFolderTool.ico"
8+
Title="CopyFolderTool" Height="490" MaxHeight="600" Width="420" MaxWidth="550" Background="#FFD1D1D1" Icon="Icon-CopyFolderTool.ico"
99
ResizeMode="CanResize">
1010
<StackPanel Margin="10">
1111
<Label FontWeight="Bold">Source Folder</Label>
@@ -15,7 +15,7 @@
1515
<ColumnDefinition Width="Auto" />
1616
</Grid.ColumnDefinitions>
1717
<TextBox Name="fieldSource" Margin="5" Padding="3" Grid.Column="0" HorizontalAlignment="Stretch"/>
18-
<Button Name="btn_SourcePath" Content=". . ." Margin="5" Click="selectDestinationFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
18+
<Button Name="btn_SourcePath" Content=". . ." Margin="5" Click="selectFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
1919
</Grid>
2020

2121
<Label FontWeight="Bold">Destination Folder</Label>
@@ -25,7 +25,7 @@
2525
<ColumnDefinition Width="Auto" />
2626
</Grid.ColumnDefinitions>
2727
<TextBox Name="fieldDestination" Margin="5" Padding="3" Grid.Column="0" HorizontalAlignment="Stretch"/>
28-
<Button Name="btn_DestinationPath" Content=". . ." Margin="5" Click="selectDestinationFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
28+
<Button Name="btn_DestinationPath" Content=". . ." Margin="5" Click="selectFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
2929
</Grid>
3030

3131
<Label FontWeight="Bold">Copy Options</Label>
@@ -35,6 +35,16 @@
3535

3636
<Label FontWeight="Bold">More Options</Label>
3737
<CheckBox Name="option_Shutdown" Margin="5">Shutdown the computer after copying</CheckBox>
38+
<CheckBox Name="option_Logfile" Margin="5">Create Logfile</CheckBox>
39+
<Label FontWeight="Bold">Logfile Folder</Label>
40+
<Grid HorizontalAlignment="Stretch" DockPanel.Dock="Top">
41+
<Grid.ColumnDefinitions>
42+
<ColumnDefinition Width="3*"/>
43+
<ColumnDefinition Width="Auto" />
44+
</Grid.ColumnDefinitions>
45+
<TextBox Name="fieldLogfile" Margin="5" Padding="3" Grid.Column="0" HorizontalAlignment="Stretch" TextWrapping="NoWrap" AcceptsReturn="False" IsEnabled="{Binding ElementName=option_Logfile, Path=IsChecked, TargetNullValue=false}"/>
46+
<Button Name="btn_Logfile" Content=". . ." Margin="5" Click="selectFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1" IsEnabled="{Binding ElementName=option_Logfile, Path=IsChecked, TargetNullValue=false}"/>
47+
</Grid>
3848
<Grid HorizontalAlignment="Stretch" DockPanel.Dock="Top" Margin="0,20,0,0">
3949
<Grid.ColumnDefinitions>
4050
<ColumnDefinition Width="1*"/>
@@ -43,6 +53,6 @@
4353
<Button Name="btn_startComparing" Content="Compare folders" Margin="5,0,5,5" Click="StartRobocopy" Padding="3" Grid.Column="0"/>
4454
<Button Name="btn_startCopying" Content="Start copying" Margin="5,0,5,5" Click="StartRobocopy" Padding="3" Grid.Column="1"/>
4555
</Grid>
46-
<TextBlock Margin="5" IsEnabled="False" Opacity="0.5" HorizontalAlignment="Right">Version 1.0.4</TextBlock>
56+
<TextBlock Margin="5" IsEnabled="False" Opacity="0.5" HorizontalAlignment="Right">Version 1.1.0</TextBlock>
4757
</StackPanel>
4858
</Window>

CopyFolderTool/MainWindow.xaml.cs

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using Microsoft.WindowsAPICodePack.Dialogs;
22
using System;
3+
using System.IO;
34
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Shapes;
7+
using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System;
48

59
namespace CopyFolderTool
610
{
@@ -9,6 +13,11 @@ namespace CopyFolderTool
913
/// </summary>
1014
public partial class MainWindow : Window
1115
{
16+
17+
static string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
18+
static string strWorkPath = System.IO.Path.GetDirectoryName(strExeFilePath);
19+
static string strSettingsFilePath = System.IO.Path.Combine(strWorkPath, "Paths.config");
20+
1221
public MainWindow()
1322
{
1423
InitializeComponent();
@@ -17,19 +26,34 @@ public MainWindow()
1726
{
1827
fieldSource.Text = checkForBackslash(App.mArgs[0]);
1928
}
29+
30+
readLogfilePath();
2031
}
2132
private void StartRobocopy(object sender, RoutedEventArgs e)
2233
{
2334
var button = sender as System.Windows.Controls.Button;
2435

2536
string command;
26-
string sourcePath = checkForBackslash(fieldSource.Text);
27-
string destinationPath = checkForBackslash(fieldDestination.Text);
37+
string sourcePath;
38+
string destinationPath;
39+
string logPath;
40+
41+
if (String.IsNullOrEmpty(fieldSource.Text) || String.IsNullOrEmpty(fieldDestination.Text))
42+
{
43+
MessageBox.Show("Please enter valid paths!", "Path missing", MessageBoxButton.OK, MessageBoxImage.Error);
44+
return;
45+
}
46+
else
47+
{
48+
sourcePath = checkForBackslash(fieldSource.Text);
49+
destinationPath = checkForBackslash(fieldDestination.Text);
50+
}
2851

2952
//Optionen
3053
string optionE = "";
3154
string optionXO = "";
3255
string optionMOV = "";
56+
string optionLog = "";
3357
string optionClose = "";
3458
string standardOptions = " /MT:8";
3559

@@ -48,6 +72,21 @@ private void StartRobocopy(object sender, RoutedEventArgs e)
4872
optionXO = " /MOV";
4973
}
5074

75+
if (option_Logfile.IsChecked == true)
76+
{
77+
if (String.IsNullOrEmpty(fieldLogfile.Text))
78+
{
79+
MessageBox.Show("Please enter paths for log file.", "Path missing", MessageBoxButton.OK, MessageBoxImage.Error);
80+
return;
81+
}
82+
else
83+
{
84+
logPath = checkForBackslash(fieldLogfile.Text);
85+
// Pfad Probleme
86+
optionLog = " /LOG:\"" + logPath + "\\CopyFolderTool_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".log\" /TEE /NDL";
87+
}
88+
}
89+
5190
if(option_Shutdown.IsChecked == true)
5291
{
5392
optionClose = "/C ";
@@ -57,38 +96,32 @@ private void StartRobocopy(object sender, RoutedEventArgs e)
5796
optionClose = "/K ";
5897
}
5998

60-
if (sourcePath.Length != 0 && destinationPath.Length != 0)
99+
if (button.Name == "btn_startCopying")
61100
{
62-
if (button.Name == "btn_startCopying")
63-
{
64-
btn_startCopying.IsEnabled = false;
65-
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + optionE + optionXO + optionMOV + standardOptions;
66-
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
67-
process.WaitForExit();
68-
Application.Current.Shutdown();
69-
btn_startComparing.IsEnabled = true;
70-
71-
if (option_Shutdown.IsChecked == true)
72-
{
73-
_ = System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
74-
}
75-
}
76-
else if (button.Name == "btn_startComparing")
101+
btn_startCopying.IsEnabled = false;
102+
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + optionE + optionXO + optionMOV + optionLog + standardOptions;
103+
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
104+
process.WaitForExit();
105+
Application.Current.Shutdown();
106+
btn_startComparing.IsEnabled = true;
107+
108+
if (option_Shutdown.IsChecked == true)
77109
{
78-
btn_startComparing.IsEnabled = false;
79-
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + "/L /NJH /NJS /NP /NS";
80-
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
81-
process.WaitForExit();
82-
btn_startComparing.IsEnabled = true;
110+
_ = System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
83111
}
84112
}
85-
else
113+
else if (button.Name == "btn_startComparing")
86114
{
87-
MessageBox.Show("Please enter destination path!");
115+
btn_startComparing.IsEnabled = false;
116+
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + "/L /NJH /NJS /NP /NS";
117+
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
118+
process.WaitForExit();
119+
btn_startComparing.IsEnabled = true;
88120
}
121+
89122
}
90123

91-
private void selectDestinationFolder(object sender, RoutedEventArgs e)
124+
private void selectFolder(object sender, RoutedEventArgs e)
92125
{
93126
var button = sender as System.Windows.Controls.Button;
94127
var dialog = new CommonOpenFileDialog();
@@ -104,6 +137,10 @@ private void selectDestinationFolder(object sender, RoutedEventArgs e)
104137
case "btn_DestinationPath":
105138
fieldDestination.Text = dialog.FileName;
106139
break;
140+
case "btn_Logfile":
141+
fieldLogfile.Text = dialog.FileName;
142+
saveLogfilePath(fieldLogfile.Text);
143+
break;
107144
default:
108145
Console.WriteLine("Wrong Button");
109146
break;
@@ -124,6 +161,28 @@ private string checkForBackslash(string inputStr)
124161
}
125162
}
126163

164+
private void readLogfilePath()
165+
{
166+
if (!File.Exists(strSettingsFilePath))
167+
{
168+
using (StreamWriter sw = File.CreateText(strSettingsFilePath))
169+
{
170+
sw.WriteLine("C:\\Logs\\");
171+
}
172+
fieldLogfile.Text = "C:\\Logs\\";
173+
}
174+
else {
175+
string[] lines = File.ReadAllLines(strSettingsFilePath);
176+
fieldLogfile.Text = lines[0];
177+
}
178+
return;
179+
}
180+
private void saveLogfilePath(string path)
181+
{
182+
File.WriteAllText(strSettingsFilePath, path);
183+
return;
184+
}
185+
127186
protected override void OnClosed(EventArgs e)
128187
{
129188
base.OnClosed(e);

CopyFolderTool/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[assembly: AssemblyConfiguration("")]
1313
[assembly: AssemblyCompany("Tobias Wilhelm")]
1414
[assembly: AssemblyProduct("CopyFolderTool")]
15-
[assembly: AssemblyCopyright("Copyright © 2020")]
15+
[assembly: AssemblyCopyright("Copyright © 2022")]
1616
[assembly: AssemblyTrademark("")]
1717
[assembly: AssemblyCulture("")]
1818

@@ -51,6 +51,6 @@
5151
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5252
// indem Sie "*" wie unten gezeigt eingeben:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.4.0")]
55-
[assembly: AssemblyFileVersion("1.0.4.0")]
54+
[assembly: AssemblyVersion("1.1.0.0")]
55+
[assembly: AssemblyFileVersion("1.1.0.0")]
5656
[assembly: NeutralResourcesLanguage("en")]

0 commit comments

Comments
 (0)