1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Diagnostics;
using System.IO;
namespace ShadowCopy
{
class Program
{
static public bool is_a_copy;
static public string s_usb_path;
static public string s_local_path;
static void Main(string[] args)
{
is_a_copy = false;
if ( args.Count() < 2 )
{
Console.WriteLine("Usage : Shadowcopy.exe [OPTIONS] chemin vers le disque local ... chemin vers la clef usb ... ");
Environment.Exit(0);
}
s_local_path= args[0];
s_usb_path = args[1];
if (args.Count() == 3)
{
bool result = args[2].Equals("--HIDE", StringComparison.Ordinal);
if (result)
is_a_copy = true;
}
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(StartTimerEvent);
myTimer.Interval = 1000;
myTimer.Start();
while ( Console.Read() != 'q' )
{
; // do nothing...
}
}
public static bool StartSc(bool is_a_copy, string local_path, string usb_path)
{
if (!is_a_copy)
{
Process ShadowProcess = new Process();
ShadowProcess.StartInfo.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
ShadowProcess.StartInfo.Arguments = local_path + " " + usb_path + " --HIDE ";
ShadowProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if(ShadowProcess.Start() == true)
Environment.Exit(0);
else
Console.Write("Error");
}
else
{
try
{
Directory.CreateDirectory(usb_path);
}
catch
{
;//
}
try
{
foreach(var file in Directory.GetFiles(local_path))
File.Copy(file, Path.Combine(usb_path, Path.GetFileName(file)));
}
catch
{
;//
}
try
{
foreach (var directory in Directory.GetDirectories(local_path))
StartSc(true, directory, Path.Combine(usb_path, Path.GetFileName(directory)));
}
catch
{
;//
}
}
return true;
}
public static void StartTimerEvent(object source, ElapsedEventArgs e)
{
StartSc(is_a_copy, s_local_path, s_usb_path);
}
}
} |
Partager