Add icon (mac & pc) to file using Cocoa

I want to add an icon (icns and ico) to a file in my iPhone application, and I'm not quite sure where to start looking! Therefore, when this file is viewed in Finder or Windows Explorer, it will have a custom icon.

Can someone point me in the right direction?

+1
source share
2 answers

I have no answer for Windows Explorer. For MacOS, the custom file icon is stored in the file’s fork resource as kIconFamilyType with the identifier kCustomIconResource . The custom icon for the folder is stored in a file named Icon\r (\ r, meaning mac newline) in the folder. For volumes, the custom icon is located in the .VolumeIcon.icns file at the root of the volume. In each case, you must set the kHasCustomIcon Finder flag for the item.

Cocoa does not give you access to resource virtualization or Finder frames. Use FSSetCatalogInfo to set the Finder flags. Use FSCreateResourceFork, AddResource, and CloseResFile to add a custom icon family to the file. The same resource fork calls are used for the custom icon file in the folder.

The usual way to set an icon is to either paste it from the Get Info Finder window or send the apple event to the Finder. You can send Apple events from cocoa, but that will not help with the iPhone.

To create a file on the iPhone with a fork resource, you probably have to create a zip archive that will create a resource fork when unpacking. You will have to manually create a wrapper for the resource fork around the data in the icon family. The resource resource structure is well documented.

It would probably be easier to have a helper application on MacOS.

+2
source

You can use the -setIcon: forFile: options: method in NSWorkspace if you want to change the file or folder icon in Mac OS X.

+6
source

Source: https://habr.com/ru/post/900672/


All Articles