예제 #1
0
        /// <summary>
        /// Creates instance of <see cref="QuickIOFileMetadata"/>
        /// </summary>
        /// <param name="uncResultPath">UNC Path of current file</param>
        /// <param name="win32FindData">Win32FindData of current file</param>
        internal QuickIOFileMetadata( string uncResultPath, Win32FindData win32FindData )
            : base(uncResultPath)
        {
            base.SetFindData( win32FindData );

            Bytes = win32FindData.CalculateBytes( );
        }
예제 #2
0
        /// <summary>
        /// Creates instance of <see cref="QuickIODirectoryMetadata"/>
        /// </summary>
        /// <param name="win32FindData">Win32FindData of current directory</param>
        /// <param name="subDirs">Directories in current directory</param>
        /// <param name="subFiles">Files in current directory</param>
        /// <param name="uncFullname">UNC Path of current directory</param>
        internal QuickIODirectoryMetadata( string uncFullname, Win32FindData win32FindData, IList<QuickIODirectoryMetadata> subDirs, IList<QuickIOFileMetadata> subFiles )
            : base(uncFullname)
        {
            Directories = new ReadOnlyCollection<QuickIODirectoryMetadata>( subDirs );
            Files = new ReadOnlyCollection<QuickIOFileMetadata>( subFiles );

            base.SetFindData( win32FindData );
        }
예제 #3
0
 /// <summary>
 /// Creates the folder information on the basis of the path and the handles
 /// </summary>
 /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIODirectoryInfo( QuickIOPathInfo pathInfo, Win32FindData win32FindData )
     : base(pathInfo, win32FindData)
 {
     if ( win32FindData != null )
     {
         RetriveDateTimeInformation( win32FindData );
     }
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the QuickIOAbstractBase class, which acts as a wrapper for a file path.
 /// </summary>
 /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param>
 /// <param name="findData"><see cref="Win32FindData"/></param>
 internal QuickIOFileSystemEntryBase( QuickIOPathInfo pathInfo, Win32FindData findData )
 {
     this.FindData = findData;
     this.PathInfo = pathInfo;
     if ( findData != null )
     {
         this.Attributes = findData.dwFileAttributes;
     }
 }
예제 #5
0
        /// <summary>
        /// Checks whether a directory supplied by PINvoke is relevant
        /// </summary>
        /// <param name="win32FindData"><see cref="Win32FindData"/></param>
        /// <returns>true if is relevant; otherwise false</returns>
        public static Boolean IsSystemDirectoryEntry( Win32FindData win32FindData )
        {
            if ( win32FindData.cFileName.Length >= 3 )
            {
                return false;
            }

            return ( win32FindData.cFileName == "." || win32FindData.cFileName == ".." );
        }
예제 #6
0
        /// <summary>
        /// Determined all sub file system entries of a directory
        /// </summary>
        /// <param name="uncDirectoryPath">Path of the directory</param>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption"><see cref="SearchOption"/></param>
        /// <param name="pathFormatReturn">Specifies the type of path to return.</param>
        /// <param name="enumerateOptions">The enumeration options for exception handling</param>
        /// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        private static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular )
        {
            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, pattern );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    if ( win32Error != Win32ErrorCodes.ERROR_NO_MORE_FILES )
                    {
                        InternalQuickIOCommon.NativeExceptionMapping( uncDirectoryPath, win32Error );
                    }

                    if ( EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) )
                    {
                        yield return new KeyValuePair<string, QuickIOFileSystemEntryType>( );
                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName );

                    // Check for Directory
                    if ( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        yield return new KeyValuePair<String, QuickIOFileSystemEntryType>( FormatPathByType( pathFormatReturn, resultPath ), QuickIOFileSystemEntryType.Directory );

                        // SubFolders?!
                        if ( searchOption == SearchOption.AllDirectories )
                        {
                            foreach ( var match in EnumerateFileSystemEntryPaths( resultPath, pattern, searchOption, enumerateOptions, pathFormatReturn ) )
                            {
                                yield return match;
                            }
                        }
                    }
                    else
                    {
                        yield return new KeyValuePair<String, QuickIOFileSystemEntryType>( FormatPathByType( pathFormatReturn, resultPath ), QuickIOFileSystemEntryType.File );

                    }
                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }
        }
