Skip to content

Commit

Permalink
Updated to new Version with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
biteworks committed Nov 22, 2022
1 parent 7fdd330 commit 4fa16ad
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 33 deletions.
18 changes: 14 additions & 4 deletions CopyFolderTool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CopyFolderTool"
mc:Ignorable="d"
Title="CopyFolderTool" Height="400" MaxHeight="400" Width="420" MaxWidth="550" Background="#FFD1D1D1" Icon="Icon-CopyFolderTool.ico"
Title="CopyFolderTool" Height="490" MaxHeight="600" Width="420" MaxWidth="550" Background="#FFD1D1D1" Icon="Icon-CopyFolderTool.ico"
ResizeMode="CanResize">
<StackPanel Margin="10">
<Label FontWeight="Bold">Source Folder</Label>
Expand All @@ -15,7 +15,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Name="fieldSource" Margin="5" Padding="3" Grid.Column="0" HorizontalAlignment="Stretch"/>
<Button Name="btn_SourcePath" Content=". . ." Margin="5" Click="selectDestinationFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
<Button Name="btn_SourcePath" Content=". . ." Margin="5" Click="selectFolder" Padding="3" Width="38" HorizontalAlignment="Right" ToolTip="Select Folder" Grid.Column="1"/>
</Grid>

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

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

<Label FontWeight="Bold">More Options</Label>
<CheckBox Name="option_Shutdown" Margin="5">Shutdown the computer after copying</CheckBox>
<CheckBox Name="option_Logfile" Margin="5">Create Logfile</CheckBox>
<Label FontWeight="Bold">Logfile Folder</Label>
<Grid HorizontalAlignment="Stretch" DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<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}"/>
<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}"/>
</Grid>
<Grid HorizontalAlignment="Stretch" DockPanel.Dock="Top" Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand All @@ -43,6 +53,6 @@
<Button Name="btn_startComparing" Content="Compare folders" Margin="5,0,5,5" Click="StartRobocopy" Padding="3" Grid.Column="0"/>
<Button Name="btn_startCopying" Content="Start copying" Margin="5,0,5,5" Click="StartRobocopy" Padding="3" Grid.Column="1"/>
</Grid>
<TextBlock Margin="5" IsEnabled="False" Opacity="0.5" HorizontalAlignment="Right">Version 1.0.4</TextBlock>
<TextBlock Margin="5" IsEnabled="False" Opacity="0.5" HorizontalAlignment="Right">Version 1.1.0</TextBlock>
</StackPanel>
</Window>
111 changes: 85 additions & 26 deletions CopyFolderTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System;

namespace CopyFolderTool
{
Expand All @@ -9,6 +13,11 @@ namespace CopyFolderTool
/// </summary>
public partial class MainWindow : Window
{

static string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
static string strWorkPath = System.IO.Path.GetDirectoryName(strExeFilePath);
static string strSettingsFilePath = System.IO.Path.Combine(strWorkPath, "Paths.config");

public MainWindow()
{
InitializeComponent();
Expand All @@ -17,19 +26,34 @@ public MainWindow()
{
fieldSource.Text = checkForBackslash(App.mArgs[0]);
}

readLogfilePath();
}
private void StartRobocopy(object sender, RoutedEventArgs e)
{
var button = sender as System.Windows.Controls.Button;

string command;
string sourcePath = checkForBackslash(fieldSource.Text);
string destinationPath = checkForBackslash(fieldDestination.Text);
string sourcePath;
string destinationPath;
string logPath;

if (String.IsNullOrEmpty(fieldSource.Text) || String.IsNullOrEmpty(fieldDestination.Text))
{
MessageBox.Show("Please enter valid paths!", "Path missing", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
else
{
sourcePath = checkForBackslash(fieldSource.Text);
destinationPath = checkForBackslash(fieldDestination.Text);
}

//Optionen
string optionE = "";
string optionXO = "";
string optionMOV = "";
string optionLog = "";
string optionClose = "";
string standardOptions = " /MT:8";

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

if (option_Logfile.IsChecked == true)
{
if (String.IsNullOrEmpty(fieldLogfile.Text))
{
MessageBox.Show("Please enter paths for log file.", "Path missing", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
else
{
logPath = checkForBackslash(fieldLogfile.Text);
// Pfad Probleme
optionLog = " /LOG:\"" + logPath + "\\CopyFolderTool_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".log\" /TEE /NDL";
}
}

if(option_Shutdown.IsChecked == true)
{
optionClose = "/C ";
Expand All @@ -57,38 +96,32 @@ private void StartRobocopy(object sender, RoutedEventArgs e)
optionClose = "/K ";
}

if (sourcePath.Length != 0 && destinationPath.Length != 0)
if (button.Name == "btn_startCopying")
{
if (button.Name == "btn_startCopying")
{
btn_startCopying.IsEnabled = false;
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + optionE + optionXO + optionMOV + standardOptions;
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
process.WaitForExit();
Application.Current.Shutdown();
btn_startComparing.IsEnabled = true;

if (option_Shutdown.IsChecked == true)
{
_ = System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
}
}
else if (button.Name == "btn_startComparing")
btn_startCopying.IsEnabled = false;
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + optionE + optionXO + optionMOV + optionLog + standardOptions;
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
process.WaitForExit();
Application.Current.Shutdown();
btn_startComparing.IsEnabled = true;

if (option_Shutdown.IsChecked == true)
{
btn_startComparing.IsEnabled = false;
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + "/L /NJH /NJS /NP /NS";
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
process.WaitForExit();
btn_startComparing.IsEnabled = true;
_ = System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
}
}
else
else if (button.Name == "btn_startComparing")
{
MessageBox.Show("Please enter destination path!");
btn_startComparing.IsEnabled = false;
command = optionClose + "ROBOCOPY \"" + @sourcePath + "\" \"" + @destinationPath + "\" " + "/L /NJH /NJS /NP /NS";
System.Diagnostics.Process process = System.Diagnostics.Process.Start("CMD.exe", command);
process.WaitForExit();
btn_startComparing.IsEnabled = true;
}

}

private void selectDestinationFolder(object sender, RoutedEventArgs e)
private void selectFolder(object sender, RoutedEventArgs e)
{
var button = sender as System.Windows.Controls.Button;
var dialog = new CommonOpenFileDialog();
Expand All @@ -104,6 +137,10 @@ private void selectDestinationFolder(object sender, RoutedEventArgs e)
case "btn_DestinationPath":
fieldDestination.Text = dialog.FileName;
break;
case "btn_Logfile":
fieldLogfile.Text = dialog.FileName;
saveLogfilePath(fieldLogfile.Text);
break;
default:
Console.WriteLine("Wrong Button");
break;
Expand All @@ -124,6 +161,28 @@ private string checkForBackslash(string inputStr)
}
}

private void readLogfilePath()
{
if (!File.Exists(strSettingsFilePath))
{
using (StreamWriter sw = File.CreateText(strSettingsFilePath))
{
sw.WriteLine("C:\\Logs\\");
}
fieldLogfile.Text = "C:\\Logs\\";
}
else {
string[] lines = File.ReadAllLines(strSettingsFilePath);
fieldLogfile.Text = lines[0];
}
return;
}
private void saveLogfilePath(string path)
{
File.WriteAllText(strSettingsFilePath, path);
return;
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Expand Down
6 changes: 3 additions & 3 deletions CopyFolderTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Tobias Wilhelm")]
[assembly: AssemblyProduct("CopyFolderTool")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

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

0 comments on commit 4fa16ad

Please sign in to comment.