예제 #1
0
        /// <summary>
        /// 载入Icon
        /// </summary>
        public void LoadIcon()
        {
            var iconPath = ShortcutHelper.GetShortcutIconPath(FullPath, out var iconId);

            if (string.IsNullOrWhiteSpace(iconPath))
            {
                //targetPath对应icon
                iconPath = TargetPath;
            }

            BitmapSource logo;

            if (iconPath.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) ||
                iconPath.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
            {
                try {
                    var tmp = Helper.GetLargeIconsFromExeFile(iconPath, iconId);
                    if (tmp != null)
                    {
                        logo = tmp.ToBitmap().ToBitmapSource();
                        Helper.DestroyIcon(tmp.Handle);
                        tmp.Dispose();
                    }
                    else
                    {
                        logo = Unknown;
                    }
                }
                catch {
                    //catch(NotImplementedException) {
                    logo = Unknown;
                }
            }
            else
            {
                //ico
                try {
                    var ico = new Icon(iconPath);
                    logo = ico.ToBitmap().ToBitmapSource();
                    ico.Dispose();
                }
                catch {
                    //catch (NotImplementedException) {
                    logo = Unknown;
                }
            }

            Logo = logo;
        }