コード例 #1
0
        /// <summary>
        /// Reset to default state
        /// </summary>
        internal static void Unload()
        {
            mainWindow.Bar.ToolTip = mainWindow.Bar.Text = NoImage;
            mainWindow.Title       = NoImage + " - " + AppName;
            canNavigate            = false;
            mainWindow.img.Source  = null;
            freshStartup           = true;
            if (Pics != null)
            {
                Pics.Clear();
            }

            PreloadCount = 0;
            Preloader.Clear();
            FolderIndex               = 0;
            mainWindow.img.Width      = mainWindow.Scroller.Width = mainWindow.Scroller.Height =
                mainWindow.img.Height = double.NaN;
            xWidth          = xHeight = 0;
            prevPicResource = null;

            if (!string.IsNullOrWhiteSpace(TempZipPath))
            {
                DeleteTempFiles();
                TempZipPath = string.Empty;
            }

            NoProgress();
            AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2));
        }
コード例 #2
0
        /// <summary>
        /// Refresh the current list of pics and reload them if there is some missing or changes.
        /// </summary>
        internal static void Reload(bool fromBackup = false)
        {
            if (fromBackup && string.IsNullOrWhiteSpace(xPicPath))
            {
                Unload();
                return;
            }

            var x = fromBackup ? xPicPath : Pics[FolderIndex];

            if (File.Exists(x))
            {
                // Force reloading values by setting freshStartup to true
                freshStartup = true;

                // Clear Preloader, to avoid errors by FolderIndex changing location because of re-sorting
                Preloader.Clear();

                // Need a sort method instead
                PicGalleryLogic.Clear();
                PicGalleryLoad.Load();

                Pic(x);

                // Reset
                if (isZoomed)
                {
                    ResetZoom();
                }

                if (Flipped)
                {
                    Flip();
                }

                if (Rotateint != 0)
                {
                    Rotate(0);
                }
            }
            else
            {
                Unload();
                ToolTipStyle("Unknown error occured");
            }
        }
コード例 #3
0
        /// <summary>
        /// Update after FastPic() was used
        /// </summary>
        internal static void FastPicUpdate()
        {
            if (!FastPicRunning)
            {
                return;
            }

            //fastPicTimer.Stop();
            FastPicRunning = false;

            if (!Preloader.Contains(Pics[FolderIndex]))
            {
                PreloadCount = 0;
                Preloader.Clear();
            }

            Pic(FolderIndex);
        }
コード例 #4
0
        /// <summary>
        /// Clears data, to free objects no longer necessary to store in memory and allow changing folder without error.
        /// </summary>
        internal static void ChangeFolder(bool backup = false)
        {
            if (backup)
            {
                // Make a backup of xPicPath and FolderIndex
                if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]))
                {
                    xPicPath = Pics[FolderIndex];
                }
            }

            Pics.Clear();
            Preloader.Clear();
            DeleteTempFiles();
            PreloadCount = 0;
            freshStartup = true;

            if (Properties.Settings.Default.PicGallery > 0)
            {
                PicGalleryLogic.Clear();
            }
        }
