JAL-3394 Changed most of the token replacement for adding compiler variables
[jalview.git] / utils / install4j / auto_file_associations.pl
index ad08a92..7613778 100755 (executable)
@@ -2,8 +2,17 @@
 
 use strict;
 
+my $i4jversion = 7;
+if ($ARGV[0] eq "-v") {
+  shift @ARGV;
+  $i4jversion = shift @ARGV;
+  die("-v i4jversion must be an integer [probably 7 or 8]") unless $i4jversion =~ m/^\d+$/;
+}
+# backwards compatibility
+$i4jversion = "" if $i4jversion < 8;
+
 my $fileformats = $ARGV[0];
-$fileformats = "../../src/jalview/io/FileFormats.java" unless $fileformats;
+$fileformats = "../../src/jalview/io/FileFormat.java" unless $fileformats;
 
 # default mimetype will be text/x-$shortname
 # TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too
@@ -38,9 +47,10 @@ my $add_associations = {
 my $add_extensions = {
   blc => ["blc"],
 };
+my @put_first = qw(jalview jvl);
 
 my $mactemplatefile = "file_associations_template-Info_plist.xml";
-my $i4jtemplatefile = "file_associations_template-install4j.xml";
+my $i4jtemplatefile = ($i4jversion >= 8)?"file_associations_template-install4j${i4jversion}.xml";
 my $mactemplate;
 my $i4jtemplate;
 open(MT,"<$mactemplatefile") or dir("Could not open '$mactemplatefile' for reading");
@@ -94,15 +104,19 @@ while(my $line = <IN>) {
       name => $name,
       extensions => \@extensions
     };
+    warn("Adding file association for $shortname\n");
   }
 }
 close(IN);
 
 my %all_associations = (%$file_associations, %$add_associations);
 
-for my $fa (sort keys %all_associations) {
-  my $shortname = $fa;
-  my $a = $all_associations{$fa};
+for my $shortname (@put_first, sort keys %all_associations) {
+  my $a = $all_associations{$shortname};
+  if (ref($a) ne "HASH") {
+    next;
+  }
+
   my $name = $a->{name};
   my $extensions = $a->{extensions};
   my $mimetype = $mimetypes->{$shortname};
@@ -146,6 +160,8 @@ for my $fa (sort keys %all_associations) {
 
     print IA $i4jextentry;
   }
+
+  delete $all_associations{$shortname};
 }
 
 close(IA);