예제 #7
0
        /// <summary>
        /// Reurns true if passed path exists
        /// </summary>
        /// <param name="pathInfo">Path to check</param>
        public static Boolean Exists( QuickIOPathInfo pathInfo )
        {
            var win32FindData = new Win32FindData( );
            int win32Error;

            var path = pathInfo.FullNameUnc;
            if ( pathInfo.IsRoot )
            {
                path = QuickIOPath.Combine( path, "*" );
            }

            using ( var fileHandle = FindFirstSafeFileHandle( path, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                return !fileHandle.IsInvalid;
            }
        }
예제 #8
0
 /// <summary>
 /// Creates the file information on the basis of the path and <see cref="Win32FindData"/>
 /// </summary>
 /// <param name="fullName">Full path to the file</param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIOFileInfo( String fullName, Win32FindData win32FindData )
     : this(new QuickIOPathInfo( fullName ), win32FindData)
 {
     RetriveDateTimeInformation( win32FindData );
     CalculateSize( win32FindData );
 }
예제 #9
0
        /// <summary>
        /// Determined metadata of directory
        /// </summary>
        /// <param name="uncDirectoryPath">Path of the directory</param>
        /// <param name="findData"><see cref="Win32FindData"/></param>
        /// <param name="enumerateOptions">The enumeration options for exception handling</param>
        /// <returns><see cref="QuickIODirectoryMetadata"/> started with the given directory</returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        internal static QuickIODirectoryMetadata EnumerateDirectoryMetadata( String uncDirectoryPath, Win32FindData findData, QuickIOEnumerateOptions enumerateOptions )
        {
            // Results
            var subFiles = new List<QuickIOFileMetadata>( );
            var subDirs = new List<QuickIODirectoryMetadata>( );

            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, QuickIOPatternConstants.All );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    if ( win32Error != Win32ErrorCodes.ERROR_NO_MORE_FILES )
                    {
                        InternalQuickIOCommon.NativeExceptionMapping( uncDirectoryPath, win32Error );
                    }

                    if ( EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) )
                    {
                        return null;
                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var uncResultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName );

                    #region File
                    // if it's a file, add to the collection
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        var fileMetaData = new QuickIOFileMetadata( uncResultPath, win32FindData );
                        subFiles.Add( fileMetaData );
                    }
                    #endregion
                    #region Directory
                    else
                    {
                        var dir = EnumerateDirectoryMetadata( uncResultPath, win32FindData, enumerateOptions );
                        subDirs.Add( dir );
                    }
                    #endregion
                    // Create new FindData object for next result

                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }

            return new QuickIODirectoryMetadata( uncDirectoryPath, findData, subDirs, subFiles );
        }
예제 #10
0
        /// <summary>
        /// Gets the <see cref="Win32FindData"/> from the passed path.
        /// </summary>
        /// <param name="pathInfo">Path</param>
        /// <param name="pathFindData"><seealso cref="Win32FindData"/>. Will be null if path does not exist.</param>
        /// <returns>true if path is valid and <see cref="Win32FindData"/> is set</returns>
        /// <remarks>
        /// <see>
        ///     <cref>QuickIOCommon.NativeExceptionMapping</cref>
        /// </see> if invalid handle found.
        /// </remarks>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static bool TryGetFindDataFromPath( QuickIOPathInfo pathInfo, out Win32FindData pathFindData )
        {
            var win32FindData = new Win32FindData( );
            int win32Error;

            //var path = pathInfo.FullNameUnc;
            //if ( pathInfo.IsRoot )
            //{
            //    path = QuickIOPath.Combine( path, QuickIOPatternConstants.All );
            //}

            using ( var fileHandle = FindFirstSafeFileHandle( pathInfo.FullNameUnc, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
                }

                // Treffer auswerten
                // Ignore . and .. directories
                if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                {
                    pathFindData = win32FindData;
                    return true;
                }
            }

            pathFindData = null;
            return false;
        }
예제 #11
0
        /// <summary>
        /// Search Exection
        /// </summary>
        /// <param name="uncDirectoryPath">Start directory path</param>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption"><see cref="SearchOption"/></param>
        /// <param name="enumerateOptions">The enumeration options for exception handling</param>
        /// <param name="pathFormatReturn">Specifies the type of path to return.</param>
        /// <param name="filterType"><see cref="QuickIOFileSystemEntryType"/></param>
        /// <returns>Collection of path</returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        private static IEnumerable<String> FindPaths( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOFileSystemEntryType? filterType = null, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular )
        {
            // Result Container
            var results = new List<String>( );

            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, pattern );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid && EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) )
                {
                    return new List<String>( );
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName );

                    // if it's a file, add to the collection
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        if ( filterType != null && ( ( QuickIOFileSystemEntryType ) filterType == QuickIOFileSystemEntryType.File ) )
                        {
                            // It's a file
                            results.Add( FormatPathByType( pathFormatReturn, resultPath ) );
                        }
                    }
                    else
                    {
                        // It's a directory
                        // Check for search searchFocus directories
                        if ( filterType != null && ( ( QuickIOFileSystemEntryType ) filterType == QuickIOFileSystemEntryType.Directory ) )
                        {
                            results.Add( FormatPathByType( pathFormatReturn, resultPath ) );
                        }

                        // SubFolders?!
                        if ( searchOption == SearchOption.AllDirectories )
                        {
                            var r = new List<String>( FindPaths( resultPath, pattern, searchOption, filterType, enumerateOptions ) );
                            if ( r.Count > 0 )
                            {
                                results.AddRange( r );
                            }

                        }
                    }

                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }
            // Return result;
            return results;
        }
