Differences between revisions 4 and 10 (spanning 6 versions)
Revision 4 as of 2008-05-18 09:11:27
Size: 2663
Editor: abuehl
Comment: removing spaces from page name
Revision 10 as of 2021-01-01 20:36:34
Size: 3096
Comment: Better header
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<Include(A:dated)>>
Line 29: Line 31:
if [ $# -eq 0  -o $# -gt 2 ] ; then
 echo "Usage: RsrcToData srcAndDestFile"
 echo "  or"
 
echo " RsrcToData srcFile destFile"
if [ $# -eq 0 ] ; then
 echo "Usage: RsrcToData FILE [FILE ...]" >&2
 echo "Example: RsrcToData *.rsrc *.ppob" >&2
Line 34: Line 35:
elif [ ! -s "$1/..namedfork/rsrc" ] ; then
 echo "no resource fork!"
 exit 2
elif [ -s "$1" ] ; then
 echo "nonempty data fork!"
 exit 3
elif [ $# -eq 1 ] ; then
 cat "$1/..namedfork/rsrc" > "$1"
 cat /dev/null > "$1/..namedfork/rsrc"
elif [ $# -eq 2 ] ; then
 cat "$1/..namedfork/rsrc" > "$2"
Line 46: Line 36:

while [ "$1" != "" ]
do
 if [ -d "$1" ] ; then
  echo "$1 is a directory" >&2
 elif [ ! -e "$1" ] ; then
  echo "$1 does not exist" >&2
 elif [ ! -s "$1/..namedfork/rsrc" ] ; then
  echo "$1 has an empty resource fork" >&2
 elif [ -s "$1" ] ; then
  echo "$1 has a nonempty data fork" >&2
 else
  # Here is the case of interest,
  # empty data fork, nonempty resource fork
  cat "$1/..namedfork/rsrc" > "$1"
  cat /dev/null > "$1/..namedfork/rsrc"
 fi
 
 shift
done
Line 49: Line 59:

Alternatively, you could convert a pure resource fork file into a text file in the "rez" format using the {{{DeRez}}} command line tool. The rez file can be converted back to a resource file by Xcode as part of a build process.
Line 51: Line 64:
CategoryMac

Note:

This page appears to contain material that is no longer relevant. Please help improve this page by updating its content.

The native Mac file system, HFS Plus, supports two forks (independent data streams) called the data fork and the resource fork. Mercurial can only handle the data fork, and if you attempt to commit a two-fork file, only the data fork will be recorded. Mac programmers adopting Mercurial must consider how to handle this limitation.

The contents of the resource fork, if any, is structured data that programs read and write using the Resource Manager APIs. However, Resource Manager data is sometimes stored in the data fork. Therefore, while a nonempty resource fork is always a resource file, a resource file is not necessarily a resource fork.

We can roughly group files with resource forks into 3 types:

  • Files in which both forks are nonempty and important. These include applications and shared libraries in the old pre-Intel-Mac CFM format, and some older document formats.

  • Data files with a few inessential resources. Examples: an image file with a thumbnail icon as a resource, a text file with a resource recording a preferred font, or a document file with a resource recording a preferred application to open it.

  • Resource files with empty data forks. Typically these would be hidden inside an application package, or merged with other resource data by a development build system.

The first kind, true two-fork files, are the most problematic, but becoming fairly rare. If you wish to preserve such files in a Mercurial repository, you will need to encode them somehow, perhaps in zip archives or using the applesingle command.

In the case of expendable resources, you might choose to just forget about them.

A pure resource fork file can usually be converted to a data fork resource file without any loss of functionality. To find pure resource fork files in the current directory hierarchy, you can use this command:

find . -type f -exec [ -s "{}/..namedfork/rsrc" -a ! -s "{}" ] \; -print

You can convert pure resource fork files to data fork resource files with the following shell script.

if [ $# -eq 0 ] ; then
        echo "Usage: RsrcToData FILE [FILE ...]" >&2
        echo "Example: RsrcToData *.rsrc *.ppob" >&2
        exit 1
fi

while [ "$1" != "" ]
do
        if [ -d "$1" ] ; then
                echo "$1 is a directory" >&2
        elif [ ! -e "$1" ] ; then
                echo "$1 does not exist" >&2
        elif [ ! -s "$1/..namedfork/rsrc" ] ; then
                echo "$1 has an empty resource fork" >&2
        elif [ -s "$1" ] ; then
                echo "$1 has a nonempty data fork" >&2
        else
                # Here is the case of interest,
                # empty data fork, nonempty resource fork
                cat "$1/..namedfork/rsrc" > "$1"
                cat /dev/null > "$1/..namedfork/rsrc"
        fi
        
        shift
done

exit 0

Alternatively, you could convert a pure resource fork file into a text file in the "rez" format using the DeRez command line tool. The rez file can be converted back to a resource file by Xcode as part of a build process.


CategoryTipsAndTricks CategoryMac

HandlingMacResourceFiles (last edited 2021-01-01 20:36:34 by DanVilliomPodlaskiChristiansen)