|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- /* 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
- }
- }
|