浏览代码

main methods and window ok

olinox 9 年之前
父节点
当前提交
593e27ea1c

二进制
.vs/barry/v14/.suo


+ 6 - 2
barry/MainWindow.xaml

@@ -5,8 +5,12 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:barry"
         mc:Ignorable="d"
-        Title="MainWindow" Height="350" Width="525">
+        Title="Barry the Elephant" Height="350" Width="525">
     <Grid>
-        
+        <Image x:Name="img_barry" HorizontalAlignment="Left" Height="77" Margin="10,10,0,0" VerticalAlignment="Top" Width="78"/>
+        <Label x:Name="lbl_cpuname" Content="Current PC:" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Width="219"/>
+        <Label x:Name="lbl_driveletter" Content="Current drive:" HorizontalAlignment="Left" Margin="10,165,0,0" VerticalAlignment="Top" Width="219"/>
+
+        <TextBox x:Name="txt_console" Margin="234,10,10,10"/>
     </Grid>
 </Window>

+ 74 - 49
barry/MainWindow.xaml.cs

@@ -12,6 +12,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using System.Threading;
 
 namespace barry
 {
@@ -20,74 +21,98 @@ namespace barry
     /// </summary>
     public partial class MainWindow : Window
     {
+        TextBoxOutputter outputter;
+        Methods methods = new Methods();
+
         public MainWindow()
         {
             InitializeComponent();
+            connect_console();
+
+            displays_barry();
+
+            Console.WriteLine("**** BARRY Backup ****");
 
-            Console.WriteLine(am_i_the_good_source());
+            lbl_cpuname.Content = "CPU Name: " + methods.computer_name();
+            lbl_driveletter.Content = "Current drive: " + methods.current_drive_label() + " (" + methods.current_drive_letter() + ")";
 
-            string cpuname = System.Environment.MachineName;
-            Console.WriteLine(cpuname);
 
-            core.FileOp fo = new core.FileOp();
 
-            if (cpuname == "OLINOX-PC")
-            {
-                string source = String.Format("{0}\\", current_drive_letter());
-                string destination = "e:\\backup\\_OMASSOT\\";
 
-                fo.robocopy(source, destination);
-            }
 
-            
-            
         }
 
-        private string current_drive_letter()
+        private void connect_console()
         {
-            return System.IO.Path.GetPathRoot(Environment.CurrentDirectory);
+            outputter = new TextBoxOutputter(txt_console);
+            Console.SetOut(outputter);
         }
 
-        /// <summary>
-        /// control that the program is launched from the source
-        /// </summary>
-        /// <returns></returns>
-        private bool am_i_the_good_source()
+        private void displays_barry()
         {
-            // current drive letter
-            string driveLetter = current_drive_letter();
-
-            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
-            //Console.WriteLine("Detected Drives: ");
-            for (int i = 0; i < drives.Count(); i++)
-            {
-            
-                //Console.WriteLine("Drive " + i);
-                //Console.WriteLine("-" + drives[i].Name);
-                //Console.WriteLine("-" + drives[i].DriveType);
-                //if (drives[i].IsReady)
-                //{
-                //    Console.WriteLine("-" + drives[i].VolumeLabel);
-                //    Console.WriteLine("-" + drives[i].DriveFormat);
-                //}
-
-                if (drives[i].Name == driveLetter)
-                {
-                    if (drives[i].IsReady)
-                    {
-                        if (drives[i].VolumeLabel == "_OMASSOT")
-                        {
-                            return true;
-                        }
-                    }
-                }
-
-            }
-            return false;
+            BitmapImage bitmap = new BitmapImage();
+            bitmap.BeginInit();
+            bitmap.UriSource = new Uri("O:\\dev\\barry\\barry\\barrys_head.png");
+            bitmap.EndInit();
+            img_barry.Source = bitmap;
         }
 
+
+
     }
 
 
 
 }
+
+// *** BACKUP
+// 1- read the configuration file
+// IF NOT: warn, and create an empty, then quit
+// IF INVALID: warn and quit
+
+
+// 2- control media name to see if good source 
+//    OR check existnce of a file which is nor copied 
+//    OR mark the destination directory as a backup dir and warn before being launbching from there
+// IF NOT: quit
+
+// 3- check the computer name (or mac adress?)
+// if not found in cpu list: quit
+
+// 4- get the map letter and expand source
+
+// 5- get the destination path in config file
+// expands it
+// if none|inexistent|unauthorized, warn and displays a selection dialog
+// if cancelled, cancel prog and quit
+
+// 6- Displays the ongoing copy operation with source and destination
+
+// ***** to replace robocopy?
+// opt- analyse the source and destination:
+// build a tree of files
+// if source file do not exist in destination: copy
+// if source file is older than destination, replace it
+
+// #renamed file case:
+// if 2 files have same signature but differents names, propose to rename
+// #renamed dir case
+// 
+// #moved file case
+//
+// #moved dir case
+//
+// ****
+
+// 8- Waits 14 seconds and propose a key to cancel
+
+// 9- process to copy
+
+// 10- displays results
+
+// END OF BACKUP
+
+// other tools:
+// purge backup: propose to remove or trash destination files which do not exist anymore in source
+// add this computer: add a computer in the list of backup targets
+// enable autorun: copy usbAR on the post, configure and run

