Re: Keeping a Folder's icon with packagemaker/installer (SOLVED) (PAINFULLY)
Re: Keeping a Folder's icon with packagemaker/installer (SOLVED) (PAINFULLY)
- Subject: Re: Keeping a Folder's icon with packagemaker/installer (SOLVED) (PAINFULLY)
- From: Russ <email@hidden>
- Date: Sun, 7 Dec 2008 20:42:33 -0800 (PST)
OK, this is really and officially a pain in the hindquarters. I'd rant here about the stupidity of it all and why it should be fixed, but obviously Apple doesn't have anyone working on Installer or Packagemaker to read it. Maybe I can save someone else from further time-wastage.
Packagemaker does not preserve the resource forks any more, if it ever did. You get a zero-length plain data file. Here is what is necessary:
I'm assuming you've manually set up the desired icon on your folder(s), and that you are copying from the where-built-and-installed location to a separate folder structure from which you will make the package. We'll mess with that copy to get the icon to come out right.
In your build process, use ditto to build an archive, something like this:
--------------------
cd "$the_folder_in_your_package"
ditto -c "Icon"$'\r' Icon.cpio
rm "Icon"$'\r'
--------------------
I'm not sure how well this will transmit through the mailing list, but note there's some bash gimmickry to be able to create the file name with the return in it. Using ditto is a good idea because it will unpack the archive appropriately whether the target volume is HFS+ or unix-style, and it is present in the vanilla Leopard installation.
Have the Icon.cpio file installed by your package, along with the setHasCustomIcon program below. Make sure that when you configure ownership and permissions in your package as it is being built, you keep the setHasCustomIcon program's executable bit turned on.
You need a postflight install script, something like this:
----------------------
#!/bin/csh
# $0: script path; $1: package path; $2: target location; $3: target volume
cd /tmp # failsafe
cd "$2/Applications/yourApp"
ditto -x "Icon.cpio" .
./setHasCustomIcon ../yourApp
rm setHasCustomIcon Icon.cpio
---------------------
In my postflight script, I also reset the ownership and permissions of everything, since packagemaker messes them up for some customers. Don't forget to put the postflight script into the resources folder of your package, and include it on the scripts tab of your package in packagemaker.
setHasCustomIcon.cpp (note that file functionality isn't required)
--------------------------
#include <stdio.h>
#include "CoreServices/CoreServices.h"
// Micro-program to turn on the "has custom icon" bit for a file or folder
// files are made invisible too --- assumed to be on the actual icon
// One argument in argv[1]: the name of the folder to be modified.
// Compile with: gcc -arch ppc -arch i386 -o setHasCustomIcon setHasCustomIcon.cpp -lstdc++ -framework carbon
int
main(int argc, char *argv[])
{
OSErr err;
Boolean isDir;
FSRef fsRef;
FSCatalogInfo catInfo;
FolderInfo *folderInfo;
FileInfo *fileInfo;
// Open the file/folder
if (argc != 2) goto bail;
err = FSPathMakeRef((const UInt8*)argv[1], &fsRef, &isDir);
if (err != noErr) goto bail;
// Get finder catalog info
err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo, 0, 0, 0);
if (err != noErr) goto bail;
// Turn on the custom-icon bit
if (isDir)
{
folderInfo = (FolderInfo*)catInfo.finderInfo;
folderInfo->finderFlags |= kHasCustomIcon;
}
else
{
fileInfo = (FileInfo*)catInfo.finderInfo;
fileInfo->finderFlags |= kHasCustomIcon | kIsInvisible;
}
// Save the modified attributes
err = FSSetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo);
if (err != noErr) goto bail;
bail:
return 0;
}
------------------------------
Wasn't that fun? It's nice we all have time to play.
----- Original Message ----
To: Installer-Dev mailing-list <email@hidden>
Sent: Sunday, December 7, 2008 4:19:44 PM
Subject: Re: Keeping a Folder's icon with packagemaker/installer
On 2008-12-04, at 21:29:15, Russ wrote:
> Is there a way to get the installed folder's icon set up right, either by installing the Icon? file correctly or some other (simple) method? Adobe CS3 and Snapz Pro X have got it working somehow. I'd just as soon NOT have to create some (Carbon AE) program to go do this programmatically as a post-installation hack. Thanks.
It might be possible to specify a pre-existing "Icon\r" file to be placed in your folder. Then the only code you'd have to take care of is setting the custom icon bit on the folder. It's only a few lines using FSSetCatalogInfo() and FSSetCatalogInfo(). Apple has some (really old) sample code at: <http://developer.apple.com/samplecode/SetCustomIcon/>
Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@
Democracy: Two wolves and a sheep voting on lunch.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden