kevinrmartinez / RetroLinker

A GUI application to create desktop links of games running on RetroArch. For Windows and Linux.
GNU General Public License v3.0
2 stars 0 forks source link

Replace the .exe icon handling to remove Windows specific requierments #27

Open kevinrmartinez opened 4 weeks ago

kevinrmartinez commented 4 weeks ago

To extract .ico files from .exe files on Windows, the app uses Tsuda Kageyu's IconExtractor/IconUtil for .NET, that requires a bunch of Windows only libraries (DLLs), and Windows only System.Drawing .NET library. This (and another) dependency forced me to create a library that can only be compiled on Windows. Now I'm looking to fix this.

A good hint: https://github.com/jlu5/icoextract

kevinrmartinez commented 1 week ago

Tsuda Kageyu's IconExtractor/IconUtil has been modified to return a MemoryStream, instead of System.Drawing.Icon. This stream however can not be properly read by Magick.NET, instead I had to resort to SkiaSharp to read it as a PNG image, BUT SkiaSharp can't encode images as .ico!

So the solution was: Read the IconExtractor stream with SkiaSharp -> Encode it as PNG -> Dump the PNG as MemoryStream -> Read the encode with Magick.NET -> Work it as a PNG and write it to disk as an .ico.

The IconExtractor stream can be written to disk directly, but it usually results in low quality .ico files, so I prefer the solution above.

Tsuda Kageyu's IconExtractor/IconUtil still ask for windows libraries, but it does it on runtime via System.Runtime.InteropServices, so it does compile on Linux, it just that if those classes are executed outside of Windows it will result in an exception. It's not a perfect solution, but it works.