Esempio n. 1
0
        internal static void Move(string sourcePath, string destinationPath)
        {
            var longPathSource      = new LongPath(sourcePath);
            var longPathDestination = new LongPath(destinationPath);

            bool result;

            if (KtmTransaction.IsInTransaction)
            {
                result = WindowsNative.MoveFileTransacted(
                    longPathSource.PathString
                    , longPathDestination.PathString
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , WindowsNative.MoveFileFlags.NONE
                    , KtmTransaction.Current.Hanlde);
            }
            else
            {
                result = WindowsNative.MoveFile(longPathSource.PathString, longPathDestination.PathString);
            }
            if (!result)
            {
                WindowsNative.HandleWindowsError();
            }
        }
Esempio n. 2
0
        /// <summary>
        ///		<see cref="IFileProvider.Copy"/>
        /// </summary>
        public void Copy(string sourcePath, string destinationPath, bool overwrite)
        {
            var longPathSource      = new LongPath(sourcePath);
            var longPathDestination = new LongPath(destinationPath);

            bool result;

            if (KtmTransaction.IsInTransaction)
            {
                bool cancel = false;
                result = WindowsNative.CopyFileTransacted(
                    longPathSource.PathString
                    , longPathDestination.PathString
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , ref cancel
                    , WindowsNative.CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS
                    , KtmTransaction.Current.Hanlde);
            }
            else
            {
                result = WindowsNative.CopyFile(longPathSource.PathString, longPathDestination.PathString, !overwrite);
            }
            if (!result)
            {
                WindowsNative.HandleWindowsError();
            }
        }
Esempio n. 3
0
        private static IEnumerable <string> EnumerateFileSystemEntries(string path, string searchPattern, bool includeDirectories, bool includeFiles)
        {
            _log.DebugFormat("EnumerateFileSystemEntries({0}, {1}, {2}, {3})", path, searchPattern, includeDirectories, includeFiles);

            LongPath longPath = new LongPath(path);

            Check.Require(longPath.IsDirectory, "path");

            return(FilesystemUtil.EnumerateFileSystemEntries(longPath, searchPattern, includeDirectories, includeFiles));
        }
Esempio n. 4
0
        internal static IEnumerable <string> EnumerateFileSystemEntries(LongPath path, string searchPattern, bool includeDirectories, bool includeFiles)
        {
            Check.DoRequireArgumentNotNull(path, "path");
            Check.Require(path.IsDirectory, "path");

            _log.DebugFormat("EnumerateFileSystemEntries({0}, {1}, {2}, {3})", path.PathString, searchPattern, includeDirectories, includeFiles);


            return(EnumerateFileSystemIterator(path, searchPattern, includeDirectories, includeFiles));
        }
Esempio n. 5
0
        /// <summary>
        ///		<see cref="IFileProvider.Open"/>
        /// </summary>
        public System.IO.FileStream Open(
            string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options)
        {
            if (bufferSize == 0)
            {
                bufferSize = 1024;
            }

            var longPath = new LongPath(path);

            SafeFileHandle handle = GetFileHandle(longPath, mode, access, share, options);

            return(new FileStream(handle, access, bufferSize, (options & FileOptions.Asynchronous) == FileOptions.Asynchronous));
        }
Esempio n. 6
0
        private static IEnumerable <string> EnumerateFileSystemIterator(
            LongPath path, string mask, bool enumerateDirectories, bool enumerateFiles)
        {
            if (string.IsNullOrEmpty(mask) || mask == ".")
            {
                mask = "*";
            }
            string unprefixedPath = path.UnPrefixedPathString;

            WindowsNative.WIN32_FIND_DATA findData;
            using (FindFileHandle handle = BeginFind(Path.Combine(path.PathString, mask), out findData))
            {
                if (handle == null)
                {
                    yield break;
                }

                do
                {
                    string fileName = findData.cFileName;

                    if (IsDirectory(findData.dwFileAttributes))
                    {
                        if (enumerateDirectories && IsRealFolder(fileName))
                        {
                            yield return(Path.Combine(unprefixedPath, fileName));
                        }
                    }
                    else
                    {
                        if (enumerateFiles)
                        {
                            yield return(Path.Combine(unprefixedPath, fileName));
                        }
                    }
                }               while (WindowsNative.FindNextFile(handle, out findData));

                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode != WindowsNative.ERROR_NO_MORE_FILES)
                {
                    WindowsNative.HandleWindowsError(errorCode);
                }
            }
        }
Esempio n. 7
0
        public void Delete(string path)
        {
            LongPath longPath = new LongPath(path);

            bool result;

            if (KtmTransaction.IsInTransaction)
            {
                result = WindowsNative.RemoveDirectoryTransacted(longPath.PathString, KtmTransaction.Current.Hanlde);
            }
            else
            {
                result = WindowsNative.RemoveDirectory(longPath.PathString);
            }
            if (!result)
            {
                WindowsNative.HandleWindowsError();
            }
        }
Esempio n. 8
0
        private static SafeFileHandle GetFileHandle(LongPath path, FileMode mode, FileAccess access, FileShare share, FileOptions options)
        {
            SafeFileHandle handle;

            if (KtmTransaction.IsInTransaction)
            {
                WindowsNative.FileMode   internalMode   = WindowsNative.TranslateFileMode(mode);
                WindowsNative.FileShare  internalShare  = WindowsNative.TranslateFileShare(share);
                WindowsNative.FileAccess internalAccess = WindowsNative.TranslateFileAccess(access);

                KtmTransactionHandle ktmTx = KtmTransaction.Current.Hanlde;

                // Create the transacted file using P/Invoke.
                handle = WindowsNative.CreateFileTransacted(
                    path.PathString,
                    internalAccess,
                    internalShare,
                    IntPtr.Zero,
                    internalMode,
                    WindowsNative.EFileAttributes.Normal,
                    IntPtr.Zero,
                    KtmTransaction.Current.Hanlde,
                    IntPtr.Zero,
                    IntPtr.Zero);
            }
            else
            {
                WindowsNative.EFileAccess underlyingAccess = WindowsNative.GetUnderlyingAccess(access);
                handle = WindowsNative.CreateFile(path.PathString, underlyingAccess, (uint)share, IntPtr.Zero, (uint)mode, (uint)options, IntPtr.Zero);
            }

            if (handle.IsInvalid)
            {
                WindowsNative.HandleWindowsError();
            }

            return(handle);
        }
Esempio n. 9
0
        public void Create(string path)
        {
            LongPath longPath = new LongPath(path);

            bool result;

            if (KtmTransaction.IsInTransaction)
            {
                result = WindowsNative.CreateDirectoryTransacted(null, longPath.PathString, IntPtr.Zero, KtmTransaction.Current.Hanlde);
            }
            else
            {
                result = WindowsNative.CreateDirectory(longPath.PathString, IntPtr.Zero);
            }
            if (!result)
            {
                int errorCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                if (errorCode != WindowsNative.ERROR_ALREADY_EXISTS || !longPath.Exists())
                {
                    WindowsNative.HandleWindowsError(errorCode);
                }
            }
        }
Esempio n. 10
0
        public bool Exists(string path)
        {
            LongPath longPath = new LongPath(path);

            return(longPath.IsDirectory);
        }