Skip to content

Commit

Permalink
Copy works
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexy committed Sep 2, 2017
1 parent 37ec73c commit bf905d6
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions source/Cosmos.System2_Plugs/System/IO/FileImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,47 +162,30 @@ public static void WriteAllBytes(string aFile, byte[] aBytes)

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
{
throw new IOException();
}
}
else
{
using (var xFS = new FileStream(srcFile, FileMode.Open))
catch (IOException ioEx)
{
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);
}
}
}
Expand Down

0 comments on commit bf905d6

Please sign in to comment.