|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332 |
- /* 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 CopyMoveResult Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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 CopyMoveResult Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult Copy(string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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 CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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 CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, CopyOptions copyOptions, bool preserveDates, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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 CopyMoveResult Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult Move(string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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 CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
- {
- return 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 CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
- {
- return 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;
- var skipPathChecks = pathFormat == PathFormat.LongFullPath;
-
-
- if (!skipPathChecks)
- {
- 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);
- }
-
-
- // 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.
- var cancel = false;
-
- // Determine Copy or Move action.
- var isCopy = DetermineIsCopy(copyOptions, moveOptions);
- var isMove = !isCopy;
-
-
- var raiseException = progressHandler == null;
- //Task completedTask = null;
-
-
- // Setup callback function for progress notifications.
- var routine = progressHandler != null
- ? (totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile, lpData) =>
- progressHandler(totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, userProgressData)
- : (NativeMethods.NativeCopyMoveProgressRoutine) null;
-
-
- var cmr = copyMoveResult ?? new CopyMoveResult(sourceFileNameLp, destFileNameLp, false, (int) Win32Errors.ERROR_SUCCESS);
-
- #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.
-
- cancel = true;
- cmr.IsCanceled = cancel;
- }
-
- 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, true, 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
- }
- }
|