Index: Mac/BuildScript/seticon.m =================================================================== --- Mac/BuildScript/seticon.m (revision 0) +++ Mac/BuildScript/seticon.m (revision 0) @@ -0,0 +1,18 @@ +/* + * Simple tool for setting an icon on a file. + */ +#import + +int main(int argc, char** argv) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSString* iconPath = [NSString stringWithUTF8String:argv[1]]; + NSString* filePath = [NSString stringWithUTF8String:argv[2]]; + + [[NSWorkspace sharedWorkspace] + setIcon: [[NSImage alloc] initWithContentsOfFile: iconPath] + forFile: filePath + options: 0]; + [pool release]; + return 0; +} Index: Mac/BuildScript/build-installer.py =================================================================== --- Mac/BuildScript/build-installer.py (revision 70167) +++ Mac/BuildScript/build-installer.py (working copy) @@ -940,78 +940,15 @@ the directory. For both files and directories write the icon as an 'icns' resource. Furthermore set kHasCustomIcon in the finder flags for filePath. """ - ref, isDirectory = Carbon.File.FSPathMakeRef(icnsPath) - icon = Carbon.Icn.ReadIconFile(ref) - del ref + toolPath = os.path.join(os.path.dirname(__file__), "seticon") + if not os.path.exists(toolPath): + dirPath = os.path.dirname(__file__) + runCommand("cc -o %s/seticon %s/seticon.m -framework Cococa"%( + shellQuote(dirPath), shellQuote(dirPath))) - # - # Open the resource fork of the target, to add the icon later on. - # For directories we use the file 'Icon\r' inside the directory. - # + runCommand("%s %s %s"%(shellQuote(toolPath), shellQuote(iconPath), + shellQuote(filePath))) - ref, isDirectory = Carbon.File.FSPathMakeRef(filePath) - - if isDirectory: - # There is a problem with getting this into the pax(1) archive, - # just ignore directory icons for now. - return - - tmpPath = os.path.join(filePath, "Icon\r") - if not os.path.exists(tmpPath): - fp = open(tmpPath, 'w') - fp.close() - - tmpRef, _ = Carbon.File.FSPathMakeRef(tmpPath) - spec = Carbon.File.FSSpec(tmpRef) - - else: - spec = Carbon.File.FSSpec(ref) - - try: - Carbon.Res.HCreateResFile(*spec.as_tuple()) - except MacOS.Error: - pass - - # Try to create the resource fork again, this will avoid problems - # when adding an icon to a directory. I have no idea why this helps, - # but without this adding the icon to a directory will fail sometimes. - try: - Carbon.Res.HCreateResFile(*spec.as_tuple()) - except MacOS.Error: - pass - - refNum = Carbon.Res.FSpOpenResFile(spec, fsRdWrPerm) - - Carbon.Res.UseResFile(refNum) - - # Check if there already is an icon, remove it if there is. - try: - h = Carbon.Res.Get1Resource('icns', kCustomIconResource) - except MacOS.Error: - pass - - else: - h.RemoveResource() - del h - - # Add the icon to the resource for of the target - res = Carbon.Res.Resource(icon) - res.AddResource('icns', kCustomIconResource, '') - res.WriteResource() - res.DetachResource() - Carbon.Res.CloseResFile(refNum) - - # And now set the kHasCustomIcon property for the target. Annoyingly, - # python doesn't seem to have bindings for the API that is needed for - # this. Cop out and call SetFile - os.system("/Developer/Tools/SetFile -a C %s"%( - shellQuote(filePath),)) - - if isDirectory: - os.system('/Developer/Tools/SetFile -a V %s'%( - shellQuote(tmpPath), - )) - def main(): # First parse options and check if we can perform our work parseOptions()