Copy works

This commit is contained in:
Alexy 2017-09-02 18:18:13 +02:00
parent 37ec73cba4
commit bf905d6e47

View file

@ -162,47 +162,30 @@ namespace Cosmos.System_Plugs.System.IO
public static void Copy(string srcFile, string destFile)
{
if (File.Exists(destFile))
try
{
throw new IOException();
byte[] srcFileBytes = File.ReadAllBytes(srcFile);
File.WriteAllBytes(destFile, srcFileBytes);
}
else
catch (IOException ioEx)
{
using (var xFS = new FileStream(srcFile, FileMode.Open))
{
var xBuff = new byte[(int)xFS.Length];
var yFS = new FileStream(destFile, FileMode.Create);
yFS.Write(xBuff, 0, xBuff.Length);
}
throw new IOException("File Copy", ioEx);
}
}
public static void Copy(string srcFile, string destFile, bool overwriting)
{
if (File.Exists(destFile))
if (overwriting)
{
if (overwriting)
File.Delete(destFile);
try
{
File.Delete(destFile);
using (var xFS = new FileStream(srcFile, FileMode.Open))
{
var xBuff = new byte[(int)xFS.Length];
var yFS = new FileStream(destFile, FileMode.Create);
yFS.Write(xBuff, 0, xBuff.Length);
}
byte[] srcFileBytes = File.ReadAllBytes(srcFile);
File.WriteAllBytes(destFile, srcFileBytes);
}
else
catch (IOException ioEx)
{
throw new IOException();
}
}
else
{
using (var xFS = new FileStream(srcFile, FileMode.Open))
{
var xBuff = new byte[(int)xFS.Length];
var yFS = new FileStream(destFile, FileMode.Create);
yFS.Write(xBuff, 0, xBuff.Length);
throw new IOException("File Copy", ioEx);
}
}
}