Permalink
Browse files

Start of iphone profile builder for windows

  • Loading branch information...
1 parent 8f3c7d0 commit ed9606655de88fbfad97c67c9eac9dbf04bb0686 @marcusramberg committed May 15, 2009
Showing with 64 additions and 0 deletions.
  1. +64 −0 imakeprofile-iphone-win/iusethis Profile Maker.pl
View
64 imakeprofile-iphone-win/iusethis Profile Maker.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use XML::TreePP;
+use MIME::Base64;
+use Data::Plist::BinaryReader;
+my $reader=Data::Plist::BinaryReader->new();
+my $backupdir=$ENV{HOME}."/Library/Application Support/MobileSync/Backup/";
+opendir(DIR,$backupdir)|| terminate( "Could not open Backup dir: ".$@);
+my $ts=0;
+my $newest;
+foreach (readdir(DIR)) {
+ next if m/^\./;
+ if((stat($backupdir.$_))[9]>$ts) {
+ $newest=$_;
+ $ts=(stat($backupdir.$_))[9];
+ }
+}
+terminate( "Could not find any backups in ~/Library/Application Support/MobileSync")
+ unless $newest;
+
+use XML::TreePP;
+my $tpp = XML::TreePP->new();
+my $doc=$tpp->parsefile($backupdir.$newest.'/Manifest.plist');
+my $blob=$doc->{plist}->{dict}->{data}->[2] || die('Could not parse manifest. Invalid XML data?');
+my $plist_data=$reader->open_string(decode_base64($blob))->data;
+
+my @apps;
+foreach my $app (keys %{$plist_data->{Applications}}) {
+ push @apps, make_short( $plist_data->{Applications}->{$app}->{AppInfo}->{CFBundleDisplayName}||
+ $plist_data->{Applications}->{$app}->{AppInfo}->{CFBundleExecutable});
+}
+my $data='-F apps='.join(' -F apps=',@apps);
+my $res=`curl -s -H \"Expect:\" $data http://iphone.iusethis.com/profile/send`;
+
+if ($res =~ m/^\d+$/) {
+ system('open','http://iphone.iusethis.com/profile/view/'.$res.'?match=1');
+ terminate("Profile uploaded. Please check your browser");
+} else
+{
+ terminate('Unable to send profile to server '.$res);
+}
+
+sub terminate {
+ my $message=shift;
+# osascript -l AppleScript -e 'tell Application "Finder" to display alert "Call Frank" '
+ system('osascript -l AppleScript -e \'tell Application "Finder" to display alert "'.$message.'" \'');
+ exit
+}
+
+sub make_short {
+ my ($name)=@_;
+ $name =~ s/[^\w\@\-]//g;
+ return lc $name;
+}
+
+sub simple_escape {
+ my $text=shift;
+ #FIXME: this sucks
+ $text =~ s/\&/\&/g;
+ $text =~ s/\s/\%20/g;
+ return $text;
+}

0 comments on commit ed96066

Please sign in to comment.