Пример #1
0
        /// <summary>
        /// Gets an ImageSource object representing the associated icon of a file.
        /// </summary>
        public ImageSource GetIconImageSource(IconSize size)
        {
            if (IsStoreApp)
            {
                var storeApp = ManagedShell.UWPInterop.StoreAppHelper.AppList.GetAppByAumid(Target);

                if (storeApp == null)
                {
                    return(IconImageConverter.GetDefaultIcon());
                }

                return(storeApp.GetIconImageSource(size));
            }

            return(IconImageConverter.GetImageFromAssociatedIcon(Path, size));
        }
Пример #2
0
        /// <summary>
        /// Gets an ImageSource object representing the associated icon of a file.
        /// </summary>
        public ImageSource GetIconImageSource(IconSize size, bool useCache)
        {
            if (IsStoreApp)
            {
                string iconUri = IconPath;

                if (!useCache || string.IsNullOrEmpty(iconUri) || !Interop.Shell.Exists(iconUri))
                {
                    try
                    {
                        string[] icon = UWPInterop.StoreAppHelper.GetAppIcon(Target, (int)size);
                        iconUri   = icon[0];
                        IconColor = icon[1];

                        if (useCache)
                        {
                            IconPath = iconUri;
                        }
                    }
                    catch
                    {
                        return(IconImageConverter.GetDefaultIcon());
                    }
                }

                try
                {
                    BitmapImage img = new BitmapImage();
                    img.BeginInit();
                    img.UriSource   = new Uri(iconUri, UriKind.Absolute);
                    img.CacheOption = BitmapCacheOption.OnLoad;
                    img.EndInit();
                    img.Freeze();
                    return(img);
                }
                catch
                {
                    return(IconImageConverter.GetDefaultIcon());
                }
            }
            else
            {
                return(IconImageConverter.GetImageFromAssociatedIcon(Path, size));
            }
        }
Пример #3
0
        /// <summary>
        /// Gets an ImageSource object representing the associated icon of a file.
        /// </summary>
        public ImageSource GetAssociatedIcon()
        {
            int size = 1;

            if (this.Category != null && this.Category.Type == AppCategoryType.QuickLaunch && Configuration.Settings.Instance.TaskbarIconSize != 1)
            {
                size = 0;
            }

            if (this.IsStoreApp)
            {
                if (string.IsNullOrEmpty(this.IconPath) || !Interop.Shell.Exists(this.IconPath))
                {
                    try
                    {
                        string[] icon = UWPInterop.StoreAppHelper.GetAppIcon(this.Target, size);
                        this.IconPath  = icon[0];
                        this.IconColor = icon[1];
                    }
                    catch
                    {
                        return(IconImageConverter.GetDefaultIcon());
                    }
                }

                try
                {
                    BitmapImage img = new BitmapImage();
                    img.BeginInit();
                    img.UriSource   = new Uri(this.IconPath, UriKind.Absolute);
                    img.CacheOption = BitmapCacheOption.OnLoad;
                    img.EndInit();
                    img.Freeze();
                    return(img);
                }
                catch
                {
                    return(IconImageConverter.GetDefaultIcon());
                }
            }
            else
            {
                return(IconImageConverter.GetImageFromAssociatedIcon(this.Path, size));
            }
        }
Пример #4
0
        /// <summary>
        /// Gets an ImageSource object representing the associated icon of a file.
        /// </summary>
        public ImageSource GetAssociatedIcon()
        {
            if (this.IsStoreApp)
            {
                if (string.IsNullOrEmpty(this.IconPath) || !Interop.Shell.Exists(this.IconPath))
                {
                    try
                    {
                        string[] icon = UWPInterop.StoreAppHelper.GetAppIcon(this.Target);
                        this.IconPath  = icon[0];
                        this.IconColor = icon[1];
                    }
                    catch
                    {
                        return(IconImageConverter.GetDefaultIcon());
                    }
                }

                try
                {
                    BitmapImage img = new BitmapImage();
                    img.BeginInit();
                    img.UriSource   = new Uri(this.IconPath, UriKind.Absolute);
                    img.CacheOption = BitmapCacheOption.OnLoad;
                    img.EndInit();
                    img.Freeze();
                    return(img);
                }
                catch
                {
                    return(IconImageConverter.GetDefaultIcon());
                }
            }
            else
            {
                return(IconImageConverter.GetImageFromAssociatedIcon(this.Path, true));
            }
        }