Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the display icon of the file.
        /// If the file is an image then it will return the image its self (e.g. preview).
        /// </summary>
        private ImageSource GetDisplayIcon(IconSize size)
        {
            if (Interop.Shell.Exists(FullName))
            {
                if (IsImage)
                {
                    try
                    {
                        if (GetFileSize(FullName) > 0)
                        {
                            BitmapImage img = new BitmapImage();
                            img.BeginInit();
                            img.CacheOption = BitmapCacheOption.OnLoad;
                            img.UriSource   = new Uri(FullName);
                            int dSize = 32;

                            if (size == IconSize.ExtraLarge)
                            {
                                dSize = 48;
                            }

                            Interop.Shell.TransformToPixels(dSize, dSize, out dSize, out dSize);
                            img.DecodePixelWidth = dSize;
                            img.EndInit();
                            img.Freeze();

                            return(img);
                        }
                        else
                        {
                            return(handleThumbnailError(size));
                        }
                    }
                    catch
                    {
                        return(handleThumbnailError(size));
                    }
                }
                else
                {
                    // This will attempt to get the icon - if it fails the default icon will be returned.
                    return(IconImageConverter.GetImageFromAssociatedIcon(FullName, size));
                }
            }
            else
            {
                return(IconImageConverter.GetDefaultIcon());
            }
        }
Exemplo n.º 2
0
        private ImageSource handleThumbnailError(IconSize size)
        {
            if (_imageReloadAttempts < MAX_IMAGE_RELOAD_ATTEMPTS)
            {
                // retry soon because this file might still be writing to disk
                DispatcherTimer iconcheck = new DispatcherTimer(DispatcherPriority.Background, Application.Current.Dispatcher);
                iconcheck.Interval = new TimeSpan(0, 0, 1);
                iconcheck.Tick    += iconcheck_Tick;
                iconcheck.Start();

                // show the placeholder icon so we don't show multiple icon changes. we'll show the default file icon if we run out of attempts.
                return(IconImageConverter.GetDefaultIcon());
            }
            else
            {
                // get the default icon for the file
                return(IconImageConverter.GetImageFromAssociatedIcon(FullName, size));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the display icon of the file.
        /// If the file is an image then it will return the image its self (e.g. preview).
        /// </summary>
        private ImageSource GetDisplayIcon(int size)
        {
            if (Interop.Shell.Exists(this.FullName))
            {
                if (GetFileIsImage(this.FullName))
                {
                    try
                    {
                        BitmapImage img = new BitmapImage();
                        img.BeginInit();
                        img.UriSource   = new Uri(this.FullName);
                        img.CacheOption = BitmapCacheOption.OnLoad;
                        int dSize = 32;

                        if (size == 2)
                        {
                            dSize = 48;
                        }

                        Interop.Shell.TransformToPixels(dSize, dSize, out dSize, out dSize);
                        img.DecodePixelWidth = dSize;
                        img.EndInit();
                        img.Freeze();

                        return(img);
                    }
                    catch
                    {
                        return(IconImageConverter.GetImageFromAssociatedIcon(this.FullName, size));
                    }
                }
                else
                {
                    // This will attempts to get the icon via AppGrabber - if it fails the default icon will be returned.
                    return(IconImageConverter.GetImageFromAssociatedIcon(this.FullName, size));
                }
            }
            else
            {
                return(IconImageConverter.GetDefaultIcon());
            }
        }