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
|
public virtual void CopyStreams2(string filesrc, string filedest, CopyProgressHandler handler)
{
int i;
FileStream fin, fout;
long done = 0, total = 0;
try
{
// open input file
try
{
fin = new FileStream(filesrc, FileMode.Open);
total = fin.Length;
}
catch (FileNotFoundException exc)
{
Console.WriteLine(exc.Message + "\nInput File Not Found");
return;
}
// open output file
try
{
fout = new FileStream(filedest, FileMode.Create);
}
catch (IOException exc)
{
Console.WriteLine(exc.Message + "\nError Opening Output File");
return;
}
}
catch (IndexOutOfRangeException exc)
{
Console.WriteLine(exc.Message + "\nUsage: CopyFile From To");
return;
}
// Copy File
try
{
do
{
i = fin.ReadByte();
if (i != -1)
{
fout.WriteByte((byte)i);
if (handler != null)
{
done = fin.Position;
if ((done % 8) == 0) // taille d'un octet on incrémente la progression
handler(total, done, total - done, (double)done / (double)total);
}
}
} while (i != -1);
}
catch (IOException exc)
{
Console.WriteLine(exc.Message + "File Error");
}
fin.Close();
fout.Close();
} |
Partager