At 09:32 -0400 2001.04.10, peter furmonavicius wrote:
>Hi.  I have been trying to figure out how to determine the
>application's "version" information from within MacPerl (i.e. the
>info shown in the "Version:" field when you do a 'get info' on an
>application).  Thanks for any advice/help.

This is what I came up with.  Have fun!  Note that you can do this with the
app open, since we open the resource in read-only mode.

#!perl -w
use strict;
use Mac::Memory;
use Mac::MoreFiles;
use Mac::Resources;

my $app = "…uck";
my $path = $Application{$app};

# "1" means "read-only" so you can open when app is open
my $res  = FSpOpenResFile($path, 1) or die $^E;

# version resource should be ID 1, I think
my $vers = Get1Resource('vers', 1) or exit;
my $data = $vers->get;
CloseResFile(CurResFile());

my @data = split //, $data;
my %r = (
    32  => 'd',
    64  => 'a',
    96  => 'b',
    128 => 'f',
);
my $r = $r{ ord $data[2] };

my $off1 = 7;  # skip numeric version stuff
my $len1 = ord(substr($data, $off1-1, 1));
my $off2 = $off1 + $len1 + 1;
my $len2 = ord(substr($data, $off2-1, 1));

# numeric version
my @num = split //, sprintf "%x", ord $data[1];
printf "%x.%d", ord $data[0], $num[0];
printf ".%d", $num[1] if $num[1];
printf "$r%x", ord $data[3] if $r ne 'f';
printf "\n";

# short version
print substr($data, $off1, $len1), "\n";

# long version
print substr($data, $off2, $len2), "\n";

__END__

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to