public override FileSystemExitCode PutFile(string localName, ref string remoteName, CopyFlags copyFlags) { bool overWrite = (CopyFlags.Overwrite & copyFlags) != 0; string rmtName = remoteName.Substring(1); if (File.Exists(rmtName) & !overWrite) { return(FileSystemExitCode.FileExists); } try { if ((CopyFlags.Move & copyFlags) != 0) { MoveFileOptions options = (overWrite) ? MoveFileOptions.ReplaceExisting : MoveFileOptions.None; FileRoutines.MoveFile(new FileInfo(localName), new FileInfo(rmtName), options, OnCopyFile); } else { CopyFileOptions options = (overWrite) ? CopyFileOptions.None : CopyFileOptions.FailIfDestinationExists; FileRoutines.CopyFile(new FileInfo(localName), new FileInfo(rmtName), options, OnCopyFile); } TraceProc(TraceLevel.Warning, "Local file '" + localName + "' transferred!"); return(FileSystemExitCode.OK); } catch (Exception ex) { MessageBox.Show( "File operation error:" + Environment.NewLine + ex.Message, "LFS Plugin (PutFile)", MessageBoxButtons.OK, MessageBoxIcon.Error); return(FileSystemExitCode.WriteError); } }
public static void MoveFile(FileInfo source, FileInfo destination, MoveFileOptions options, CopyFileCallback callback) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } if ((options & ~MoveFileOptions.All) != 0) { throw new ArgumentOutOfRangeException("options"); } new FileIOPermission(FileIOPermissionAccess.Write, source.FullName).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, destination.FullName).Demand(); object state = null; CopyProgressRoutine cpr = (callback == null) ? null : new CopyProgressRoutine(new CopyProgressData( source, destination, callback, state).CallbackHandler); if (!NativeMethods.MoveFileWithProgress(source.FullName, destination.FullName, cpr, IntPtr.Zero, (int)options)) { throw new IOException(new Win32Exception().Message); } }
public MoveFileEngine (List <FileInfoEx> source, string destination, string mask, MoveEngineOptions options, CopyFileProgressDialog dialog) { initial_mask = mask; initial_source = source; innitial_destination = destination; this.options = options; progress_dialog = dialog; internal_thread = new Thread(move_proc); options_api = MoveFileOptions.CopyAllowed | MoveFileOptions.WriteThrough; if ((options & MoveEngineOptions.ReplaceExistingFiles) == MoveEngineOptions.ReplaceExistingFiles) { options_api = options_api | MoveFileOptions.ReplaceExisting; } if (progress_dialog != null) { progress_dialog.FormClosing += new FormClosingEventHandler(progress_dialog_FormClosing); } update_progress_delegate_holder = new MethodInvokerUpdateProgress(update_progress_unsafe); move_progress_delegate_holder = new CopyProgressRoutine(move_progress_proc); }
public override FileSystemExitCode GetFile(string remoteName, ref string localName, CopyFlags copyFlags, RemoteInfo remoteInfo) { bool overWrite = (CopyFlags.Overwrite & copyFlags) != 0; remoteName = remoteName.Substring(1); if (File.Exists(localName) & !overWrite) { return(FileSystemExitCode.FileExists); } try { if ((CopyFlags.Move & copyFlags) != 0) { MoveFileOptions options = (overWrite) ? MoveFileOptions.ReplaceExisting : MoveFileOptions.None; FileRoutines.MoveFile(new FileInfo(remoteName), new FileInfo(localName), options, OnCopyFile); } else { CopyFileOptions options = (overWrite) ? CopyFileOptions.None : CopyFileOptions.FailIfDestinationExists; FileRoutines.CopyFile(new FileInfo(remoteName), new FileInfo(localName), options, OnCopyFile); } return(FileSystemExitCode.OK); } catch (Exception ex) { MessageBox.Show( "File operation error:" + Environment.NewLine + ex.Message, "LFS Plugin (GetFile)", MessageBoxButtons.OK, MessageBoxIcon.Error); return(FileSystemExitCode.ReadError); } }
public static void MoveFile(FileInfo source, FileInfo destination, MoveFileOptions options, CopyFileCallback callback) { if (source == null) throw new ArgumentNullException("source"); if (destination == null) throw new ArgumentNullException("destination"); new FileIOPermission(FileIOPermissionAccess.Read, source.FullName).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, destination.FullName).Demand(); CopyProgressRoutine cpr = (callback == null ? null : new CopyProgressRoutine(new CopyProgressData(source, destination, callback, null).CallbackHandler)); if (!MoveFileWithProgress(source.FullName, destination.FullName, cpr, IntPtr.Zero, options)) { throw new IOException(new Win32Exception().Message); } }
public override FileSystemExitCode RenMovFile(string oldName, string newName, bool move, bool overwrite, RemoteInfo remoteInfo) { oldName = oldName.Substring(1); if (!File.Exists(oldName)) { return(FileSystemExitCode.FileNotFound); } newName = newName.Substring(1); if (File.Exists(newName) & !overwrite) { return(FileSystemExitCode.FileExists); } try { if (move) { MoveFileOptions options = (overwrite) ? MoveFileOptions.ReplaceExisting : MoveFileOptions.None; FileRoutines.MoveFile(new FileInfo(oldName), new FileInfo(newName), options, OnCopyFile); } else { CopyFileOptions options = (overwrite) ? CopyFileOptions.None : CopyFileOptions.FailIfDestinationExists; FileRoutines.CopyFile(new FileInfo(oldName), new FileInfo(newName), options, OnCopyFile); } return(FileSystemExitCode.OK); } catch (IOException ex) { if (ex.Message.Equals(ErrorRequestAbortedMsg)) { return(FileSystemExitCode.UserAbort); } if (ex.Message.Equals(ErrorFileNotFoundMsg)) { return(FileSystemExitCode.FileNotFound); } MessageBox.Show( "File operation error:" + Environment.NewLine + ex.Message, "LFS Plugin (RenMovFile)", MessageBoxButtons.OK, MessageBoxIcon.Error); return(FileSystemExitCode.ReadError); } }
public static void MoveFile(FileInfo source, FileInfo destination, MoveFileOptions options, CopyFileCallback callback) { if (source == null) { throw new ArgumentNullException("source"); } if (destination == null) { throw new ArgumentNullException("destination"); } new FileIOPermission(FileIOPermissionAccess.Read, source.FullName).Demand(); new FileIOPermission(FileIOPermissionAccess.Write, destination.FullName).Demand(); CopyProgressRoutine cpr = (callback == null ? null : new CopyProgressRoutine(new CopyProgressData(source, destination, callback, null).CallbackHandler)); if (!MoveFileWithProgress(source.FullName, destination.FullName, cpr, IntPtr.Zero, options)) { throw new IOException(new Win32Exception().Message); } }
static internal extern bool MoveFileTransactedW(string lpExistingFileName, string lpNewFileName, NativeCopyProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.U4)] MoveFileOptions dwCopyFlags, SafeHandle hTransaction);
static internal extern bool MoveFileWithProgressW([In] string existingFileName, [In] string newFileName, NativeCopyProgressRoutine lpProgressRoutine, object lpData, [MarshalAs(UnmanagedType.U4)] MoveFileOptions dwFlags);
private static extern bool MoveFileWithProgress(string lpExistingFileName, string lpNewFileName, CopyProgressRoutine lpProgressRoutine, IntPtr lpData, MoveFileOptions dwCopyFlags);