11using Microsoft . WindowsAPICodePack . Dialogs ;
22using System ;
3+ using System . IO ;
34using System . Windows ;
5+ using System . Windows . Controls ;
6+ using System . Windows . Shapes ;
7+ using static Microsoft . WindowsAPICodePack . Shell . PropertySystem . SystemProperties . System ;
48
59namespace 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 ) ;
0 commit comments