U-C-S / Hurl

Choose the browser on the click of a link
MIT License
254 stars 8 forks source link

Setting the custom icon to an ico file yields low resolution image #65

Closed petero-dk closed 11 months ago

petero-dk commented 1 year ago

When selecting an image file for the CustomIconPath, the icon is loaded as a bitmap and defaults to a low resolution even though the icon file has a high resolution.

This could probably be easily resolved changing the following lines:

https://github.com/U-C-S/Hurl/blob/71b6b38f50e5dcece37a3f992614e5770225028c/Source/Hurl.Library/Models/Browser.cs#L41-L51

To


                if (!string.IsNullOrEmpty(CustomIconPath) && CustomIconPath.EndsWith(".ico"))
                {
                    Icon RawIcon = new System.Drawing.Icon(CustomIconPath,-1,-1);
                    return IconUtilites.ToImageSource(RawIcon);
                }
                else if (!string.IsNullOrEmpty(CustomIconPath))
                {
                    return new BitmapImage(new Uri(CustomIconPath));
                }
                else if (!string.IsNullOrEmpty(ExePath))
                {
                    Icon RawIcon = ExePath.StartsWith('"'.ToString())
                                ? IconExtractor.FromFile(ExePath.Substring(1, ExePath.Length - 2))
                                : IconExtractor.FromFile(ExePath);

                    return IconUtilites.ToImageSource(RawIcon);

also the substring method of the ExePath could be changed to using Trim() for better readability

                    Icon RawIcon = IconExtractor.FromFile(ExePath.Trim('"'));

Notes for the -1, -1 size of the icon, please see this StackOverflow post: https://stackoverflow.com/questions/35081239/how-to-retrieve-the-largest-available-image-from-an-icon-file-using-c-sharp

Note: This is untested right now, it was just a thought.

The reason I though of this is because I am setting my profiles as different browsers, and MSEdge creates a Profile icon for each profile: %USERPROFILE%\AppData\Local\Microsoft\Edge\User Data\Default\Edge Profile.ico

U-C-S commented 1 year ago

I am planning to change how icons are retrived. Will look at this soon.