예제 #12
0
 internal static extern bool SetLastWriteFileTime( Win32FindData hFile, IntPtr lpCreationTime, IntPtr lpLastAccessTime, ref long lpLastWriteTime );
예제 #13
0
 internal static extern bool FindClose( Win32FindData win32FindData );
예제 #14
0
 internal static extern bool SetAllFileTimes( Win32FindData hFile, ref long lpCreationTime, ref long lpLastAccessTime, ref long lpLastWriteTime );
예제 #15
0
 /// <summary>
 /// Determines the time stamp of the given <see cref="Win32FindData"/>
 /// </summary>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 private void RetriveDateTimeInformation( Win32FindData win32FindData )
 {
     LastWriteTimeUtc = win32FindData.GetLastWriteTimeUtc( );
     LastAccessTimeUtc = win32FindData.GetLastAccessTimeUtc( );
     CreationTimeUtc = win32FindData.GetCreationTimeUtc( );
 }
예제 #16
0
 /// <summary>
 /// Creates the folder information on the basis of the path and the handles
 /// </summary>
 /// <param name="fullname">Full path to the directory</param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIODirectoryInfo( String fullname, Win32FindData win32FindData )
     : this(new QuickIOPathInfo( fullname ), win32FindData)
 {
 }
예제 #17
0
 /// <summary>
 /// Returns the handle by given path and finddata
 /// </summary>
 /// <param name="uncPath">Specified path</param>
 /// <param name="win32FindData">FindData to fill</param>
 /// <param name="win32Error">Win32Error Code. 0 on success</param>
 /// <returns><see cref="Win32FileHandle"/> of specified path</returns>
 private static Win32FileHandle FindFirstFileManaged( String uncPath, Win32FindData win32FindData, out Int32 win32Error )
 {
     var handle = Win32SafeNativeMethods.FindFirstFile( uncPath, win32FindData );
     win32Error = Marshal.GetLastWin32Error( );
     return handle;
 }
예제 #18
0
        ///// <summary>
        ///// Returns the <see cref="Win32FindData"/> from specified <paramref name="fullUncPath"/>
        ///// </summary>
        ///// <param name="fullUncPath">Path to the file system entry</param>
        ///// <returns><see cref="Win32FindData"/></returns>
        ///// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        /// 
        /// <summary>
        /// Returns the <see cref="Win32FindData"/> from specified <paramref name="pathInfo"/>
        /// </summary>
        /// <param name="pathInfo">Path to the file system entry</param>
        /// <returns><see cref="Win32FindData"/></returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static Win32FindData GetFindDataFromPath( QuickIOPathInfo pathInfo )
        {
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( pathInfo.FullNameUnc, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
                }

                // Treffer auswerten
                // Ignore . and .. directories
                if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                {
                    return win32FindData;
                }
            }

            throw new PathNotFoundException( pathInfo.FullName );
        }
예제 #19
0
        /// <summary>
        /// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path.
        /// </summary>
        /// <param name="path">Path to the file system entry</param>
        /// <param name="win32FindData"></param>
        /// <param name="win32Error">Last error code. 0 if no error occurs</param>
        /// <returns><see cref="SafeFileHandle"/></returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        private static Win32FileHandle FindFirstSafeFileHandle( string path, Win32FindData win32FindData, out Int32 win32Error )
        {
            var result = Win32SafeNativeMethods.FindFirstFile( path, win32FindData );
            win32Error = Marshal.GetLastWin32Error( );

            return result;
        }
예제 #20
0
 /// <summary>
 /// Creates the file information on the basis of the path and <see cref="Win32FindData"/>
 /// </summary>
 /// <param name="pathInfo">Full path to the file</param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIOFileInfo( QuickIOPathInfo pathInfo, Win32FindData win32FindData )
     : base(pathInfo, win32FindData)
 {
     RetriveDateTimeInformation( win32FindData );
     CalculateSize( win32FindData );
 }