+ 11 - 0
barry/barry.csproj

@@ -34,6 +34,12 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <ApplicationIcon>icon.ico</ApplicationIcon>
+  </PropertyGroup>
+  <PropertyGroup>
+    <NoWin32Manifest>true</NoWin32Manifest>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Data" />
@@ -63,6 +69,8 @@
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="core\TextBoxOutputter.cs" />
+    <Compile Include="core\methods.cs" />
     <Compile Include="core\FileOp.cs" />
     <Compile Include="MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
@@ -96,6 +104,9 @@
   <ItemGroup>
     <None Include="App.config" />
   </ItemGroup>
+  <ItemGroup>
+    <Resource Include="icon.ico" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

二进制
barry/barrys_head.png


二进制
barry/bin/Debug/barry.exe


二进制
barry/bin/Debug/barry.pdb


+ 0 - 11
barry/bin/Debug/barry.vshost.exe.manifest

@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
-  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
-  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
-    <security>
-      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
-        <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
-      </requestedPrivileges>
-    </security>
-  </trustInfo>
-</assembly>

+ 36 - 0
barry/core/TextBoxOutputter.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+using System.Windows.Controls;
+
+namespace barry
+{
+    public class TextBoxOutputter : TextWriter
+    {
+        TextBox textBox = null;
+
+        public TextBoxOutputter(TextBox output)
+        {
+            textBox = output;
+        }
+
+        public override void Write(char value)
+        {
+            base.Write(value);
+            textBox.Dispatcher.BeginInvoke(new Action(() =>
+            {
+                textBox.AppendText(value.ToString());
+            }));
+        }
+
+        public override Encoding Encoding
+        {
+            get { return System.Text.Encoding.UTF8; }
+        }
+    }
+}
+
+

+ 112 - 0
barry/core/methods.cs