コード例 #5
0
        /// <summary>
        /// Goes to next, previous, first or last file in folder
        /// </summary>
        /// <param name="next">Whether it's forward or not</param>
        /// <param name="end">Whether to go to last or first,
        /// depending on the next value</param>
        internal static void Pic(bool next = true, bool end = false)
        {
            // Exit if not intended to change picture
            if (!canNavigate)
            {
                return;
            }

            // exit if browsing PicGallery
            if (picGallery != null)
            {
                if (Properties.Settings.Default.PicGallery == 1)
                {
                    if (PicGalleryLogic.IsOpen)
                    {
                        return;
                    }
                }
            }

            // Make backup?
            var x = FolderIndex;

            // Go to first or last
            if (end)
            {
                FolderIndex = next ? Pics.Count - 1 : 0;

                // Reset preloader values to prevent errors
                if (Pics.Count > 20)
                {
                    Preloader.Clear();
                }

                PreloadCount = 4;
            }
            // Go to next or previous
            else
            {
                if (next)
                {
                    // loop next
                    if (Properties.Settings.Default.Looping)
                    {
                        FolderIndex = FolderIndex == Pics.Count - 1 ? 0 : FolderIndex + 1;
                    }
                    else
                    {
                        // Go to next if able
                        if (FolderIndex + 1 == Pics.Count)
                        {
                            return;
                        }

                        FolderIndex++;
                    }

                    PreloadCount++;
                    reverse = false;
                }
                else
                {
                    // Loop prev
                    if (Properties.Settings.Default.Looping)
                    {
                        FolderIndex = FolderIndex == 0 ? Pics.Count - 1 : FolderIndex - 1;
                    }
                    else
                    {
                        // Go to prev if able
                        if (FolderIndex - 1 < 0)
                        {
                            return;
                        }

                        FolderIndex--;
                    }

                    PreloadCount--;
                    reverse = true;
                }
            }

            // Go to the image!
            Pic(FolderIndex);

            // Update PicGallery selected item, if needed
            if (picGallery != null)
            {
                if (Properties.Settings.Default.PicGallery > 0)
                {
                    if (picGallery.Container.Children.Count > FolderIndex)
                    {
                        var prevItem = picGallery.Container.Children[x] as PicGalleryItem;
                        prevItem.SetSelected(false);

                        var nextItem = picGallery.Container.Children[FolderIndex] as PicGalleryItem;
                        nextItem.SetSelected(true);
                        PicGalleryScroll.ScrollTo();
                    }
                    else
                    {
                        // TODO Find way to get PicGalleryItem an alternative way...
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Loads a picture from a given file path and does extra error checking
        /// </summary>
        /// <param name="path"></param>
        internal static async void Pic(string path)
        {
            // Set Loading
            mainWindow.Title       = mainWindow.Bar.Text = Loading;
            mainWindow.Bar.ToolTip = Loading;
            if (mainWindow.img.Source == null)
            {
                AjaxLoadingStart();
            }

            // Handle if from web
            if (!File.Exists(path))
            {
                if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                {
                    LoadFromWeb.PicWeb(path);
                }
                else
                {
                    Unload();
                }

                return;
            }

            // If count not correct or just started, get values
            if (Pics.Count <= FolderIndex || FolderIndex < 0 || freshStartup)
            {
                await GetValues(path).ConfigureAwait(true);
            }
            // If the file is in the same folder, navigate to it. If not, start manual loading procedure.
            else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(path) != Path.GetDirectoryName(Pics[FolderIndex]))
            {
                //// Reset zipped values
                //if (!string.IsNullOrWhiteSpace(TempZipPath))
                //{
                //    DeleteTempFiles();
                //    TempZipPath = string.Empty;
                //    RecentFiles.SetZipped(string.Empty, false);
                //}

                // Reset old values and get new
                ChangeFolder(true);
                await GetValues(path).ConfigureAwait(true);
            }

            // If no need to reset values, get index
            else if (Pics != null)
            {
                FolderIndex = Pics.IndexOf(path);
            }

            if (Pics != null)
            {
                // Fix large archive extraction error
                if (Pics.Count == 0)
                {
                    var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true);

                    if (!recovery)
                    {
                        if (sexyToolTip.Opacity == 0)
                        {
                            ToolTipStyle("Archive could not be processed");
                        }

                        Reload(true);
                        return;
                    }
                    mainWindow.Focus();
                }
            }
            else
            {
                Reload(true);
                return;
            }

            if (File.Exists(Pics[FolderIndex]))
            {
                if (!freshStartup)
                {
                    Preloader.Clear();
                }

                // Navigate to picture using obtained index
                Pic(FolderIndex);
            }
            else
            {
                Reload(true);
                return;
            }

            // Load images for PicGallery if enabled
            if (Properties.Settings.Default.PicGallery > 0)
            {
                if (!PicGalleryLogic.IsLoading)
                {
                    await PicGalleryLoad.Load().ConfigureAwait(true);
                }
            }

            prevPicResource = null; // Make sure to not waste memory
        }