autc04 / Retro68

a gcc-based cross-compiler for classic 68K and PPC Macintoshes
GNU General Public License v3.0
548 stars 54 forks source link

Setting file attributes #58

Open antscode opened 6 years ago

antscode commented 6 years ago

Is it possible to set file attributes using Retro68? Specifically, I'd like to set the Has Bundle flag so that my icons work without having to manually update the file after building.

MPW had SetFile: http://mirror.informatimago.com/next/developer.apple.com/tools/mpw-tools/commandref/setfile.html

I see that Rez in Retro68 can do Type and Creator, but no other attributes?

Thanks.

ryandesign commented 2 years ago

Indeed, like Apple's Rez, Retro68's Rez can set type and creator but not Finder flags.

If you are running Retro68 on modern macOS, SetFile still exists at /usr/bin/SetFile (presumably you have to install the developer tools to get it) and can be used to modify the Finder flags of the the "real" two-fork version of your program that Retro68 creates (foo.APPL).

If you want to modify the file encoded in the MacBinary file that Retro68 creates (foo.bin), the Finder flags are in byte decimal 73. There may be a utility to edit them, but you can probably find a way to set the byte directly.

        Offset   Length   Contents 
        ------   ------   -------- 
        073      1        Finder flags: 
                                 Bit 7 - Locked. 
                                 Bit 6 - Invisible. 
                                 Bit 5 - Bundle. 
                                 Bit 4 - System. 
                                 Bit 3 - Bozo. 
                                 Bit 2 - Busy. 
                                 Bit 1 - Changed. 
                                 Bit 0 - Inited. 

If you want to modify the file on the disk image that Retro68 creates (foo.dsk), you can write a program to do that. Retro68 uses the libhfs library from hfsutils to read and write files on HFS disk images, and that library has the ability to read and modify a file's Finder flags. hfsutils also ships with several command line utilities, most promisingly hattrib, but its documentation says it only supports setting the invisible or locked bits; it doesn't mention the other bits like the bundle bit.

If you want to modify the file encoded in the AppleDouble files that Retro68 creates (foo and %foo.ad), the Finder flags are stored in a byte of the %foo.ad file like they are in MacBinary but unlike MacBinary they're not in a fixed position. AppleDouble and AppleSingle files are composed of several blocks, one of which is the Finder info block; you'd have to parse the file to see whether it contains a Finder info block and if so where it's located in the file. There may be a utility I'm unaware of that already does this for you and lets you set those bits.

Possibly, Retro68 should be modified to automatically set the bundle bit if the application has a BNDL resource.