|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324 |
- /* 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.Globalization;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Security;
-
- namespace Alphaleonis.Win32.Filesystem
- {
- public static partial class File
- {
- #region Copy
-
- #region .NET
-
- /// <summary>Copies an existing file to a new file. Overwriting a file of the same name is not allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory or an existing file.</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>Copies an existing file to a new file. Overwriting a file of the same name is allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination file should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName, bool overwrite)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- #endregion // .NET
-
-
- #region AlphaFS
-
- #region Non-Transactional
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is not allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination file 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 void Copy(string sourceFileName, string destinationFileName, bool overwrite, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
- }
-
- #endregion // Non-Transactional
-
-
- #region Transactional
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is not allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory or an existing file.</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is not allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination file should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, bool overwrite)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed.</summary>
- /// <remarks>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy. </param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="overwrite"><see langword="true"/> if the destination file 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 void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, bool overwrite, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
- }
-
- #endregion // Transactional
-
- #endregion // AlphaFS
-
- #endregion // Copy
-
-
- #region Copy (CopyOptions)
-
- #region Non-Transactional
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, copyOptions, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, copyOptions, null, null, null, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, preserveDates, copyOptions, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, preserveDates, copyOptions, null, null, null, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 file 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 void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 file 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 void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the file 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 void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, preserveDates, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the file 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 void Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, preserveDates, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
- }
-
- #endregion // Non-Transactional
-
-
- #region Transactional
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, copyOptions, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, copyOptions, null, null, null, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, preserveDates, copyOptions, null, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified.</summary>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, preserveDates, copyOptions, null, null, null, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 file 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 void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file 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 file 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 void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
- }
-
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the file 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 void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, preserveDates, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Copies an existing file to a new file. Overwriting a file of the same name is allowed. <see cref="CopyOptions"/> can be specified,
- /// <para>and the possibility of notifying the application of its progress through a callback function.</para>
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
- /// <remarks>
- /// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
- /// <para>The attributes of the original file are retained in the copied file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The file to copy.</param>
- /// <param name="destinationFileName">The name of the destination file. This cannot be a directory.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise.</param>
- /// <param name="progressHandler">A callback function that is called each time another portion of the file 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>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- [SecurityCritical]
- public static void CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, preserveDates, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
- }
-
- #endregion // Transactional
-
- #endregion // Copy (CopyOptions)
-
-
- #region Move
-
- #region .NET
-
- /// <summary>Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- [SecurityCritical]
- public static void Move(string sourceFileName, string destinationFileName)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, MoveOptions.CopyAllowed, null, null, null, PathFormat.RelativePath);
- }
-
- #endregion // .NET
-
- #region AlphaFS
-
- #region Non-Transactional
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void Move(string sourceFileName, string destinationFileName, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, MoveOptions.CopyAllowed, null, null, null, pathFormat);
- }
-
- #endregion // Non-Transactional
-
- #region Transactional
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- [SecurityCritical]
- public static void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, MoveOptions.CopyAllowed, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
- [SecurityCritical]
- public static void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, MoveOptions.CopyAllowed, null, null, null, pathFormat);
- }
-
- #endregion // Transactional
-
- #endregion // AlphaFS
-
- #endregion // Move
-
-
- #region Move (MoveOptions)
-
- #region Non-Transactional
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file is to be moved. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static void Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, moveOptions, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 void Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, moveOptions, null, null, null, pathFormat);
- }
-
-
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 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 void Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 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 void Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, null, sourceFileName, destinationFileName, false, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
- }
-
- #endregion // Non-Transactional
-
- #region Transactional
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file is to be moved. This parameter can be <see langword="null"/>.</param>
- [SecurityCritical]
- public static void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, moveOptions, null, null, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, moveOptions, null, null, null, pathFormat);
- }
-
-
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 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 void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
- }
-
- /// <summary>[AlphaFS] Moves a specified file to a new location, providing the option to specify a new file name.</summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
- /// <remarks>
- /// <para>This method works across disk volumes, and it does not throw an exception if the source and destination are the same.</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 <see cref="IOException"/>.</para>
- /// <para>You cannot use the Move method to overwrite an existing file.</para>
- /// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
- /// <para>If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
- /// </remarks>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The name of the file to move.</param>
- /// <param name="destinationFileName">The new path for the file.</param>
- /// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file 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 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 void MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- CopyMoveCore(false, transaction, sourceFileName, destinationFileName, false, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
- }
-
- #endregion // Transactional
-
- #endregion // Move (MoveOptions)
-
-
- #region Internal Methods
-
- /// <summary>Determine the Copy or Move action.</summary>
- internal static bool DetermineIsCopy(CopyOptions? copyOptions, MoveOptions? moveOptions)
- {
- // Determine Copy or Move action.
- var isCopy = copyOptions != null;
- var isMove = !isCopy && moveOptions != null;
-
- if ((!isCopy && !isMove) || (isCopy && isMove))
- throw new NotSupportedException(Resources.Cannot_Determine_Copy_Or_Move);
-
- return isCopy;
- }
-
-
- /// <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.
- /// </summary>
- /// <returns>A <see cref="CopyMoveResult"/> class with the status of the Copy or Move action.</returns>
- /// <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>This Move method works across disk volumes, and it does not throw an exception if the
- /// source and destination are the same. </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>
- /// <exception cref="ArgumentException"/>
- /// <exception cref="ArgumentNullException"/>
- /// <exception cref="DirectoryNotFoundException"/>
- /// <exception cref="FileNotFoundException"/>
- /// <exception cref="IOException"/>
- /// <exception cref="NotSupportedException"/>
- /// <exception cref="UnauthorizedAccessException"/>
- /// <param name="isFolder">Specifies that <paramref name="sourceFileName"/> and <paramref name="destinationFileName"/> are a file or directory.</param>
- /// <param name="transaction">The transaction.</param>
- /// <param name="sourceFileName">The source directory path.</param>
- /// <param name="destinationFileName">The destination directory path.</param>
- /// <param name="preserveDates"><see langword="true"/> if original Timestamps must be preserved, <see langword="false"/> otherwise. This parameter is ignored for move operations.</param>
- /// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
- /// <param name="moveOptions">Flags that specify how the file or 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(bool isFolder, KernelTransaction transaction, string sourceFileName, string destinationFileName, bool preserveDates, CopyOptions? copyOptions, MoveOptions? moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, CopyMoveResult copyMoveResult, PathFormat pathFormat)
- {
- #region Setup
-
- var sourceFileNameLp = sourceFileName;
- var destFileNameLp = destinationFileName;
-
- if (pathFormat != PathFormat.LongFullPath)
- {
- Path.CheckSupportedPathFormat(sourceFileName, true, true);
- Path.CheckSupportedPathFormat(destinationFileName, true, true);
-
- sourceFileNameLp = Path.GetExtendedLengthPathCore(transaction, sourceFileName, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);
- destFileNameLp = Path.GetExtendedLengthPathCore(transaction, destinationFileName, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);
- }
-
-
- // Determine Copy or Move action.
- var isCopy = DetermineIsCopy(copyOptions, moveOptions);
- var isMove = !isCopy;
-
- var cmr = copyMoveResult ?? new CopyMoveResult(sourceFileName, destinationFileName, false, (int) Win32Errors.ERROR_SUCCESS);
-
-
- // MSDN: If this flag is set to TRUE during the copy/move operation, the operation is canceled.
- // Otherwise, the copy/move operation will continue to completion.
- bool cancel;
-
- var raiseException = progressHandler == null;
-
- // Setup callback function for progress notifications.
- var routine = !raiseException
- ? (totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile, lpData) =>
- progressHandler(totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, userProgressData)
- : (NativeMethods.NativeCopyMoveProgressRoutine) null;
-
- #endregion // Setup
-
-
- startCopyMove:
-
- #region Win32 Copy/Move
-
- var success = transaction == null || !NativeMethods.IsAtLeastWindowsVista
-
- ? isMove
- // MoveFileWithProgress() / MoveFileTransacted()
- // In the ANSI version of this function, the name is limited to MAX_PATH characters.
- // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
- // 2013-04-15: MSDN confirms LongPath usage.
-
- // CopyFileEx() / CopyFileTransacted()
- // In the ANSI version of this function, the name is limited to MAX_PATH characters.
- // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
- // 2013-04-15: MSDN confirms LongPath usage.
-
-
- // Note: The NativeMethod.MoveFileXxx() methods fail if 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
-
-
- ? NativeMethods.MoveFileWithProgress(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, (MoveOptions) moveOptions)
- : NativeMethods.CopyFileEx(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, out cancel, (CopyOptions) copyOptions)
-
- : isMove
- ? NativeMethods.MoveFileTransacted(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, (MoveOptions) moveOptions, transaction.SafeHandle)
- : NativeMethods.CopyFileTransacted(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, out cancel, (CopyOptions) copyOptions, transaction.SafeHandle);
-
-
- var lastError = (uint) Marshal.GetLastWin32Error();
- if (!success)
- {
- cmr.ErrorCode = (int) lastError;
-
- if (lastError == Win32Errors.ERROR_REQUEST_ABORTED)
- {
- // MSDN:
- //
- // If lpProgressRoutine returns PROGRESS_CANCEL due to the user canceling the operation,
- // CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED.
- // In this case, the partially copied destination file is deleted.
- //
- // If lpProgressRoutine returns PROGRESS_STOP due to the user stopping the operation,
- // CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED.
- // In this case, the partially copied destination file is left intact.
-
- cmr.IsCanceled = true;
- }
-
- else if (raiseException)
- {
- raiseException:
-
- #region Win32Errors
-
- switch (lastError)
- {
- case Win32Errors.ERROR_FILE_NOT_FOUND:
- if (isFolder)
- {
- lastError = Win32Errors.ERROR_PATH_NOT_FOUND;
- goto raiseException;
- }
-
- // File.Copy()
- // File.Move()
- // MSDN: .NET 3.5+: FileNotFoundException: sourceFileName was not found.
- NativeError.ThrowException(lastError, sourceFileNameLp);
- break;
-
- case Win32Errors.ERROR_PATH_NOT_FOUND:
- // File.Copy()
- // File.Move()
- // Directory.Move()
- // MSDN: .NET 3.5+: DirectoryNotFoundException: The path specified in sourceFileName or destinationFileName is invalid (for example, it is on an unmapped drive).
- NativeError.ThrowException(lastError, sourceFileNameLp);
- break;
-
- case Win32Errors.ERROR_FILE_EXISTS:
- // File.Copy()
- // Directory.Copy()
- NativeError.ThrowException(lastError, destFileNameLp);
- break;
-
- default:
- var destExists = ExistsCore(isFolder, transaction, destFileNameLp, PathFormat.LongFullPath);
-
- // For a number of error codes (sharing violation, path not found, etc)
- // we don't know if the problem was with the source or destination file.
-
- // Check if destination directory already exists.
- // Directory.Move()
- // MSDN: .NET 3.5+: IOException: destDirName already exists.
- if (isFolder && destExists)
- NativeError.ThrowException(Win32Errors.ERROR_ALREADY_EXISTS, destFileNameLp);
-
- if (isMove)
- {
- // Ensure that the source file or directory exists.
- // Directory.Move()
- // MSDN: .NET 3.5+: DirectoryNotFoundException: The path specified by sourceDirName is invalid (for example, it is on an unmapped drive).
- if (!ExistsCore(isFolder, transaction, sourceFileNameLp, PathFormat.LongFullPath))
- NativeError.ThrowException(isFolder ? Win32Errors.ERROR_PATH_NOT_FOUND : Win32Errors.ERROR_FILE_NOT_FOUND, sourceFileNameLp);
- }
-
-
- // Try reading the source file.
- var fileNameLp = destFileNameLp;
-
- if (!isFolder)
- {
- using (var safeHandle = CreateFileCore(transaction, sourceFileNameLp, ExtendedFileAttributes.Normal, null, FileMode.Open, 0, FileShare.Read, false, PathFormat.LongFullPath))
- if (safeHandle != null && safeHandle.IsInvalid)
- fileNameLp = sourceFileNameLp;
- }
-
- if (lastError == Win32Errors.ERROR_ACCESS_DENIED)
- {
- // File.Copy()
- // File.Move()
- // MSDN: .NET 3.5+: IOException: An I/O error has occurred.
- // Directory exists with the same name as the file.
- if (!isFolder && destExists)
- NativeError.ThrowException(lastError, string.Format(CultureInfo.CurrentCulture, Resources.Target_File_Is_A_Directory, destFileNameLp));
-
- if (isMove)
- {
- var data = new NativeMethods.WIN32_FILE_ATTRIBUTE_DATA();
- FillAttributeInfoCore(transaction, destFileNameLp, ref data, false, true);
-
- if (data.dwFileAttributes != (FileAttributes) (-1))
- {
- if ((data.dwFileAttributes & FileAttributes.ReadOnly) != 0)
- {
- // MSDN: .NET 3.5+: IOException: The directory specified by path is read-only.
- if (((MoveOptions) moveOptions & MoveOptions.ReplaceExisting) != 0)
- {
- // Reset file system object attributes.
- SetAttributesCore(isFolder, transaction, destFileNameLp, FileAttributes.Normal, PathFormat.LongFullPath);
-
- goto startCopyMove;
- }
-
-
- // MSDN: .NET 3.5+: UnauthorizedAccessException: destinationFileName is read-only.
- // MSDN: Win32 CopyFileXxx: This function fails with ERROR_ACCESS_DENIED if the destination file already exists
- // and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.
- throw new FileReadOnlyException(destFileNameLp);
- }
-
-
- // MSDN: Win32 CopyFileXxx: This function fails with ERROR_ACCESS_DENIED if the destination file already exists
- // and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.
- if ((data.dwFileAttributes & FileAttributes.Hidden) != 0)
- NativeError.ThrowException(lastError, string.Format(CultureInfo.CurrentCulture, Resources.File_Is_Hidden, destFileNameLp));
- }
- }
- }
-
-
- // MSDN: .NET 3.5+: An I/O error has occurred.
- // File.Copy(): IOException: destinationFileName exists and overwrite is false.
- // File.Move(): The destination file already exists or sourceFileName was not found.
- NativeError.ThrowException(lastError, fileNameLp);
-
- break;
- }
-
- #endregion // Win32Errors
- }
- }
-
- #endregion // Win32 Copy/Move
-
-
- #region Transfer Timestamps
-
- // Apply original Timestamps if requested.
- // MoveFileWithProgress() / MoveFileTransacted() automatically preserve Timestamps.
- // File.Copy()
-
- if (success && preserveDates && isCopy)
- {
- // Currently preserveDates is only used with files.
- var data = new NativeMethods.WIN32_FILE_ATTRIBUTE_DATA();
- var dataInitialised = FillAttributeInfoCore(transaction, sourceFileNameLp, ref data, false, true);
-
- if (dataInitialised == Win32Errors.ERROR_SUCCESS && data.dwFileAttributes != (FileAttributes) (-1))
- SetFsoDateTimeCore(false, transaction, destFileNameLp, DateTime.FromFileTimeUtc(data.ftCreationTime),
- DateTime.FromFileTimeUtc(data.ftLastAccessTime), DateTime.FromFileTimeUtc(data.ftLastWriteTime), false, PathFormat.LongFullPath);
- }
-
- #endregion // Transfer Timestamps
-
-
- return cmr;
- }
-
- #endregion // Internal Methods
- }
- }
|