예제 #21
0
        /// <summary>
        /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes.        
        /// </summary>
        /// <param name="path">Path to the directory to generate the statistics.</param>
        /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param>
        /// <returns>Provides the statistics of the directory</returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static QuickIOFolderStatisticResult GetDirectoryStatistics( String path, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            UInt64 fileCount = 0;
            UInt64 folderCount = 0;
            UInt64 totalSize = 0;

            // Match for start of search
            var currentPath = QuickIOPath.Combine( path, QuickIOPatternConstants.All );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    if ( EnumerationHandleInvalidFileHandle( currentPath, enumerateOptions, win32Error ) )
                    {
                        return null;
                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( path, win32FindData.cFileName );

                    // if it's a file, add to the collection
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        fileCount++;
                        totalSize += win32FindData.CalculateBytes( ); win32FindData.CalculateBytes( );
                    }
                    else
                    {
                        folderCount++;
                        var result = GetDirectoryStatistics( resultPath, enumerateOptions );
                        {
                            folderCount += result.FolderCount;
                            fileCount += result.FileCount;
                            totalSize += result.TotalBytes;
                        }
                    }

                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }

            // Return result;
            return new QuickIOFolderStatisticResult( folderCount, fileCount, totalSize );
        }
예제 #22
0
 /// <summary>
 /// Determines the type based on the attributes of the handle
 /// </summary>
 /// <param name="findData"><see cref="Win32FindData"/></param>
 /// <returns><see cref="QuickIOFileSystemEntryType"/></returns>
 internal static QuickIOFileSystemEntryType DetermineFileSystemEntry( Win32FindData findData )
 {
     return !InternalHelpers.ContainsFileAttribute( findData.dwFileAttributes, FileAttributes.Directory ) ? QuickIOFileSystemEntryType.File : QuickIOFileSystemEntryType.Directory;
 }
예제 #23
0
        /// <summary>
        /// Gets the <see cref="Win32FindData"/> from the passed path.
        /// </summary>
        /// <param name="fullUncPath">Path to the file system entry</param>
        /// <param name="estimatedFileSystemEntryType">Estimated Type (File or Directory)</param>
        /// <returns><seealso cref="Win32FindData"/></returns>
        /// <exception cref="UnmatchedFileSystemEntryTypeException">Searched for file but found folder or vise versa.</exception>
        /// <exception cref="PathNotFoundException">No entry found for passed path</exception>        
        public static Win32FindData GetFindDataFromPath( String fullUncPath, QuickIOFileSystemEntryType? estimatedFileSystemEntryType )
        {
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( fullUncPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    InternalQuickIOCommon.NativeExceptionMapping( fullUncPath, win32Error );
                }

                // Treffer auswerten
                // Ignore . and .. directories
                if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                {

                    // Check for correct type
                    switch ( estimatedFileSystemEntryType )
                    {
                        // Unimportant
                        case null:
                            {
                                return win32FindData;
                            }
                        case QuickIOFileSystemEntryType.Directory:
                            {
                                // Check for directory flag
                                if ( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                                {
                                    return win32FindData;
                                }
                                throw new UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType.Directory, QuickIOFileSystemEntryType.File, fullUncPath );
                            }
                        case QuickIOFileSystemEntryType.File:
                            {
                                // Check for directory flag
                                if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                                {
                                    return win32FindData;
                                }
                                throw new UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType.File, QuickIOFileSystemEntryType.Directory, fullUncPath );
                            }
                    }
                    return win32FindData;

                }
            }
            throw new PathNotFoundException( fullUncPath );
        }
예제 #24
0
        /// <summary>
        /// Gets the <see cref="Win32FindData"/> from the passed <paramref name="pathInfo"/>
        /// </summary>
        /// <param name="pathInfo"><seealso cref="QuickIOPathInfo"/></param>
        /// <param name="pathFindData"><seealso cref="Win32FindData"/>. Will be null if path does not exist.</param>
        /// <returns>true if path is valid and <see cref="Win32FindData"/> is set</returns>
        /// <remarks>
        /// <see>
        ///     <cref>QuickIOCommon.NativeExceptionMapping</cref>
        /// </see> if invalid handle found.
        /// </remarks>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static bool TryGetFindDataFromPath( QuickIOPathInfo pathInfo, out Win32FindData pathFindData )
        {
            if ( TryGetFindDataFromPath( pathInfo.FullNameUnc, out pathFindData ) )
            {
                return true;
            }

            pathFindData = null;
            return false;
        }
