コード例 #1
0
        internal override bool IsResultIncluded(SearchResult result)
        {
            bool includeFile = _includeFiles && Win32FileSystemEnumerableHelpers.IsFile(result.FindData);
            bool includeDir  = _includeDirs && Win32FileSystemEnumerableHelpers.IsDir(result.FindData);

            Contract.Assert(!(includeFile && includeDir), result.FindData.cFileName + ": current item can't be both file and dir!");
            return(includeFile || includeDir);
        }
コード例 #2
0
        [System.Security.SecurityCritical]  // auto-generated
        private void AddSearchableDirsToStack(Directory.SearchData localSearchData)
        {
            Contract.Requires(localSearchData != null);

            String         searchPath = Path.Combine(localSearchData.fullPath, "*");
            SafeFindHandle hnd        = null;

            Interop.WIN32_FIND_DATA data = new Interop.WIN32_FIND_DATA();
            try
            {
                // Get all files and dirs
                hnd = Interop.mincore.FindFirstFile(searchPath, ref data);

                if (hnd.IsInvalid)
                {
                    int errorCode = Marshal.GetLastWin32Error();

                    // This could happen if the dir doesn't contain any files.
                    // Continue with the recursive search though, eventually
                    // searchStack will become empty
                    if (errorCode == Interop.ERROR_FILE_NOT_FOUND || errorCode == Interop.ERROR_NO_MORE_FILES || errorCode == Interop.ERROR_PATH_NOT_FOUND)
                    {
                        return;
                    }

                    HandleError(errorCode, localSearchData.fullPath);
                }

                // Add subdirs to searchStack. Exempt ReparsePoints as appropriate
                int incr = 0;
                do
                {
                    if (Win32FileSystemEnumerableHelpers.IsDir(data))
                    {
                        Contract.Assert(data.cFileName.Length != 0 && !Path.IsPathRooted(data.cFileName),
                                        "Expected file system enumeration to not have empty file/directory name and not have rooted name");

                        String tempFullPath = Path.Combine(localSearchData.fullPath, data.cFileName);
                        String tempUserPath = Path.Combine(localSearchData.userPath, data.cFileName);

                        SearchOption option = localSearchData.searchOption;

                        // Setup search data for the sub directory and push it into the stack
                        Directory.SearchData searchDataSubDir = new Directory.SearchData(tempFullPath, tempUserPath, option);

                        _searchStack.Insert(incr++, searchDataSubDir);
                    }
                } while (Interop.mincore.FindNextFile(hnd, ref data));
                // We don't care about errors here
            }
            finally
            {
                if (hnd != null)
                {
                    hnd.Dispose();
                }
            }
        }
コード例 #3
0
            internal override bool IsResultIncluded(string fullPath, string userPath, ref Interop.mincore.WIN32_FIND_DATA findData, out DirectoryInfo result)
            {
                if (Win32FileSystemEnumerableHelpers.IsDir(ref findData))
                {
                    string fullPathFinal = Path.Combine(fullPath, findData.cFileName);
                    result = new DirectoryInfo(fullPathFinal, ref findData);
                    return(true);
                }

                result = null;
                return(false);
            }
コード例 #4
0
            internal override bool IsResultIncluded(string fullPath, string userPath, ref Interop.mincore.WIN32_FIND_DATA findData, out string result)
            {
                if ((_includeFiles && Win32FileSystemEnumerableHelpers.IsFile(ref findData)) ||
                    (_includeDirs && Win32FileSystemEnumerableHelpers.IsDir(ref findData)))
                {
                    result = Path.Combine(userPath, findData.cFileName);
                    return(true);
                }

                result = null;
                return(false);
            }
コード例 #5
0
            internal override bool IsResultIncluded(string fullPath, string userPath, ref Interop.Kernel32.WIN32_FIND_DATA findData, out FileInfo result)
            {
                if (Win32FileSystemEnumerableHelpers.IsFile(ref findData))
                {
                    string fullPathFinal = Path.Combine(fullPath, findData.cFileName.GetStringFromFixedBuffer());
                    result = new FileInfo(fullPathFinal, ref findData);
                    return(true);
                }

                result = null;
                return(false);
            }
コード例 #6
0
        internal override FileSystemInfo CreateObject(SearchResult result)
        {
            bool   isFile = Win32FileSystemEnumerableHelpers.IsFile(result.FindData);
            bool   isDir  = Win32FileSystemEnumerableHelpers.IsDir(result.FindData);
            String name   = result.FullPath;

            if (isDir)
            {
                IFileSystemObject fileSystemObject = new Win32FileSystem.Win32FileSystemObject(name, result.FindData, asDirectory: true);
                DirectoryInfo     di = new DirectoryInfo(name, fileSystemObject);
                return(di);
            }
            else
            {
                Contract.Assert(isFile);
                IFileSystemObject fileSystemObject = new Win32FileSystem.Win32FileSystemObject(name, result.FindData, asDirectory: false);
                FileInfo          fi = new FileInfo(name, fileSystemObject);
                return(fi);
            }
        }
コード例 #7
0
        [SecurityCritical]  // auto-generated
        private void AddSearchableDirsToList(PathPair localSearchData)
        {
            string         searchPath = Path.Combine(localSearchData.FullPath, "*");
            SafeFindHandle hnd        = null;

            Interop.mincore.WIN32_FIND_DATA data = new Interop.mincore.WIN32_FIND_DATA();
            try
            {
                // Get all files and dirs
                hnd = Interop.mincore.FindFirstFile(searchPath, ref data);

                if (hnd.IsInvalid)
                {
                    int errorCode = Marshal.GetLastWin32Error();

                    // This could happen if the dir doesn't contain any files.
                    // Continue with the recursive search though, eventually
                    // _searchList will become empty
                    if (errorCode == Interop.mincore.Errors.ERROR_FILE_NOT_FOUND || errorCode == Interop.mincore.Errors.ERROR_NO_MORE_FILES || errorCode == Interop.mincore.Errors.ERROR_PATH_NOT_FOUND)
                    {
                        return;
                    }

                    HandleError(errorCode, localSearchData.FullPath);
                }

                // Add subdirs to _searchList. Exempt ReparsePoints as appropriate
                int initialCount = _searchList.Count;
                do
                {
                    if (Win32FileSystemEnumerableHelpers.IsDir(ref data))
                    {
                        Debug.Assert(data.cFileName.Length != 0 && !Path.IsPathRooted(data.cFileName),
                                     "Expected file system enumeration to not have empty file/directory name and not have rooted name");

                        string tempFullPath = Path.Combine(localSearchData.FullPath, data.cFileName);
                        string tempUserPath = Path.Combine(localSearchData.UserPath, data.cFileName);

                        // Setup search data for the sub directory and push it into the list
                        PathPair searchDataSubDir = new PathPair(tempUserPath, tempFullPath);

                        Debug.Assert(_searchList != null, "_searchList should not be null");
                        _searchList.Add(searchDataSubDir);
                    }
                } while (Interop.mincore.FindNextFile(hnd, ref data));

                // Reverse the items just added to maintain FIFO order
                if (_searchList.Count > initialCount)
                {
                    _searchList.Reverse(initialCount, _searchList.Count - initialCount);
                }

                // We don't care about errors here
            }
            finally
            {
                if (hnd != null)
                {
                    hnd.Dispose();
                }
            }
        }
コード例 #8
0
 internal override bool IsResultIncluded(SearchResult result)
 {
     return(Win32FileSystemEnumerableHelpers.IsDir(result.FindData));
 }