6 if ($ARGV[0] eq "-v") {
8 $i4jversion = shift @ARGV;
9 die("-v i4jversion must be an integer [probably 7 or 8]") unless $i4jversion =~ m/^\d+$/;
11 # backwards compatibility
12 $i4jversion = "" if $i4jversion < 8;
14 my $fileformats = $ARGV[0];
15 $fileformats = "../../src/jalview/io/FileFormat.java" unless $fileformats;
17 # default mimetype will be text/x-$shortname
18 # TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too
19 # TODO: look up standard mime type used for BLASTfmt matrices, etc
21 rnaml => "application/rnaml+xml",
22 biojson => "application/x-jalview-biojson+json",
23 jnet => "application/x-jalview-jnet+text",
24 features => "application/x-jalview-features+text",
25 scorematrix => "application/x-jalview-scorematrix+text",
26 pdb => "chemical/x-pdb",
27 mmcif => "chemical/x-cif",
28 mmcif2 => "chemical/x-mcif",
29 jalview => "application/x-jalview+xml+zip",
30 jvl => "application/x-jalview-jvl+text",
31 annotations => "application/x-jalview-annotations+text",
34 my @dontaddshortname = qw(features json);
35 my @dontaddextension = qw(html xml json jar mfa fastq);
36 my $add_associations = {
37 biojson => {shortname=>"biojson",name=>"BioJSON",extensions=>["biojson"]},
38 gff2 => {shortname=>"gff2",name=>"Generic Features Format v2",extensions=>["gff2"]},
39 gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]},
40 features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]},
41 annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]},
42 mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]},
43 jvl => {shortname=>"jvl",name=>"Jalview Version Locator",extensions=>["jvl"],iconfile=>"Jalview-Version-Locator"},
44 jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]},
45 scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]},
47 my $add_extensions = {
50 my @put_first = qw(jalview jvl);
52 my $mactemplatefile = "file_associations_template-Info_plist.xml";
53 my $i4jtemplatefile = ($i4jversion >= 8)?"file_associations_template-install4j${i4jversion}.xml";
56 open(MT,"<$mactemplatefile") or dir("Could not open '$mactemplatefile' for reading");
61 open(IT,"<$i4jtemplatefile") or dir("Could not open '$i4jtemplatefile' for reading");
69 my $macautofile = $mactemplatefile;
70 $macautofile =~ s/template/auto$1/;
71 my $i4jautofile = $i4jtemplatefile;
72 $i4jautofile =~ s/template/auto$1/;
74 open(MA,">$macautofile") or die ("Could not open '$macautofile' for writing");
75 print MA "<key>CFBundleDocumentTypes</key>\n<array>\n\n";
76 open(IA,">$i4jautofile") or die ("Could not open '$i4jautofile' for writing");
78 open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading");
80 my $file_associations = {};
81 while(my $line = <IN>) {
83 $line =~ s/(^ | $)//g;
84 if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) {
85 my $shortname = lc($1);
86 next if (grep($_ eq $shortname, @dontaddshortname));
89 $extensions =~ s/\s+//g;
90 my @possextensions = split(m/,/,$extensions);
92 my $addext = $add_extensions->{$shortname};
93 if (ref($addext) eq "ARRAY") {
94 push(@possextensions, @$addext);
96 for my $possext (@possextensions) {
97 next if grep($_ eq $possext, @extensions);
98 next if grep($_ eq $possext, @dontaddextension);
99 push(@extensions,$possext);
101 next unless scalar(@extensions);
102 $file_associations->{$shortname} = {
103 shortname => $shortname,
105 extensions => \@extensions
107 warn("Adding file association for $shortname\n");
112 my %all_associations = (%$file_associations, %$add_associations);
114 for my $shortname (@put_first, sort keys %all_associations) {
115 my $a = $all_associations{$shortname};
116 if (ref($a) ne "HASH") {
120 my $name = $a->{name};
121 my $extensions = $a->{extensions};
122 my $mimetype = $mimetypes->{$shortname};
123 $mimetype = "text/x-$shortname" unless $mimetype;
125 my $iconfile = $a->{iconfile};
126 $iconfile = "Jalview-File" unless $iconfile;
128 my @extensions = @$extensions;
129 #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n");
131 my $macentry = $mactemplate;
132 my $i4jentry = $i4jtemplate;
134 $macentry =~ s/\$\$NAME\$\$/$name/g;
135 $macentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
136 $macentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
137 $macentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
139 $i4jentry =~ s/\$\$NAME\$\$/$name/g;
140 $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
141 $i4jentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
142 $i4jentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
144 while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) {
148 for my $ext (@extensions) {
149 $macextensions .= $pre.$ext.$post;
151 $macentry =~ s/\$\$${pre}EXTENSIONS${post}\$\$/$macextensions/g;
155 for my $ext (@extensions) {
156 my $i4jextentry = $i4jentry;
157 $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g;
158 $i4jextentry =~ s/\$\$ID\$\$/$id/g;
161 print IA $i4jextentry;
164 delete $all_associations{$shortname};
168 print MA "</array>\n";