Пример #1
0
        public bool MovePrev(AdvanceFlags flags)
        {
            // If before beginning or after end
            if (fCurrentDirectoryList == null)
            {
                if (fRootDirectories == null || fRootDirectories.Length == 0)
                {
                    return(false);
                }

                // if before beginning, load up the first lists
                if (fCurrentFileIndex < 0)
                {
                    return(false);
                }

                // Else, after end
                else
                {
                    // Load up the stack
                    fDirectoryStack.Clear();
                    fCurrentDirectoryList = new DirectoryList(fRootDirectories, fIncludeExtensions.Keys);
                    for (;;)
                    {
                        DirectoryList directoryList = fCurrentDirectoryList.GetSubDirectoryList();
                        if (directoryList.Directories.Length == 0)
                        {
                            break;
                        }
                        fDirectoryStack.Push(fCurrentDirectoryList);
                        fCurrentDirectoryList = directoryList;
                        fCurrentDirectoryList.CurrentIndex = fCurrentDirectoryList.Directories.Length - 1;
                    }
                    fCurrentFiles     = fCurrentDirectoryList.GetCurrentFiles();
                    fCurrentFileIndex = fCurrentFiles.Length - 1;
                }
            }

            // Else, if advance to previous folder
            else if ((flags & AdvanceFlags.NextFolder) != 0)
            {
                fCurrentFileIndex = -1;
            }

            // Else, advance to previous image
            else
            {
                --fCurrentFileIndex;
            }

            // Keep trying to load up an image until success or beginning is reached
            for (; ;)
            {
                // Get current file if available
                if (fCurrentFiles != null && fCurrentFiles.Length > 0 && fCurrentFileIndex >= 0)
                {
                    fCurrent = fCurrentFiles[fCurrentFileIndex];
                    return(true);
                }

                // Move to previous folder
                else
                {
                    fCurrentFiles     = null;
                    fCurrentFileIndex = 0;

                    // Pop the stack if necessary
                    if (fCurrentDirectoryList.CurrentIndex == 0)
                    {
                        // We're at the very beginning. Cannot go further.
                        if (fDirectoryStack.Count <= 0)
                        {
                            fCurrentFileIndex     = -1;
                            fCurrentFiles         = null;
                            fCurrentDirectoryList = null;
                            fCurrent = null;
                            return(false);
                        }

                        // Pop one directory
                        fCurrentDirectoryList = fDirectoryStack.Pop();
                    }

                    else
                    {
                        // Move to the previous peer folder
                        --fCurrentDirectoryList.CurrentIndex;

                        // Load up all subfolders
                        for (; ;)
                        {
                            DirectoryList directoryList = fCurrentDirectoryList.GetSubDirectoryList();
                            if (directoryList.Directories.Length == 0)
                            {
                                break;
                            }
                            fDirectoryStack.Push(fCurrentDirectoryList);
                            fCurrentDirectoryList = directoryList;
                            fCurrentDirectoryList.CurrentIndex = fCurrentDirectoryList.Directories.Length - 1;
                        }
                    }

                    // Load up all files
                    fCurrentFiles     = fCurrentDirectoryList.GetCurrentFiles();
                    fCurrentFileIndex = fCurrentFiles.Length - 1;
                }
            }             // End of retry loop
        }
Пример #2
0
        public bool MoveNext(AdvanceFlags flags)
        {
            // If before beginning or after end
            if (fCurrentDirectoryList == null)
            {
                if (fRootDirectories == null || fRootDirectories.Length == 0)
                {
                    return(false);
                }

                if (fCurrentFileIndex >= 0 && 0 != (flags & AdvanceFlags.Wrap))
                {
                    Reset();
                }

                // if before beginning, load up the first lists
                if (fCurrentFileIndex < 0)
                {
                    fDirectoryStack.Clear();
                    fCurrentDirectoryList = new DirectoryList(fRootDirectories, fIncludeExtensions.Keys);
                    fCurrentFiles         = fCurrentDirectoryList.GetCurrentFiles();
                    fCurrentFileIndex     = 0;
                }

                // Else, after end
                else
                {
                    return(false);
                }
            }

            // Else, if Advance to next folder
            else if ((flags & AdvanceFlags.NextFolder) != 0)
            {
                fCurrentFileIndex = int.MaxValue;
            }

            // Else, advance image
            else
            {
                ++fCurrentFileIndex;
            }

            // Keep trying to load up an image until success or end is reached
            for (; ;)
            {
                // Get next file if available
                if (fCurrentFiles != null && fCurrentFileIndex < fCurrentFiles.Length)
                {
                    fCurrent = fCurrentFiles[fCurrentFileIndex];
                    return(true);
                }

                // Advance folder
                else
                {
                    fCurrentFiles     = null;
                    fCurrentFileIndex = 0;

                    // Load up the subFolders
                    DirectoryList directoryList = fCurrentDirectoryList.GetSubDirectoryList();
                    if (directoryList.Directories.Length != 0)
                    {
                        fDirectoryStack.Push(fCurrentDirectoryList);
                        fCurrentDirectoryList = directoryList;
                    }

                    // Else, move to the next peer folder
                    else
                    {
                        ++fCurrentDirectoryList.CurrentIndex;

                        // If all folders are used up, pop levels off the stack
                        if (fCurrentDirectoryList.CurrentIndex >= fCurrentDirectoryList.Directories.Length)
                        {
                            fCurrentDirectoryList = null;
                            while (fDirectoryStack.Count > 0)
                            {
                                fCurrentDirectoryList = fDirectoryStack.Pop();
                                ++fCurrentDirectoryList.CurrentIndex;
                                if (fCurrentDirectoryList.CurrentIndex < fCurrentDirectoryList.Directories.Length)
                                {
                                    break;
                                }
                                fCurrentDirectoryList = null;
                            }
                        }
                    }

                    // We've popped the entire stack. At the end.
                    if (fCurrentDirectoryList == null)
                    {
                        if (0 == (flags & AdvanceFlags.Wrap))
                        {
                            fCurrentFileIndex     = 0;
                            fCurrentFiles         = null;
                            fCurrentDirectoryList = null;
                            fDirectoryStack.Clear();
                            fCurrent = null;
                            return(false);
                        }
                        else
                        {
                            // Wrap back to the beginning
                            fCurrentDirectoryList = new DirectoryList(fRootDirectories, fIncludeExtensions.Keys);
                            fCurrentFileIndex     = 0;
                        }
                    }

                    // Get the files from the current folder
                    fCurrentFiles = fCurrentDirectoryList.GetCurrentFiles();
                }
            }             // End of retry loop
        }