Retain custom icon when unpacking

I can embed support files in my app, and unpack them at startup.
When saved, they have a custom icon.
When added and unpacked, the icon is lost.

Is there a way to embed and unpack, yet keep the custom icon?

You’ll need to manually edit your primary App’s Info.plist file to add the file types to the list of Document Types and their icons. Open another app’s to see examples.

Thanks tim.
Actually not even that… the icons are totally customised: each file has an icon that is a preview of the contents. (I use MBS Plugins to do it… rather neat, but it doesn’t survive a zip/unzip)

How are you getting the icon? The MBS Icon Family stuff I use asks the system for the icon, so the system must know the document type and UTI and THAT info comes from your app’s Info.plist. The icons aren’t stored with the actual files.

A perfect example is the CMX3600 EDL (Edit Decision List) icon. If Premiere Pro or Media Composer aren’t installed on a system, you can copy all of the .edl files that you want to the system and they’ll only show up as generic document files. It’s not until you install an app that recognizes that file type and assigns an icon via it’s Info.plist Document Types entry that they get their EDL icon.

Mine doesn’t.
Same technique as setting a custom icon for a folder. Nothing to do with the UTI, its a custom icon.
In days of yore I would have expected the picture to be in a resource fork…

This sort of thing:

[code]i=NewIconFamilyMBS

  // For Mac OS X
  i.Thumbnail32BitData=p
  i.Thumbnail8BitMask=m
 
  
  // 512, 256, 128 Pixel images for Leopard
  ps=ScalePicture(p,512)
  ms=ScalePicture(m,512)
  call i.SetIconImage(ps,ms)
  ps=ScalePicture(p,256)
  ms=ScalePicture(m,256)
  call i.SetIconImage(ps,ms)
  ps=ScalePicture(p,128)
  ms=ScalePicture(m,128)
  call i.SetIconImage(ps,ms)

    n=f.AddCustomIconMBS(i,true)
 [/code]

That’s just it, there are no longer any resource forks and the system now tracks all of that stuff. The application of the custom icon to a file only applies to the system where that operation was run. For a folder, an actual file is created named “icon\r” and that stays with the folder (just like a .VolumeIcons.icns file stays with a disk).

Maybe Christian can drop in with a better explanation of what is occurring.

I just changed the icon of a txt file, then compressed it, and uncompressed it, the icon survived…

Michel - try moving the compressed file to a different system.

Could not take the time try the MBS way, so I have changed the icon through the file info dialog.

The icon shows up fine after extracting the zip archive under Snow Leopard, while it was compressed under Mavericks 10.9.5…

If I zip up a bunch of these files, and embed the zip,
I can extract the zip file and .launch it

If I do that, the icons are kept: the archive handles it.
Sadly, Finder also opens and displays the folder: unwanted behaviour.

If I unzip using code, nope.
If I embed the individual files and just copy them, the icons are lost.

What if you unzip them from a shell script within your app?

[quote=133892:@Jeff Tullin]If I unzip using code, nope.
If I embed the individual files and just copy them, the icons are lost.[/quote]

It seems the shell unzip extracts the icon information in a way that distroys it.

Got a workaround : tar the files before zipping them, then you can shell unzip and tar -xf, the icons survive fine :slight_smile:

Since tarring protects the contents, why not just “tar -zcvf” them and skip the zip step all together? They’ll be compressed with gzip.

This also gets rid of the ugly ._XXXX files created when you extract on non-OS X system.

[quote=133897:@Tim Jones]Since tarring protects the contents, why not just “tar -zcvf” them and skip the zip step all together? They’ll be compressed with gzip.

This also gets rid of the ugly ._XXXX files created when you extract on non-OS X system.[/quote]

Did not know the option -z. Great.

A few things:

What are you using to zip up the file? It may be losing the custome data.

Have you tried using the NSWorkSpace function for setting a custom icon?

If your documents are document packages, you can add in a preview file and thumbnail file and Quicklook will automatically take care of the rest for you. You’ll find the name and location of this folder on the forums, or I can look it up for you when I get back.

The icon is actually saved correctly. It is destroyed by shell unzip. Otherwise, it is preserved when opening the zip file.

But the tar method does preserve custom icons fine.

There is a API for that!

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-BCIDEBIB

performFileOperation, it’s a bit long winded as you need to pass it an array; however whenever there’s an API v.s. console application…

tar may be the way to go.
Unzipping using MBS’ zip classes may do it too… in the past I have added code to prevent the .files being created (ugly in Windows)
Just maybe this will be enough to preserve them on the mac.

If not, I guess you (Michel) mean shell out to use tar on OSX
Not sure I have the same option on Windows, so watch this space…

[quote=133965:@Jeff Tullin]If not, I guess you (Michel) mean shell out to use tar on OSX
Not sure I have the same option on Windows, so watch this space…[/quote]

Yes, I mean shell to tar on OS X.

As for Windows, you may want to do like Xojo who packs its own utility to produce tar archives that pack the Mac executables built on Windows.

See http://stackoverflow.com/questions/484133/whats-a-good-tar-utility-for-windows
where the subject is discussed. Tar is part of the Gnu project, so it is freely distributable.

But I am curious : how do you change the icon for Windows regular files (not folders) ? The MBS plugins seem not to do that, and I know of no way to do that unless placing the document inside a folder or using a shortcut.

Custom icons don’t work on windows document files. (Sorry, Windows customers. Not everything is cross platform.)
Its only Mac that I want to preserve them.
But I want cross platform code so that the same unpacking happens in both, if I can.

That said, I type hundreds of words in the forum trying to save dozens of words in Xojo code.