예제 #25
0
        /// <summary>
        /// Determined all subfolders of a directory
        /// </summary>
        /// <param name="pathInfo">Path of the directory</param>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption"><see cref="SearchOption"/></param>
        /// <param name="enumerateOptions">The enumeration options for exception handling</param>
        /// <returns><see cref="QuickIODirectoryInfo"/> collection of subfolders</returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        internal static IEnumerable<QuickIODirectoryInfo> EnumerateDirectories( QuickIOPathInfo pathInfo, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            // Match for start of search
            var currentPath = QuickIOPath.Combine( pathInfo.FullNameUnc, pattern );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    if ( win32Error != Win32ErrorCodes.ERROR_NO_MORE_FILES )
                    {
                        InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
                    }

                    if ( EnumerationHandleInvalidFileHandle( pathInfo.FullName, enumerateOptions, win32Error ) )
                    {
                        yield return null;

                    }
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( pathInfo.FullName, win32FindData.cFileName );

                    // Check for Directory
                    if ( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        yield return new QuickIODirectoryInfo( resultPath, win32FindData );

                        // SubFolders?!
                        if ( searchOption == SearchOption.AllDirectories )
                        {
                            foreach ( var match in EnumerateDirectories( new QuickIOPathInfo( resultPath, win32FindData.cFileName ), pattern, searchOption, enumerateOptions ) )
                            {
                                yield return match;
                            }
                        }
                    }
                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }
        }
예제 #26
0
        /// <summary>
        /// Gets the <see cref="Win32FindData"/> from the passed path.
        /// </summary>
        /// <param name="fullName">Path</param>
        /// <param name="pathFindData"><seealso cref="Win32FindData"/>. Will be null if path does not exist.</param>
        /// <returns>true if path is valid and <see cref="Win32FindData"/> is set</returns>
        /// <remarks>
        /// <see>
        ///     <cref>QuickIOCommon.NativeExceptionMapping</cref>
        /// </see> if invalid handle found.
        /// </remarks>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static bool TryGetFindDataFromPath( String fullName, out Win32FindData pathFindData )
        {
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstSafeFileHandle( fullName, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid )
                {
                    InternalQuickIOCommon.NativeExceptionMapping( fullName, win32Error );
                }

                // Treffer auswerten
                // Ignore . and .. directories
                if ( !InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                {
                    pathFindData = win32FindData;
                    return true;
                }
            }

            pathFindData = null;
            return false;
        }
예제 #27
0
        /// <summary>
        /// Determined all files of a directory
        /// </summary>
        /// <param name="uncDirectoryPath">Path of the directory</param>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption"><see cref="SearchOption"/></param>
        /// <param name="enumerateOptions">The enumeration options for exception handling</param>
        /// <returns>Collection of files</returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        internal static IEnumerable<QuickIOFileInfo> EnumerateFiles( String uncDirectoryPath, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            // Match for start of search
            var currentPath = QuickIOPath.Combine( uncDirectoryPath, pattern );

            // Find First file
            var win32FindData = new Win32FindData( );
            int win32Error;
            using ( var fileHandle = FindFirstFileManaged( currentPath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if ( fileHandle.IsInvalid && EnumerationHandleInvalidFileHandle( uncDirectoryPath, enumerateOptions, win32Error ) )
                {
                    yield return null;
                }

                // Treffer auswerten
                do
                {
                    // Ignore . and .. directories
                    if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) )
                    {
                        continue;
                    }

                    // Create hit for current search result
                    var resultPath = QuickIOPath.Combine( uncDirectoryPath, win32FindData.cFileName );

                    // Check for Directory
                    if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                    {
                        yield return new QuickIOFileInfo( resultPath, win32FindData );
                    }
                    else
                    {
                        // SubFolders?!
                        if ( searchOption == SearchOption.AllDirectories )
                        {
                            foreach ( var match in EnumerateFiles( resultPath, pattern, searchOption, enumerateOptions ) )
                            {
                                yield return match;
                            }
                        }
                    }
                    // Create new FindData object for next result
                    win32FindData = new Win32FindData( );
                } // Search for next entry
                while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) );
            }
        }
예제 #28
0
 /// <summary>
 /// Calculates the size of the file from the handle
 /// </summary>
 /// <param name="win32FindData"></param>
 private void CalculateSize( Win32FindData win32FindData )
 {
     this.Bytes = win32FindData.CalculateBytes( );
 }