|
- /* 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.
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- [SecurityCritical]
- public static CopyMoveResult Copy(string sourcePath, string destinationPath)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static CopyMoveResult Copy(string sourcePath, string destinationPath, PathFormat pathFormat)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
- }
-
-
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- [SecurityCritical]
- public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
- {
- return CopyMoveCore(transaction, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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);
- }
-
-
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
- /// <remarks>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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)
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, pathFormat);
- }
-
-
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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);
- }
-
-
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>Moves a file or a directory and its contents to a new location.
- /// <remarks>
- /// <para>This method does not work across disk volumes.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- [SecurityCritical]
- public static CopyMoveResult Move(string sourcePath, string destinationPath)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
- }
-
- #endregion // .NET
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
- /// <remarks>
- /// <para>This method does not work across disk volumes.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
- /// <remarks>
- /// <para>This method does not work across disk volumes.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- [SecurityCritical]
- public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
- {
- return CopyMoveCore(transaction, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
- /// <remarks>
- /// <para>This method does not work across disk volumes.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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)
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
- {
- return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, pathFormat);
- }
-
-
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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);
- }
-
-
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- [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);
- }
-
- /// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
- /// <remarks>
- /// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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
-
- /// <summary>Copy/move a Non-/Transacted file or directory including its children to a new location,
- /// <see cref="CopyOptions"/> or <see cref="MoveOptions"/> can be specified,
- /// and the possibility of notifying the application of its progress through a callback function.
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>You cannot use the Move method to overwrite an existing file, unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.ReplaceExisting"/>.</para>
- /// <para>Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOException.</para>
- /// </remarks>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Copy or Move action.</returns>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourcePath">The source directory path.</param>
- /// <param name="destinationPath">The destination directory path.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the file has been copied/moved. This parameter can be <see langword="null"/>.</param>
- /// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
- /// <param name="copyMoveResult"></param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [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<FileSystemEntryInfo>(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
- }
- }
|