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
|
public class Copie
{
public static void copie_fichier(string f_a_copier, string f_destination, ProgressBar progressbar)
{
try
{
System.Diagnostics.Stopwatch stop = System.Diagnostics.Stopwatch.StartNew();
using (FileStream inputStream = File.OpenRead(f_a_copier))
{
using (FileStream outputStream = File.OpenWrite(f_destination))
{
byte[] bufferWork = new byte[main.BufferSize];
byte[] bufferLoad = new byte[main.BufferSize];
byte[] bufferTmp;
IAsyncResult asyncResult;
int nbRead = inputStream.Read(bufferWork, 0, bufferWork.Length);
while (nbRead > 0)
{
asyncResult = inputStream.BeginRead(bufferLoad, 0, bufferLoad.Length, null, null);
outputStream.Write(bufferWork, 0, nbRead);
nbRead = inputStream.EndRead(asyncResult);
// j'incremente la progressbar
progressbar.PerformStep();
bufferTmp = bufferWork;
bufferWork = bufferLoad;
bufferLoad = bufferTmp;
}
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString(), "erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
public static void copie_DVD(string dvd, string rep_dest, ProgressBar progressbar)
{
try
{
DirectoryInfo rep = new DirectoryInfo(dvd);
if (rep.Exists)
{
string vrai_rep_dest;
if (rep.Root.Name != rep.Name)
{
vrai_rep_dest = Path.Combine(rep_dest, rep.Name);
if (!Directory.Exists(vrai_rep_dest))
{ Directory.CreateDirectory(vrai_rep_dest); }
}
else
{ vrai_rep_dest = rep_dest; }
foreach (string d in Directory.GetDirectories(dvd))
Copie.copie_DVD(d, vrai_rep_dest,progressbar);
foreach (string fichier in Directory.GetFiles(dvd))
{
string fichier_dest = Path.Combine(vrai_rep_dest, Path.GetFileName(fichier));
copie_fichier(fichier, fichier_dest,progressbar);
}
}
}
catch (Exception)
{
MessageBox.Show(erreur.affiche_erreur(03), "Erreur ... ", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
} |
Partager