[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Resource question



>OpenResFile($file);
>$res=Get1Resource("vers",1);
>($a, $b, $c, $d, $e, $f, $g) = unpack("I I I I I2 C256 C256",$res);
>print "$a $b $c $d $e $f $g \n";

There are a couple of problems with this:

- Get1Resource (and the other "get a resource" functions) return a perl
package reference (to a Handle), not the data of the resource itself. You
have to get the data to do anything with it: $res->get

- You have to match the unpack format with the C structure of the version
resource. The version resource is 4 unsigned characters, a short, and two
packed Pascal strings. The unpack above is six 32-bit unsigned integers and
512 unsigned characters (the last 510 of which are thrown away).

Making those changes, the following works for me:

use Mac::Memory;
use Mac::Resources;

$file = 'Macintosh HD:Desktop Folder:Shuck';

$rfd = OpenResFile $file or die;

$res = Get1Resource 'vers', 1 or die;

$data = $res->get;

($a, $b, $c, $d, $e, $f) = unpack 'C C C C n C', $data;
($f, $g) = unpack "x7 A$f x A*", $data;

print "majorRev: $a\n";
print "minorAndBugRev: ", ($b / 16), ", ", ($b % 16), "\n";
print "stage: $c\n";
print "nonRelRev: $d\n";
print "countryCode: $e\n";
print "shortVersion: $f\n";
print "reserved: $g\n";

ReleaseResource $res;
CloseResFile $rfd;

Brian



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch