2010-05-27 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 27 May 2010 17:19:48 +0000 (17:19 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 27 May 2010 17:19:48 +0000 (17:19 -0000)
* IsolatedStorageFile.cs: Implement CopyFile.

svn path=/trunk/mcs/; revision=158049

mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

index 68b6bc673e7941215fffa3bc3c1084c0fad8a82a..9e4c606d38dfe4e327f14f04ddd77152c7c76110 100644 (file)
@@ -1,3 +1,7 @@
+2010-05-27  Carlos Alberto Cortez <calberto.cortez@gmail.com> 
+
+       * IsolatedStorageFile.cs: Implement CopyFile.
+
 2010-05-27  Carlos Alberto Cortez <calberto.cortez@gmail.com>
 
        * IsolatedStorageFile.cs: Implement GetCreationTime, GetLastAccessTime
index eb16f4f82adc11e0cfdd47fbc8ee86b5a8b24f3f..ff590e2932b7c26c297ba0d0c2bf9d1536b22c33 100644 (file)
@@ -507,6 +507,44 @@ namespace System.IO.IsolatedStorage {
                }
 
 #if NET_4_0
+               [ComVisible (false)]
+               public void CopyFile (string sourceFileName, string destinationFileName)
+               {
+                       CopyFile (sourceFileName, destinationFileName, false);
+               }
+
+               [ComVisible (false)]
+               public void CopyFile (string sourceFileName, string destinationFileName, bool overwrite)
+               {
+                       if (sourceFileName == null)
+                               throw new ArgumentNullException ("sourceFileName");
+                       if (destinationFileName == null)
+                               throw new ArgumentNullException ("destinationFileName");
+                       if (sourceFileName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty file name is not valid.", "sourceFileName");
+                       if (destinationFileName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty file name is not valid.", "destinationFileName");
+
+                       CheckOpen ();
+
+                       string source_full_path = Path.Combine (directory.FullName, sourceFileName);
+                       string dest_full_path = Path.Combine (directory.FullName, destinationFileName);
+
+                       // These excs can be thrown from File.Copy, but we can try to detect them from here.
+                       if (!Directory.Exists (Path.GetDirectoryName (source_full_path)))
+                               throw new DirectoryNotFoundException ("Could not find a part of path '" + sourceFileName + "'.");
+                       if (!File.Exists (source_full_path))
+                               throw new FileNotFoundException ("Could not find a part of path '" + sourceFileName + "'.");
+                       if (File.Exists (dest_full_path) && !overwrite)
+                               throw new IsolatedStorageException ("Operation not allowed.");
+
+                       try {
+                               File.Copy (source_full_path, dest_full_path, overwrite);
+                       } catch (IOException) {
+                               throw new IsolatedStorageException ("Operation not allowed.");
+                       }
+               }
+
                [ComVisible (false)]
                public IsolatedStorageFileStream CreateFile (string path)
                {