Exemplo n.º 1
0
        internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler)
        {
            this.oldMode     = Win32Native.SetErrorMode(1);
            this.searchStack = new List <Directory.SearchData>();
            string str = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern);

            if (str.Length == 0)
            {
                this.empty = true;
            }
            else
            {
                this._resultHandler = resultHandler;
                this.searchOption   = searchOption;
                this.fullPath       = Path.GetFullPathInternal(path);
                string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, str);

                this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString);
                string[] pathList = new string[] { Directory.GetDemandDir(this.fullPath, true), Directory.GetDemandDir(this.normalizedSearchPath, true) };
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, pathList, false, false).Demand();
                this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath);

                string directoryName = Path.GetDirectoryName(str);
                string str4          = originalUserPath;
                if ((directoryName != null) && (directoryName.Length != 0))
                {
                    str4 = Path.Combine(str4, directoryName);
                }
                this.userPath   = str4;
                this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption);
                this.CommonInit();
            }
        }
        internal FileSystemEnumerableIterator(string path, string originalUserPath, string searchPattern, SearchOption searchOption, SearchResultHandler <TSource> resultHandler, bool checkHost)
        {
            this.oldMode     = Win32Native.SetErrorMode(1);
            this.searchStack = new List <Directory.SearchData>();
            string text = FileSystemEnumerableIterator <TSource> .NormalizeSearchPattern(searchPattern);

            if (text.Length == 0)
            {
                this.empty = true;
                return;
            }
            this._resultHandler = resultHandler;
            this.searchOption   = searchOption;
            this.fullPath       = Path.GetFullPathInternal(path);
            string fullSearchString = FileSystemEnumerableIterator <TSource> .GetFullSearchString(this.fullPath, text);

            this.normalizedSearchPath = Path.GetDirectoryName(fullSearchString);
            if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
            {
                FileIOPermission.EmulateFileIOPermissionChecks(this.fullPath);
                FileIOPermission.EmulateFileIOPermissionChecks(this.normalizedSearchPath);
            }
            else
            {
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[]
                {
                    Directory.GetDemandDir(this.fullPath, true),
                    Directory.GetDemandDir(this.normalizedSearchPath, true)
                }, false, false).Demand();
            }
            this._checkHost     = checkHost;
            this.searchCriteria = FileSystemEnumerableIterator <TSource> .GetNormalizedSearchCriteria(fullSearchString, this.normalizedSearchPath);

            string directoryName = Path.GetDirectoryName(text);
            string path2         = originalUserPath;

            if (directoryName != null && directoryName.Length != 0)
            {
                path2 = Path.CombineNoChecks(path2, directoryName);
            }
            this.userPath   = path2;
            this.searchData = new Directory.SearchData(this.normalizedSearchPath, this.userPath, searchOption);
            this.CommonInit();
        }
Exemplo n.º 3
0
        public override bool MoveNext()
        {
            Win32Native.WIN32_FIND_DATA data = new Win32Native.WIN32_FIND_DATA();
            switch (base.state)
            {
            case 1:
                if (!this.empty)
                {
                    if (this.searchData.searchOption == SearchOption.TopDirectoryOnly)
                    {
                        base.state = 3;
                        if (base.current != null)
                        {
                            return(true);
                        }
                        goto Label_017A;
                    }
                    base.state = 2;
                    break;
                }
                base.state = 4;
                goto Label_0250;

            case 2:
                break;

            case 3:
                goto Label_017A;

            case 4:
                goto Label_0250;

            default:
                goto Label_0256;
            }
Label_015D:
            while (this.searchStack.Count > 0)
            {
                this.searchData = this.searchStack[0];
                this.searchStack.RemoveAt(0);
                this.AddSearchableDirsToStack(this.searchData);
                string fileName = this.searchData.fullPath + this.searchCriteria;
                this._hnd = Win32Native.FindFirstFile(fileName, data);
                if (this._hnd.IsInvalid)
                {
                    int hr = Marshal.GetLastWin32Error();
                    switch (hr)
                    {
                    case 2:
                    case 0x12:
                    case 3:
                    {
                        continue;
                    }
                    }
                    this._hnd.Dispose();
                    this.HandleError(hr, this.searchData.fullPath);
                }
                base.state = 3;
                this.needsParentPathDiscoveryDemand = true;
                SearchResult result = this.CreateSearchResult(this.searchData, data);
                if (!this._resultHandler.IsResultIncluded(result))
                {
                    goto Label_017A;
                }
                if (this.needsParentPathDiscoveryDemand)
                {
                    FileSystemEnumerableIterator <TSource> .DoDemand(this.searchData.fullPath);

                    this.needsParentPathDiscoveryDemand = false;
                }
                base.current = this._resultHandler.CreateObject(result);
                return(true);
            }
            base.state = 4;
            goto Label_0250;
Label_017A:
            if ((this.searchData != null) && (this._hnd != null))
            {
                while (Win32Native.FindNextFile(this._hnd, data))
                {
                    SearchResult result2 = this.CreateSearchResult(this.searchData, data);
                    if (this._resultHandler.IsResultIncluded(result2))
                    {
                        if (this.needsParentPathDiscoveryDemand)
                        {
                            FileSystemEnumerableIterator <TSource> .DoDemand(this.searchData.fullPath);

                            this.needsParentPathDiscoveryDemand = false;
                        }
                        base.current = this._resultHandler.CreateObject(result2);
                        return(true);
                    }
                }
                int num2 = Marshal.GetLastWin32Error();
                if (this._hnd != null)
                {
                    this._hnd.Dispose();
                }
                if (((num2 != 0) && (num2 != 0x12)) && (num2 != 2))
                {
                    this.HandleError(num2, this.searchData.fullPath);
                }
            }
            if (this.searchData.searchOption == SearchOption.TopDirectoryOnly)
            {
                base.state = 4;
            }
            else
            {
                base.state = 2;
                goto Label_015D;
            }
Label_0250:
            base.Dispose();
Label_0256:
            return(false);
        }