|
|
@@ -13,6 +13,8 @@ using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
using System.Threading;
|
|
|
+using System.Windows.Threading;
|
|
|
+using System.Diagnostics;
|
|
|
|
|
|
namespace barry
|
|
|
{
|
|
|
@@ -21,46 +23,45 @@ namespace barry
|
|
|
/// </summary>
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
- TextBoxOutputter outputter;
|
|
|
+ //TextBoxOutputter outputter;
|
|
|
Methods methods = new Methods();
|
|
|
|
|
|
+ string source;
|
|
|
+ string target;
|
|
|
+
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- connect_console_to_textbox();
|
|
|
+ //connect_console_to_textbox();
|
|
|
displays_barry_picture();
|
|
|
|
|
|
lbl_cpuname.Content = methods.computer_name();
|
|
|
lbl_driveletter.Content = methods.current_drive_label() + " (" + methods.current_drive_letter() + ")";
|
|
|
lbl_cpu_uuid.Content = methods.get_machine_guid();
|
|
|
-
|
|
|
- Console.WriteLine("**** BARRY Backup ****");
|
|
|
+
|
|
|
+ print("**** BARRY Backup ****");
|
|
|
|
|
|
//methods.register_this_cpu();
|
|
|
|
|
|
BackupConfig bkp = methods.load_this_cpu();
|
|
|
if (bkp == null)
|
|
|
{
|
|
|
- Console.WriteLine(">> unknown machine");
|
|
|
+ print(">> unknown machine");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- string target = bkp.dir_path;
|
|
|
- Console.WriteLine("Target of the backup: " + bkp.dir_path);
|
|
|
- string source = methods.current_drive_letter() + bkp.local_subdir;
|
|
|
- Console.WriteLine("Source: " + source);
|
|
|
-
|
|
|
- // // run in a separate thread
|
|
|
- //System.Threading.Thread.Sleep(3000);
|
|
|
- //methods.cmd( String.Format("ROBOCOPY {0} {1} /E /XO /w:1 /r:3", source, target) );
|
|
|
+ target = bkp.dir_path;
|
|
|
+ print("Target of the backup: " + bkp.dir_path);
|
|
|
+ source = methods.current_drive_letter() + bkp.local_subdir;
|
|
|
+ print("Source: " + source);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void connect_console_to_textbox()
|
|
|
- {
|
|
|
- outputter = new TextBoxOutputter(txt_console);
|
|
|
- Console.SetOut(outputter);
|
|
|
- }
|
|
|
+ //private void connect_console_to_textbox()
|
|
|
+ //{
|
|
|
+ // outputter = new TextBoxOutputter(txt_console);
|
|
|
+ // Console.SetOut(outputter);
|
|
|
+ //}
|
|
|
|
|
|
private void displays_barry_picture()
|
|
|
{
|
|
|
@@ -71,6 +72,80 @@ namespace barry
|
|
|
img_barry.Source = bitmap;
|
|
|
}
|
|
|
|
|
|
+ public void print(string line)
|
|
|
+ {
|
|
|
+ txt_console.AppendText(line + "\n");
|
|
|
+ txt_console.ScrollToEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// this void runs immediatly after the main window loaded
|
|
|
+ /// </summary>
|
|
|
+ private void autoexec()
|
|
|
+ {
|
|
|
+ //System.Threading.Thread.Sleep(7000);
|
|
|
+ //methods.cmd(String.Format("ROBOCOPY {0} {1} /E /XO /w:1 /r:3 /L", source, target));
|
|
|
+
|
|
|
+ // /E : recursive
|
|
|
+ // /XO : only copy newer files
|
|
|
+ // /w:1 /r:3 : if fails, retry 3 times waiting 1 sec each time
|
|
|
+ // /L : only list the ongoing copy, do not proceed
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnWindowLoaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Dispatcher.BeginInvoke(new Action(() => autoexec()), DispatcherPriority.ContextIdle, null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ cmd(String.Format("ROBOCOPY {0} {1} /E /XO /w:1 /r:3", source, target));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ cmd(String.Format("ROBOCOPY {0} {1} /E /XO /L", source, target));
|
|
|
+ //cmd("ping www.qwant.fr");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void cmd(string cmd)
|
|
|
+ {
|
|
|
+ using (System.Diagnostics.Process p = new System.Diagnostics.Process())
|
|
|
+ {
|
|
|
+ print(">> " + cmd);
|
|
|
+
|
|
|
+ p.StartInfo.FileName = "CMD.EXE";
|
|
|
+ p.StartInfo.Arguments = String.Format("/C {0}", cmd);
|
|
|
+
|
|
|
+ p.StartInfo.UseShellExecute = false;
|
|
|
+ p.StartInfo.RedirectStandardOutput = true;
|
|
|
+ //p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
|
|
|
+ //p.StartInfo.RedirectStandardInput = true;
|
|
|
+
|
|
|
+ p.StartInfo.RedirectStandardError = true;
|
|
|
+ //p.StartInfo.StandardErrorEncoding = Encoding.UTF8;
|
|
|
+ p.StartInfo.CreateNoWindow = true;
|
|
|
+ p.OutputDataReceived += new DataReceivedEventHandler(process_ouput_handler);
|
|
|
+ //p.ErrorDataReceived += new DataReceivedEventHandler(process_error_handler);
|
|
|
+
|
|
|
+ p.Start();
|
|
|
+ p.BeginOutputReadLine();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void process_ouput_handler(object sendingProcess, DataReceivedEventArgs outLine)
|
|
|
+ {
|
|
|
+ Dispatcher.BeginInvoke(new Action(() => print(outLine.Data)), DispatcherPriority.ContextIdle, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void process_error_handler(object sendingProcess, DataReceivedEventArgs outLine)
|
|
|
+ {
|
|
|
+ Dispatcher.BeginInvoke(new Action(() => print(outLine.Data)), DispatcherPriority.ContextIdle, null);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|