@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace barry
+{
+    public class Methods
+    {
+
+        public void read_config()
+        {
+
+        }
+
+        /// <summary>
+        /// returns the current drive letter
+        /// </summary>
+        /// <returns></returns>
+        public string current_drive_letter()
+        {
+            return System.IO.Path.GetPathRoot(Environment.CurrentDirectory);
+        }
+
+        /// <summary>
+        /// returns the current drive letter
+        /// </summary>
+        /// <returns></returns>
+        public string computer_name()
+        {
+            return System.Environment.MachineName;
+        }
+
+
+        /// <summary>
+        /// returns the current drive label
+        /// </summary>
+        /// <returns></returns>
+        public string current_drive_label()
+        {
+            // current drive letter
+            string driveLetter = current_drive_letter();
+
+            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
+            for (int i = 0; i < drives.Count(); i++)
+            {
+                if (drives[i].Name == driveLetter)
+                {
+                    if (drives[i].IsReady)
+                    {
+                        return drives[i].VolumeLabel;
+                    }
+                }
+
+            }
+            return "<unknwown>";
+        }
+
+        /// <summary>
+        /// control that the program is launched from the source
+        /// </summary>
+        /// <returns></returns>
+        public bool am_i_the_good_source()
+        {
+            // current drive letter
+            string driveLetter = current_drive_letter();
+
+            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
+            //Console.WriteLine("Detected Drives: ");
+            for (int i = 0; i < drives.Count(); i++)
+            {
+                if (drives[i].Name == driveLetter)
+                {
+                    if (drives[i].IsReady)
+                    {
+                        if (drives[i].VolumeLabel == "_OMASSOT")
+                        {
+                            return true;
+                        }
+                    }
+                }
+
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// makes a backup of source in destination
+        /// if purge is set to true: destination will be a mirror of source: files which are not in the source will be removed
+        /// </summary>
+        /// <param name="source"></param>
+        /// <param name="destination"></param>
+        /// <param name="purge"></param>
+        public void robocopy(string source, string destination, bool purge = false)
+        {
+            using (System.Diagnostics.Process p = new System.Diagnostics.Process())
+            {
+                string purge_opt = "";
+                if (purge) { purge_opt = "/Purge"; }
+
+                p.StartInfo.Arguments = String.Format("/C ROBOCOPY {0} {1} /E /XO /w:3 {2} /xf ctrl.barry & pause", source, destination, purge_opt);
+                p.StartInfo.FileName = "CMD.EXE";
+                p.StartInfo.CreateNoWindow = false;
+                p.StartInfo.UseShellExecute = false;
+                p.Start();
+                p.WaitForExit();
+            }
+        }
+    }
+
+}

二进制
barry/icon.ico


二进制
barry/obj/Debug/MainWindow.baml


+ 48 - 1
barry/obj/Debug/MainWindow.g.cs

@@ -1,4 +1,4 @@
-#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "633377BFD4DCBA46A232300718562D79"
+#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "C797204CC6D42A548BFE8004014E9541"
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     Ce code a été généré par un outil.
@@ -40,6 +40,38 @@ namespace barry {
     /// </summary>
     public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
         
+        
+        #line 10 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Image img_barry;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 11 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Label lbl_cpuname;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 12 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Label lbl_driveletter;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 14 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.TextBox txt_console;
+        
+        #line default
+        #line hidden
+        
         private bool _contentLoaded;
         
         /// <summary>
@@ -68,6 +100,21 @@ namespace barry {
         [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
         [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
         void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
+            switch (connectionId)
+            {
+            case 1:
+            this.img_barry = ((System.Windows.Controls.Image)(target));
+            return;
+            case 2:
+            this.lbl_cpuname = ((System.Windows.Controls.Label)(target));
+            return;
+            case 3:
+            this.lbl_driveletter = ((System.Windows.Controls.Label)(target));
+            return;
+            case 4:
+            this.txt_console = ((System.Windows.Controls.TextBox)(target));
+            return;
+            }
             this._contentLoaded = true;
         }
     }

+ 48 - 1
barry/obj/Debug/MainWindow.g.i.cs

@@ -1,4 +1,4 @@
-#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "633377BFD4DCBA46A232300718562D79"
+#pragma checksum "..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "C797204CC6D42A548BFE8004014E9541"
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     Ce code a été généré par un outil.
@@ -40,6 +40,38 @@ namespace barry {
     /// </summary>
     public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
         
+        
+        #line 10 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Image img_barry;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 11 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Label lbl_cpuname;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 12 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.Label lbl_driveletter;
+        
+        #line default
+        #line hidden
+        
+        
+        #line 14 "..\..\MainWindow.xaml"
+        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
+        internal System.Windows.Controls.TextBox txt_console;
+        
+        #line default
+        #line hidden
+        
         private bool _contentLoaded;
         
         /// <summary>
@@ -68,6 +100,21 @@ namespace barry {
         [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
         [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
         void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
+            switch (connectionId)
+            {
+            case 1:
+            this.img_barry = ((System.Windows.Controls.Image)(target));
+            return;
+            case 2:
+            this.lbl_cpuname = ((System.Windows.Controls.Label)(target));
+            return;
+            case 3:
+            this.lbl_driveletter = ((System.Windows.Controls.Label)(target));
+            return;
+            case 4:
+            this.txt_console = ((System.Windows.Controls.TextBox)(target));
+            return;
+            }
             this._contentLoaded = true;
         }
     }

+ 0 - 1
barry/obj/Debug/barry.csproj.FileListAbsolute.txt

@@ -1,7 +1,6 @@
 O:\dev\barry\barry\bin\Debug\barry.exe.config
 O:\dev\barry\barry\bin\Debug\barry.exe
 O:\dev\barry\barry\bin\Debug\barry.pdb
-O:\dev\barry\barry\obj\Debug\barry.csprojResolveAssemblyReference.cache
 O:\dev\barry\barry\obj\Debug\MainWindow.g.cs
 O:\dev\barry\barry\obj\Debug\App.g.cs
 O:\dev\barry\barry\obj\Debug\barry_MarkupCompile.cache

二进制
barry/obj/Debug/barry.csproj.GenerateResource.Cache


二进制
barry/obj/Debug/barry.csprojResolveAssemblyReference.cache


二进制
barry/obj/Debug/barry.exe


二进制
barry/obj/Debug/barry.g.resources


二进制
barry/obj/Debug/barry.pdb


+ 13 - 0
barry/obj/Debug/barry_Content.g.i.cs

@@ -0,0 +1,13 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Ce code a été généré par un outil.
+//     Version du runtime :4.0.30319.42000
+//
+//     Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
+//     le code est régénéré.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+[assembly: System.Windows.Resources.AssemblyAssociatedContentFileAttribute("icon.ico")]
+
+

+ 1 - 1
barry/obj/Debug/barry_MarkupCompile.cache

@@ -12,7 +12,7 @@ DEBUG;TRACE
 O:\dev\barry\barry\App.xaml
 11151548125
 
-6-710949358
+8-282000408
 131254293103
 MainWindow.xaml;
 

+ 2 - 2
barry/obj/Debug/barry_MarkupCompile.i.cache

@@ -12,9 +12,9 @@ DEBUG;TRACE
 O:\dev\barry\barry\App.xaml
 11151548125
 
-10-216713968
+12212234982
 131254293103
 MainWindow.xaml;
 
-False
+True
 

+ 4 - 0
barry/obj/Debug/barry_MarkupCompile.i.lref

@@ -0,0 +1,4 @@
+
+
+FO:\dev\barry\barry\MainWindow.xaml;;
+