/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;
namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region Copy
// .NET: Directory class does not contain the Copy() method.
// Mimic .NET File.Copy() methods.
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath)
{
return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, .
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, bool overwrite)
{
return CopyMoveCore(null, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, bool overwrite, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}
#region Transactional
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, .
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, bool overwrite)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
///
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, bool overwrite, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}
#endregion // Transactional
#endregion // Copy
#region Copy (CopyOptions)
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, pathFormat);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// A callback function that is called each time another portion of the directory has been copied. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// A callback function that is called each time another portion of the directory has been copied. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
}
#region Transactional
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, null, null, null, pathFormat);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// A callback function that is called each time another portion of the directory has been copied. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
}
/// [AlphaFS] Copies a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// Option is recommended for very large file transfers.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Copy action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// A callback function that is called each time another portion of the directory has been copied. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
}
#endregion // Transactional
#endregion // Copy (CopyOptions)
#region Move
#region .NET
/// Moves a file or a directory and its contents to a new location.
///
/// This method does not work across disk volumes.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
}
#endregion // .NET
/// [AlphaFS] Moves a file or a directory and its contents to a new location.
///
/// This method does not work across disk volumes.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, pathFormat);
}
#region Transactional
/// [AlphaFS] Moves a file or a directory and its contents to a new location.
///
/// This method does not work across disk volumes.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location.
///
/// This method does not work across disk volumes.
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, pathFormat);
}
#endregion // Transactional
#endregion // Move
#region Move (MoveOptions)
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, pathFormat);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// A callback function that is called each time another portion of the directory has been moved. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// A callback function that is called each time another portion of the directory has been moved. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
}
#region Transactional
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, null, null, null, PathFormat.RelativePath);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, null, null, null, pathFormat);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// A callback function that is called each time another portion of the directory has been moved. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
}
/// [AlphaFS] Moves a file or a directory and its contents to a new location, can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// A class with the status of the Move action.
///
/// This method does not work across disk volumes unless contains .
/// Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.
/// If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.
///
///
/// A class with details of the Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be moved. This parameter can be .
/// A callback function that is called each time another portion of the directory has been moved. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
/// Indicates the format of the path parameter(s).
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
}
#endregion // Transactional
#endregion // Move (MoveOptions)
#region Internal Methods
/// Copy/move a Non-/Transacted file or directory including its children to a new location,
/// or can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
///
/// Option is recommended for very large file transfers.
/// You cannot use the Move method to overwrite an existing file, unless contains .
/// Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOException.
///
///
/// A class with the status of the Copy or Move action.
///
///
///
///
///
///
/// The transaction.
/// The source directory path.
/// The destination directory path.
/// that specify how the directory is to be copied. This parameter can be .
/// that specify how the directory is to be moved. This parameter can be .
/// A callback function that is called each time another portion of the file has been copied/moved. This parameter can be .
/// The argument to be passed to the callback function. This parameter can be .
///
/// Indicates the format of the path parameter(s).
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SecurityCritical]
internal static CopyMoveResult CopyMoveCore(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions? copyOptions, MoveOptions? moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, CopyMoveResult copyMoveResult, PathFormat pathFormat)
{
#region Setup
var sourcePathLp = sourcePath;
var destinationPathLp = destinationPath;
var skipPathChecks = pathFormat == PathFormat.LongFullPath;
if (!skipPathChecks)
{
Path.CheckSupportedPathFormat(sourcePathLp, true, true);
Path.CheckSupportedPathFormat(destinationPathLp, true, true);
// MSDN: .NET 4+ Trailing spaces are removed from the end of the path parameters before moving the directory.
// TrimEnd() is also applied for AlphaFS implementation of method Directory.Copy(), .NET does not have this method.
const GetFullPathOptions fullPathOptions = GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator;
sourcePathLp = Path.GetExtendedLengthPathCore(transaction, sourcePath, pathFormat, fullPathOptions);
destinationPathLp = Path.GetExtendedLengthPathCore(transaction, destinationPath, pathFormat, fullPathOptions);
// MSDN: .NET3.5+: IOException: The sourceDirName and destDirName parameters refer to the same file or directory.
if (sourcePathLp.Equals(destinationPathLp, StringComparison.OrdinalIgnoreCase))
NativeError.ThrowException(Win32Errors.ERROR_SAME_DRIVE, destinationPathLp);
}
var emulateMove = false;
// Determine Copy or Move action.
var isCopy = File.DetermineIsCopy(copyOptions, moveOptions);
var isMove = !isCopy;
var cmr = copyMoveResult ?? new CopyMoveResult(sourcePathLp, destinationPathLp, false, (int) Win32Errors.ERROR_SUCCESS);
// Execute once only.
if (!skipPathChecks && isMove)
{
// Compare the root part of both paths.
var equalRootPaths = Path.GetPathRoot(sourcePathLp, false).Equals(Path.GetPathRoot(destinationPathLp, false), StringComparison.OrdinalIgnoreCase);
// Method Volume.IsSameVolume() returns true when both paths refer to the same volume, even if one of the paths is a UNC path.
// For example, src = C:\TempSrc and dst = \\localhost\C$\TempDst
var isSameVolume = equalRootPaths || Volume.IsSameVolume(sourcePathLp, destinationPathLp);
isMove = isSameVolume && equalRootPaths;
if (!isMove)
{
// A Move() can be emulated by using Copy() and Delete(), but only if the CopyAllowed flag is set.
isMove = ((MoveOptions) moveOptions & MoveOptions.CopyAllowed) != 0;
// MSDN: .NET3.5+: IOException: An attempt was made to move a directory to a different volume.
if (!isMove)
NativeError.ThrowException(Win32Errors.ERROR_NOT_SAME_DEVICE, sourcePathLp, destinationPathLp);
}
// The NativeMethod.MoveFileXxx() methods fail when:
// - A directory is being moved;
// - One of the paths is a UNC path, even though both paths refer to the same volume.
// For example, src = C:\TempSrc and dst = \\localhost\C$\TempDst
if (isMove)
{
var srcIsUncPath = Path.IsUncPathCore(sourcePathLp, false, false);
var dstIsUncPath = Path.IsUncPathCore(destinationPathLp, false, false);
isMove = srcIsUncPath && dstIsUncPath;
if (!isMove)
isMove = !srcIsUncPath && !dstIsUncPath;
}
isMove = isMove && isSameVolume && equalRootPaths;
// Emulate Move().
if (!isMove)
{
emulateMove = true;
moveOptions = null;
isCopy = true;
copyOptions = CopyOptions.FailIfExists;
}
}
#endregion // Setup
#region Copy
if (isCopy)
{
CreateDirectoryCore(transaction, destinationPathLp, null, null, false, PathFormat.LongFullPath);
foreach (var fsei in EnumerateFileSystemEntryInfosCore(transaction, sourcePathLp, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath))
{
var newDestinationPathLp = Path.CombineCore(false, destinationPathLp, fsei.FileName);
cmr = fsei.IsDirectory
? CopyMoveCore(transaction, fsei.LongFullPath, newDestinationPathLp, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath)
: File.CopyMoveCore(false, transaction, fsei.LongFullPath, newDestinationPathLp, false, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath);
if (cmr.ErrorCode == Win32Errors.ERROR_SUCCESS)
{
if (fsei.IsDirectory)
cmr.TotalFolders++;
else
{
cmr.TotalFiles++;
cmr.TotalBytes += fsei.FileSize;
}
// Remove the folder or file when copying was successful.
if (emulateMove)
{
if (fsei.IsDirectory)
DeleteDirectoryCore(fsei, transaction, null, true, true, false, true, PathFormat.LongFullPath);
else
File.DeleteFileCore(transaction, fsei.LongFullPath, true, PathFormat.LongFullPath);
}
}
if (cmr.IsCanceled)
return cmr;
}
// Remove source folder.
if (emulateMove && cmr.ErrorCode == Win32Errors.ERROR_SUCCESS)
DeleteDirectoryCore(null, transaction, sourcePathLp, true, true, false, true, PathFormat.LongFullPath);
}
#endregion // Copy
#region Move
else
{
// MoveOptions.ReplaceExisting: This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
if (((MoveOptions) moveOptions & MoveOptions.ReplaceExisting) != 0)
DeleteDirectoryCore(null, transaction, destinationPathLp, true, true, false, true, PathFormat.LongFullPath);
// Moves a file or directory, including its children.
// Copies an existing directory, including its children to a new directory.
cmr = File.CopyMoveCore(true, transaction, sourcePathLp, destinationPathLp, false, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath);
}
#endregion // Move
return cmr;
}
#endregion // Internal Methods
}
}