Page 1 of 1

"import icon..." -- doable?

Posted: Sat Jul 20, 2013 3:31 pm
by FourthWorld
Certain types of media and other file management apps could benefit from being able to render the icon associated with the file, whether it be an app or a document. I would imagine one way to do this syntactically might be:

import icon from file <filePath> [at <size>]

...where "size" is the width/height of the resulting image in pixels.

How feasible would it be to do this for Mac, Win, and Linux?
And am I the only one who would find this useful?

Re: "import icon..." -- doable?

Posted: Mon Jul 22, 2013 4:09 pm
by SirWobbyTheFirst
Do you mean something along the lines of displaying a .EXE's icon in an image similar to the properties window on Windows? Like below:

Image

Re: "import icon..." -- doable?

Posted: Tue Jul 23, 2013 9:59 am
by LCMark
Well, on Windows, you can certainly lookup the icon of an executable as its embedded within it. For documents, you resolve the filetype of the document then lookup in the registry for its icon (which will be also be embedded in some executable). Mac, it would be a similar story - the icon is stored in the app bundle, and referenced in the plist, same for document icons. Linux, I'm not 100% sure - I think gnome has a registry of some sort for such things, so it will depend on what APIs are provided there.

Re: "import icon..." -- doable?

Posted: Tue Jul 23, 2013 11:57 am
by monte
OS X is easy... [NSWorkspace iconForFile:..

Re: "import icon..." -- doable?

Posted: Tue Jul 23, 2013 3:45 pm
by FourthWorld
runrevmark wrote:Well, on Windows, you can certainly lookup the icon of an executable as its embedded within it. For documents, you resolve the filetype of the document then lookup in the registry for its icon (which will be also be embedded in some executable). Mac, it would be a similar story - the icon is stored in the app bundle, and referenced in the plist, same for document icons. Linux, I'm not 100% sure - I think gnome has a registry of some sort for such things, so it will depend on what APIs are provided there.
If you'd be interested in the hard part of parsing out the ICO and icns resources and converting those to PNG for import, I'd be happy to look up the GTK APIs for Linux.

Re: "import icon..." -- doable?

Posted: Tue Jul 23, 2013 4:53 pm
by SirWobbyTheFirst
runrevmark wrote:Well, on Windows, you can certainly lookup the icon of an executable as its embedded within it. For documents, you resolve the filetype of the document then lookup in the registry for its icon (which will be also be embedded in some executable). Mac, it would be a similar story - the icon is stored in the app bundle, and referenced in the plist, same for document icons. Linux, I'm not 100% sure - I think gnome has a registry of some sort for such things, so it will depend on what APIs are provided there.
In order to load the icon for a .EXE, you need to parse the PE format, go to the resources section and then pick out the first icon. Microsoft has got a description of the PE format on the MSDN site which could help. http://msdn.microsoft.com/en-us/library ... 63119.aspx

At that point, you will need to parse an ICO format and convert it to PNG or another image type before you could display it in LiveCode.

Re: "import icon..." -- doable?

Posted: Thu Jul 25, 2013 9:33 am
by LCMark
Well, whether that is necessary depends on how 'cross-platform' we want the feature - i.e. in the first instance if it is sufficient to only fetch icons from Windows exes on Windows and Mac bundles on Mac (Linux doesn't have any sort of embedded icons, they are - I believe - registered with the desktop environment so that won't be available anywhere but Linux) then there are system API calls that do the work (meaning parsing of exe files and such isn't necessary).

Re: "import icon..." -- doable?

Posted: Thu Jul 25, 2013 4:29 pm
by SirWobbyTheFirst
runrevmark wrote:Well, whether that is necessary depends on how 'cross-platform' we want the feature - i.e. in the first instance if it is sufficient to only fetch icons from Windows exes on Windows and Mac bundles on Mac (Linux doesn't have any sort of embedded icons, they are - I believe - registered with the desktop environment so that won't be available anywhere but Linux) then there are system API calls that do the work (meaning parsing of exe files and such isn't necessary).
That does make sense, I had a look on MSDN and found a number of API calls for extracting icons and have listed them below, all seem to be located within Shell32.dll, so they should work across pretty much every version of Windows since Windows 95 (Although the articles state support since Windows 2000), even in the live environments like Windows PE, so if you develop an app for corporate use, it would work in those environments too.

Hell revEnterprise 4.0 was able to fire up with no problems in those environments, well provided that you used the 32-bit Windows PE as the 64-bit version doesn't include support for 32-bit apps.

http://msdn.microsoft.com/en-us/library ... s.85).aspx