X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2Fupdate-info-plist.pl;h=172996bd96d855f533a8000c3e251b174c863076;hb=d1ae2829ff0fd2a96c16a0c8c5420efaa47d7b30;hp=14b1494a14e350ea17ac267e4bc716130032b464;hpb=c141c2b05e374757b6499d12bb8a6d4d943b1529;p=xscreensaver diff --git a/OSX/update-info-plist.pl b/OSX/update-info-plist.pl index 14b1494a..172996bd 100755 --- a/OSX/update-info-plist.pl +++ b/OSX/update-info-plist.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2006-2012 Jamie Zawinski +# Copyright © 2006-2014 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -21,16 +21,51 @@ require 5; #use diagnostics; # Fails on some MacOS 10.5 systems use strict; +use IPC::Open3; +use IO::Uncompress::Gunzip qw(gunzip $GunzipError); +use IO::Compress::Gzip qw(gzip $GzipError); -my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.22 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my ($exec_dir, $progname) = ($0 =~ m@^(.*?)/([^/]+)$@); + +my ($version) = ('$Revision: 1.38 $' =~ m/\s(\d[.\d]+)\s/s); $ENV{PATH} = "/usr/local/bin:$ENV{PATH}"; # for seticon +my $thumbdir = $ENV{HOME} . '/www/xscreensaver/screenshots/'; + + my $verbose = 1; -sub read_info_plist($); +sub convert_plist($$) { + my ($data, $to_binary_p) = @_; + my $is_binary_p = ($data =~ m/^bplist/s); + if ($data && (!$is_binary_p) != (!$to_binary_p)) { + print STDERR "$progname: converting plist\n" if ($verbose > 2); + my $which = ($to_binary_p ? 'binary1' : 'xml1'); + my @cmd = ('plutil', '-convert', $which, '-s', '-o', '-', '-'); + my $pid = open3 (my $in, my $out, undef, @cmd) || + error ("pipe: $cmd[0]: $!"); + error ("$cmd[0]: $!") unless $pid; + print $in $data; + close $in; + local $/ = undef; # read entire file + $data = <$out>; + close $out; + waitpid ($pid, 0); + if ($?) { + my $exit_value = $? >> 8; + my $signal_num = $? & 127; + my $dumped_core = $? & 128; + error ("$cmd[0]: core dumped!") if ($dumped_core); + error ("$cmd[0]: signal $signal_num!") if ($signal_num); + error ("$cmd[0]: exited with $exit_value!") if ($exit_value); + } + } + return $data; +} + + sub read_info_plist($) { my ($app_dir) = @_; my $file = "$app_dir/Contents/Info.plist"; @@ -43,16 +78,12 @@ sub read_info_plist($) { } else { error ("$file: $!"); } + print STDERR "$progname: read $file\n" if ($verbose > 2); local $/ = undef; # read entire file my $body = <$in>; close $in; - if ($body =~ m/^bplist/s) { - print STDERR "$progname: converting binary plist file: $file\n"; - system ("plutil", "-convert", "xml1", $file); - return read_info_plist ($app_dir); - } - + $body = convert_plist ($body, 0); # convert to xml plist return ($file, $body); } @@ -65,6 +96,7 @@ sub read_saver_xml($) { return () if ($name eq 'XScreenSaver'); return () if ($name eq 'SaverTester'); + return () if ($name eq 'XScreenSaverUpdater'); my $file = "$app_dir/Contents/Resources/" . lc($name) . ".xml"; my $file2 = "$app_dir/" . lc($name) . ".xml"; @@ -78,16 +110,22 @@ sub read_saver_xml($) { } else { error ("$file: $!"); } + print STDERR "$progname: read $file\n" if ($verbose > 2); local $/ = undef; # read entire file my $body = <$in>; close $in; - return ($file, $body); + + # Uncompress the XML if it is compressed. + my $body2 = ''; + gunzip (\$body, \$body2) || error ("$app_dir: xml gunzip: $GunzipError"); + my $was_compressed_p = ($body ne $body2); + return ($file, $body2, $was_compressed_p); } sub update_saver_xml($$) { my ($app_dir, $vers) = @_; - my ($filename, $body) = read_saver_xml ($app_dir); + my ($filename, $body, $was_compressed_p) = read_saver_xml ($app_dir); my $obody = $body; return () unless defined ($filename); @@ -111,8 +149,13 @@ sub update_saver_xml($$) { s/\nCopyright [^ \r\n\t]+ (\d{4})(-\d{4})? (.*)\.$/\nWritten $3; $1./s; $desc =~ s/^\n+//s; - error ("$filename: description contains bad characters") - if ($desc =~ m/([^\t\n -~]|[<>])/); + error ("$filename: description contains markup: $1") + if ($desc =~ m/([<>&][^<>&\s]*)/s); + error ("$filename: description contains ctl chars: $1") + if ($desc =~ m/([\000-\010\013-\037])/s); + error ("$filename: description contains non-ASCII and is not UTF-8: $1") + if ($body !~ m/\Q)(.*?)()@$1$desc1$3@s; - if ($obody eq $body) { + # NSXMLParser doesn't seem to work properly on Latin1 XML documents, + # so we convert these to UTF8 when embedding them in the .saver bundle. + $body =~ s@encoding="ISO-8859-1"@encoding="UTF-8"@gsi; + + if ($obody eq $body && $was_compressed_p) { print STDERR "$progname: $filename: unchanged\n" if ($verbose > 1); } else { + + # Gzip the XML. + my $body2 = ''; + gzip (\$body, \$body2) || error ("$app_dir: xml gzip: $GzipError"); + $body = $body2; + my $file_tmp = "$filename.tmp"; - open (my $out, '>', $file_tmp) || error ("$file_tmp: $!"); + open (my $out, '>:raw', $file_tmp) || error ("$file_tmp: $!"); print $out $body || error ("$file_tmp: $!"); close $out || error ("$file_tmp: $!"); @@ -190,6 +243,40 @@ sub update_saver_xml($$) { } +sub compress_all_xml_files($) { + my ($dir) = @_; + opendir (my $dirp, $dir) || error ("$dir: $!"); + my @files = readdir ($dirp); + closedir $dirp; + foreach my $f (sort @files) { + next unless ($f =~ m/\.xml$/si); + my $filename = "$dir/$f"; + open (my $in, '<', $filename) || error ("$filename: $!"); + print STDERR "$progname: read $filename\n" if ($verbose > 2); + local $/ = undef; # read entire file + my $body = <$in>; + close $in; + + if ($body =~ m/^<\?xml/s) { + my $body2 = ''; + gzip (\$body, \$body2) || error ("$filename: xml gzip: $GzipError"); + $body = $body2; + my $file_tmp = "$filename.tmp"; + open (my $out, '>:raw', $file_tmp) || error ("$file_tmp: $!"); + print $out $body || error ("$file_tmp: $!"); + close $out || error ("$file_tmp: $!"); + + if (!rename ("$file_tmp", "$filename")) { + unlink "$file_tmp"; + error ("mv \"$file_tmp\" \"$filename\": $!"); + } + print STDERR "$progname: compressed $filename\n" if ($verbose); + } elsif ($verbose > 2) { + print STDERR "$filename: already compressed\n"; + } + } +} + sub set_plist_key($$$$) { my ($filename, $body, $key, $val) = @_; @@ -228,6 +315,68 @@ sub set_icon($) { } +sub set_thumb($) { + my ($app_dir) = @_; + + return unless ($app_dir =~ m@\.saver/?$@s); + + my @cmd = ("$exec_dir/update-thumbnail.pl", $thumbdir, $app_dir); + push @cmd, "-" . ("v" x $verbose) if ($verbose); + print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" + if ($verbose > 1); + system (@cmd); + my $exit = $? >> 8; + exit ($exit) if $exit; +} + + +sub enable_gc($) { + my ($app_dir) = @_; + + return unless ($app_dir =~ m@\.saver/?$@s); + my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.saver$@s); + error ("unparsable: $app_dir") unless $name; + my $exe = "$app_dir/Contents/MacOS/$name"; + my @cmd = ("$dir/enable_gc", $exe); + print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" + if ($verbose > 1); + system (@cmd); + my $exit = $? >> 8; + exit ($exit) if $exit; +} + + +sub fix_coretext($) { + my ($app_dir) = @_; + + # In MacOS 10.8, they moved CoreText.framework from + # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ + # to /System/Library/Frameworks/ which means that executables compiled + # on 10.8 and newer won't run on 10.7 and older because they can't find + # the library. Fortunately, 10.8 and later leave a symlink behind, so + # the old location still works. So we need our executables to contain + # an LC_LOAD_DYLIB pointing at the old directory instead of the new + # one. + # + return if ($app_dir =~ m@-iphone@s); + my ($dir, $name) = ($app_dir =~ m@^(.*)/([^/]+)\.(app|saver)$@s); + error ("unparsable: $app_dir") unless $name; + my $exe = "$app_dir/Contents/MacOS/$name"; + + my $new = ("/System/Library/Frameworks/CoreText.framework/" . + "Versions/A/CoreText"); + my $old = ("/System/Library/Frameworks/ApplicationServices.framework/" . + "Frameworks/CoreText.framework/Versions/A/CoreText"); + my @cmd = ("install_name_tool", "-change", $new, $old, $exe); + + print STDERR "$progname: exec: " . join(' ', @cmd) . "\n" + if ($verbose > 1); + system (@cmd); + my $exit = $? >> 8; + exit ($exit) if $exit; +} + + sub update($) { my ($app_dir) = @_; @@ -244,7 +393,12 @@ sub update($) { my $vers = $1; my ($ignore, $info_str) = update_saver_xml ($app_dir, $vers); - if (! defined($info_str)) { + # No, don't do this -- the iOS version reads the XML file in a few + # different places, and most of those places don't understand gzip. + + if ($app_name eq 'XScreenSaver') { + compress_all_xml_files ($app_dir); + } elsif (! defined($info_str)) { print STDERR "$progname: $filename: no XML file\n" if ($verbose > 1); } else { @@ -268,8 +422,9 @@ sub update($) { if ($oplist eq $plist) { print STDERR "$progname: $filename: unchanged\n" if ($verbose > 1); } else { + $plist = convert_plist ($plist, 1); # convert to binary plist my $file_tmp = "$filename.tmp"; - open (my $out, '>', $file_tmp) || error ("$file_tmp: $!"); + open (my $out, '>:raw', $file_tmp) || error ("$file_tmp: $!"); print $out $plist || error ("$file_tmp: $!"); close $out || error ("$file_tmp: $!"); @@ -282,6 +437,9 @@ sub update($) { } set_icon ($app_dir); + set_thumb ($app_dir); +# enable_gc ($app_dir); + fix_coretext ($app_dir) }