internal static String InternalCopy(String sourceFileName, String destFileName, bool overwrite, bool checkHost) { String fullSourceFileName = Path.GetFullPathInternal(sourceFileName); String fullDestFileName = Path.GetFullPathInternal(destFileName); MonoIOError error; if (!MonoIO.CopyFile(fullSourceFileName, fullDestFileName, overwrite, out error)) { string p = Locale.GetText("{0}\" or \"{1}", sourceFileName, destFileName); throw MonoIO.GetException(p, error); } return(fullDestFileName); }
public static void Copy(string sourceFileName, string destFileName, bool overwrite) { MonoIOError error; if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName"); } if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (sourceFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "sourceFileName"); } if (sourceFileName.Trim().Length == 0 || sourceFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } if (destFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destFileName"); } if (destFileName.Trim().Length == 0 || destFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } SecurityManager.EnsureElevatedPermissions(); // this is a no-op outside moonlight if (!MonoIO.Exists(sourceFileName, out error)) { throw new FileNotFoundException(Locale.GetText("{0} does not exist", sourceFileName), sourceFileName); } if ((GetAttributes(sourceFileName) & FileAttributes.Directory) == FileAttributes.Directory) { throw new ArgumentException(Locale.GetText("{0} is a directory", sourceFileName)); } if (MonoIO.Exists(destFileName, out error)) { if ((GetAttributes(destFileName) & FileAttributes.Directory) == FileAttributes.Directory) { throw new ArgumentException(Locale.GetText("{0} is a directory", destFileName)); } if (!overwrite) { throw new IOException(Locale.GetText("{0} already exists", destFileName)); } } string DirName = Path.GetDirectoryName(destFileName); if (DirName != String.Empty && !Directory.Exists(DirName)) { throw new DirectoryNotFoundException(Locale.GetText("Destination directory not found: {0}", DirName)); } if (!MonoIO.CopyFile(sourceFileName, destFileName, overwrite, out error)) { string p = Locale.GetText("{0}\" or \"{1}", sourceFileName, destFileName); throw MonoIO.GetException(p, error); } }