/// <summary>
 /// Exception if path returns another type as excepted
 /// </summary>
 public UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType expected, QuickIOFileSystemEntryType found, string path )
     : base( "FileSystemEntryType not matched!" )
 {
     Expected = expected;
     Found = found;
     Path = path;
 }
예제 #2
0
 /// <summary>
 /// Exception if path returns another type as excepted
 /// </summary>
 public UnmatchedFileSystemEntryTypeException(QuickIOFileSystemEntryType expected, QuickIOFileSystemEntryType found, string path)
     : base("FileSystemEntryType not matched!")
 {
     Expected = expected;
     Found    = found;
     Path     = path;
 }
예제 #3
0
        /// <summary>
        /// Checks whether the path with the expected system entry type exists
        /// </summary>
        /// <param name="pathInfo">A file or a directory</param>
        /// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
        /// <returns></returns>
        /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
        public static Boolean Exists( QuickIOPathInfo pathInfo, QuickIOFileSystemEntryType systemEntryType )
        {
            switch ( systemEntryType )
            {
                case QuickIOFileSystemEntryType.Directory:
                    try
                    {
                        InternalQuickIO.LoadDirectoryFromPathInfo( pathInfo );
                        return true;
                    }
                    catch ( PathNotFoundException )
                    {
                        return false;
                    }

                case QuickIOFileSystemEntryType.File:
                    try
                    {
                        InternalQuickIO.LoadFileFromPathInfo( pathInfo );
                        return true;
                    }
                    catch ( PathNotFoundException )
                    {
                        return false;
                    }

                default:
                    throw new ArgumentException( "Unknown QuickIOFileSystemEntryType passed." );
            }
        }
예제 #4
0
 /// <summary>
 /// Exception if path returns another type as excepted
 /// </summary>
 public UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType estimated, QuickIOFileSystemEntryType found, string path )
     : base( "FileSystemEntryType not matched!" )
 {
     Estimated = estimated;
     Found = found;
     FullName = path;
 }
예제 #5
0
 /// <summary>
 /// Creates an instance of <see cref = "QuickIOFileSystemEntry"/>
 /// </summary>
 internal QuickIOFileSystemEntry(string path, QuickIOFileSystemEntryType type, FileAttributes attributes, ulong bytes)
 {
     Contract.Requires(!string.IsNullOrWhiteSpace(path));
     Path       = path;
     Type       = type;
     Attributes = attributes;
     Bytes      = bytes;
 }
 /// <summary>
 /// Creates an instance of <see cref = "QuickIOFileSystemEntry"/>
 /// </summary>
 internal QuickIOFileSystemEntry( string path, QuickIOFileSystemEntryType type, FileAttributes  attributes, ulong bytes)
 {
     Contract.Requires( !string.IsNullOrWhiteSpace( path ) );
     Path = path;
     Type = type;
     Attributes = attributes;
     Bytes = bytes;
 }
        /// <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>
        public static IEnumerable<String> EnumerateSystemPaths( String uncDirectoryPath, String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOFileSystemEntryType? filterType = null )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( uncDirectoryPath ) );
            Contract.Ensures( Contract.Result<IEnumerable<String>>() != null );


            IEnumerable<QuickIOFileSystemEntry> entries = EnumerateFileSystemEntries( uncDirectoryPath, pattern, searchOption, enumerateOptions );

            // filter?
            if( filterType != null )
            {
                entries = entries.Where( entry => entry.Type == filterType );
            }

            // TODO: path format

            return entries.Select( entry => entry.Path );
        }
예제 #8
0
        /// <summary>
        /// Checks whether the path with the expected system entry type exists
        /// </summary>
        /// <param name="path">Path to a file or a directory</param>
        /// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
        /// <returns></returns>
        /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
        public static Boolean Exists( String path, QuickIOFileSystemEntryType systemEntryType )
        {
            var info = new QuickIOPathInfo( path );
            if ( !info.Exists )
            {
                return false;
            }

            if ( info.IsRoot && systemEntryType == QuickIOFileSystemEntryType.Directory ) // root is always directory
            {
                return true;
            }

            if ( info.SystemEntryType == systemEntryType )
            {
                return true;
            }

            throw new UnmatchedFileSystemEntryTypeException( systemEntryType, info.SystemEntryType, info.FullName );
        }
예제 #9
0
 /// <summary>
 /// Returns true if path exists. Checks <see cref="QuickIOFileSystemEntryType"/>
 /// </summary>
 /// <returns></returns>
 public Boolean CheckExistance( QuickIOFileSystemEntryType? systemEntryType = null )
 {
     return systemEntryType == null ? InternalQuickIO.Exists( this ) : InternalQuickIOCommon.Exists( FullNameUnc, ( QuickIOFileSystemEntryType ) systemEntryType );
 }
예제 #10
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 );
        }
예제 #11
0
 /// <summary>
 /// Gets the <see cref="Win32FindData"/> from the passed <see cref="QuickIOPathInfo"/>
 /// </summary>
 /// <param name="pathInfo">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( QuickIOPathInfo pathInfo, QuickIOFileSystemEntryType? estimatedFileSystemEntryType )
 {
     return GetFindDataFromPath( pathInfo.FullNameUnc, estimatedFileSystemEntryType );
 }
예제 #12
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;
        }
        public static Win32FindData GetFindDataFromPath( string fullpath, QuickIOFileSystemEntryType? estimatedFileSystemEntryType = null )
        {
            Contract.Requires( fullpath != null );
            Contract.Ensures( Contract.Result<Win32FindData>() != null );

            Win32FindData win32FindData = SafeGetFindDataFromPath( fullpath );

            if( win32FindData == null )
            {
                throw new PathNotFoundException( fullpath );
            }

            // Check for correct type
            switch( estimatedFileSystemEntryType )
            {
                case QuickIOFileSystemEntryType.Directory:
                    {
                        // Check for directory flag
                        if( InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                        {
                            return win32FindData;
                        }
                        throw new UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType.Directory, QuickIOFileSystemEntryType.File, fullpath );
                    }
                case QuickIOFileSystemEntryType.File:
                    {
                        // Check for directory flag
                        if( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) )
                        {
                            return win32FindData;
                        }
                        throw new UnmatchedFileSystemEntryTypeException( QuickIOFileSystemEntryType.File, QuickIOFileSystemEntryType.Directory, fullpath );
                    }
                case null:
                default:
                    {
                        return win32FindData;
                    }
            }
        }
예제 #14
0
 /// <summary>
 /// Checks whether the path with the expected system entry type exists
 /// </summary>
 /// <param name="path">Path to a file or a directory</param>
 /// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
 /// <returns></returns>
 /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
 public static Boolean Exists( String path, QuickIOFileSystemEntryType systemEntryType )
 {
     return Exists( new QuickIOPathInfo( path ), systemEntryType );
 }
예제 #15
0
 /// <summary>
 /// Checks whether the path with the expected system entry type exists
 /// </summary>
 /// <param name="path">Path to a file or a directory</param>
 /// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
 /// <returns></returns>
 /// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
 public static Boolean Exists( QuickIOPathInfo path, QuickIOFileSystemEntryType systemEntryType )
 {
     return Exists( path.FullNameUnc, systemEntryType );
 }