Change 17662: Make Mac::Glue work to glue Mac OS X apps under Classic
[email protected] (Chris Nandor) Mon, 29 Jul 2002 15:55:41 -0400
| Newsgroups | perl.perl5.changes.mac |
|---|---|
| Message-ID | <p05111b10b96b4e232e8b@[10.0.1.177]> |
Change 17662 by pudge@pudge-mobile on 2002/07/29 18:21:16
Make Mac::Glue work to glue Mac OS X apps under Classic
Affected files ...
.... //depot/maint-5.6/macperl/macos/lib/Mac/AETE/App.pm#2 edit
.... //depot/maint-5.6/macperl/macos/lib/Mac/AETE/Format/Glue.pm#2 edit
Differences ...
==== //depot/maint-5.6/macperl/macos/lib/Mac/AETE/App.pm#2 (text) ====
Index: macperl/macos/lib/Mac/AETE/App.pm
--- macperl/macos/lib/Mac/AETE/App.pm#1~12326~ Wed Oct 3 12:08:28 2001
+++ macperl/macos/lib/Mac/AETE/App.pm Mon Jul 29 11:21:16 2002
@@ -111,13 +111,15 @@
use strict;
+use File::Basename;
+use File::Spec::Functions qw(catfile);
use Mac::AETE::Parser;
use Mac::AppleEvents;
use Mac::Files;
use Mac::Memory;
use Mac::Processes;
use Mac::Resources;
-use File::Basename;
+use Symbol;
use Carp;
@@ -128,13 +130,14 @@
my $self = {};
my $aete_handle;
- my($name, $running) = &get_app_status_and_launch($target);
+ my($name, $running, $sign) = &get_app_status_and_launch($target);
return unless $name;
$self->{_target} = $name;
+ $self->{ID} = $sign;
if ($running) {
- unless ($aete_handle = get_aete_via_event($target)) {
+ unless ($aete_handle = get_aete_via_event($target, $sign)) {
carp("The application is not scriptable");
return;
}
@@ -164,53 +167,81 @@
{
my ($app_path) = @_;
my ($name, $path, $suffix, $running, $ok_to_launch, $pname, $launch);
- my ($psn, $psi);
-
+ my ($psn, $psi, $sign);
+
$running = 0;
- fileparse_set_fstype("MacOS");
- ($name,$path,$suffix) = fileparse($app_path, "");
- for $psn (keys %Process) {
- $pname = $Process{$psn}->processName;
-# print "$pname", " $name\n";
- $running = 1, last if $pname eq $name;
+
+ # test for package, works under Mac OS X/Classic too
+ my $pkginfo = catfile($app_path, 'Contents', 'PkgInfo');
+ if (-d $app_path && -f $pkginfo) {
+ my $fh = gensym();
+ open $fh, "<" . $pkginfo or croak "Can't open $pkginfo: $!";
+ (my($type), $sign) = (<$fh> =~ /^(.{4})(.{4})$/);
+ for $psn (keys %Process) {
+ $pname = $Process{$psn}->processName;
+ $running = 1, $name = $pname, last
+ if $sign eq $Process{$psn}->processSignature;
+ }
+ $ok_to_launch = !$running;
+
+ } else {
+ fileparse_set_fstype("MacOS");
+ ($name,$path,$suffix) = fileparse($app_path, "");
+ for $psn (keys %Process) {
+ $pname = $Process{$psn}->processName;
+# print "$pname", " $name\n";
+ $running = 1, last if $pname eq $name;
+ }
}
+
if (!$running) {
- my $RF = OpenResFile($app_path);
- if (!defined($RF) || $RF == 0) {
- carp("No Resource Fork available for '$app_path': $^E");
- return;
+ unless (-d $app_path && -f $pkginfo) {
+ my $RF = OpenResFile($app_path);
+ if (!defined($RF) || $RF == 0) {
+ carp("No Resource Fork available for '$app_path': $^E");
+ return;
+ }
+ my $check_resource = Get1Resource('scsz', 0);
+ if (!defined($check_resource) || $check_resource == 0) {
+ $check_resource = Get1Resource('scsz', 128);
+ }
+ $ok_to_launch = defined($check_resource) && $check_resource;
+ CloseResFile($RF); # don't do anything with the resource now!
}
- my $check_resource = Get1Resource('scsz', 0);
- if (!defined($check_resource) || $check_resource == 0) {
- $check_resource = Get1Resource('scsz', 128);
- }
- $ok_to_launch = defined($check_resource) && $check_resource;
- CloseResFile($RF); # don't do anything with the resource now!
- if ($ok_to_launch) {
+ if ($ok_to_launch) {
$launch = new LaunchParam(
launchControlFlags => eval(launchContinue + launchNoFileFlags + launchDontSwitch),
launchAppSpec => $app_path
);
LaunchApplication $launch;
$running = 1;
+ sleep 10;
}
}
-
+
while (($psn, $psi) = each(%Process)) {
- $pname = $psi->processName;
- $running = 1, last if $pname eq $name;
+ if (defined $sign) {
+ $running = 1, $name = $psi->processName,
+ last if $sign eq $psi->processSignature;
+ } else {
+ $running = 1, $sign = $psi->processSignature,
+ last if $name eq $psi->processName;
+ }
}
$name = $app_path if $name !~ /:/;
- ($name, $running);
+ ($name, $running, $sign);
}
sub get_aete_via_event
{
- my($target) = @_;
- my $info = FSpGetFInfo($target);
-
- my $addr_desc = AECreateDesc(typeApplSignature, $info->fdCreator);
- my $event = AEBuildAppleEvent('ascr', 'gdte', 'sign', $info->fdCreator, 0, 0, , "'----':0");
+ my($target, $sign) = @_;
+ if (!$sign) {
+ my $info = FSpGetFInfo($target);
+ $sign = $info->fdCreator;
+ }
+
+ my $addr_desc = AECreateDesc(typeApplSignature, $sign);
+ my $event = AEBuildAppleEvent('ascr', 'gdte', 'sign', $sign, 0, 0, , "'----':0");
my $reply = AESend($event, kAEWaitReply);
my @handles;
if ($reply) {
==== //depot/maint-5.6/macperl/macos/lib/Mac/AETE/Format/Glue.pm#2 (text) ====
Index: macperl/macos/lib/Mac/AETE/Format/Glue.pm
--- macperl/macos/lib/Mac/AETE/Format/Glue.pm#1~12326~ Wed Oct 3 12:08:28 2001
+++ macperl/macos/lib/Mac/AETE/Format/Glue.pm Mon Jul 29 11:21:16 2002
@@ -1,11 +1,14 @@
package Mac::AETE::Format::Glue;
+use Carp;
use Data::Dumper;
use Fcntl;
use File::Basename;
use File::Path;
+use File::Spec::Functions qw(catfile);
use Mac::AETE::Parser;
use Mac::Glue;
use MLDBM ('DB_File', $Mac::Glue::SERIALIZER);
+use Symbol;
use strict;
use vars qw(@ISA $VERSION $TYPE);
@@ -205,7 +208,19 @@
sub write_title {
my($self, $title) = @_;
- $self->{ID} = (MacPerl::GetFileInfo($title))[0];
+
+ my $pkginfo = catfile($title, 'Contents', 'PkgInfo');
+ if (-d $title && -f $pkginfo) {
+ my $fh = gensym();
+ open $fh, "<" . $pkginfo or croak "Can't open $pkginfo: $!";
+ my($type, $sign) = (<$fh> =~ /^(.{4})(.{4})$/);
+ $self->{ID} = $sign;
+ } else {
+ $self->{ID} = (MacPerl::GetFileInfo($title))[0];
+ }
+ croak("Can't get application signature for $title")
+ if !$self->{ID};
+
$self->{TITLE} = basename($self->{OUTPUT});
}
End of Patch.
--
Chris Nandor [email protected] http://pudge.net/
Open Source Development Network [email protected] http://osdn.com/