5 my $fileformats = $ARGV[0];
6 $fileformats = "../../src/jalview/io/FileFormat.java" unless $fileformats;
8 # default mimetype will be text/x-$shortname
9 # TODO: find an actual extension for mat, see JAL-Xxxxx for outstanding issues too
10 # TODO: look up standard mime type used for BLASTfmt matrices, etc
12 rnaml => "application/rnaml+xml",
13 biojson => "application/x-jalview-biojson+json",
14 jnet => "application/x-jalview-jnet+text",
15 features => "application/x-jalview-features+text",
16 scorematrix => "application/x-jalview-scorematrix+text",
17 pdb => "chemical/x-pdb",
18 mmcif => "chemical/x-cif",
19 mmcif2 => "chemical/x-mcif",
20 jalview => "application/x-jalview+xml+zip",
21 jvl => "application/x-jalview-jvl+text",
22 annotations => "application/x-jalview-annotations+text",
25 my @dontaddshortname = qw(features json);
26 my @dontaddextension = qw(html xml json jar mfa fastq);
27 my $add_associations = {
28 biojson => {shortname=>"biojson",name=>"BioJSON",extensions=>["biojson"]},
29 gff2 => {shortname=>"gff2",name=>"Generic Features Format v2",extensions=>["gff2"]},
30 gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]},
31 features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]},
32 annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]},
33 mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]},
34 jvl => {shortname=>"jvl",name=>"Jalview Version Locator",extensions=>["jvl"],iconfile=>"Jalview-Version-Locator"},
35 jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]},
36 scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]},
38 my $add_extensions = {
41 my @put_first = qw(jalview jvl);
43 my $mactemplatefile = "file_associations_template-Info_plist.xml";
44 my $i4jtemplatefile = "file_associations_template-install4j.xml";
47 open(MT,"<$mactemplatefile") or dir("Could not open '$mactemplatefile' for reading");
52 open(IT,"<$i4jtemplatefile") or dir("Could not open '$i4jtemplatefile' for reading");
60 my $macautofile = $mactemplatefile;
61 $macautofile =~ s/template/auto$1/;
62 my $i4jautofile = $i4jtemplatefile;
63 $i4jautofile =~ s/template/auto$1/;
65 open(MA,">$macautofile") or die ("Could not open '$macautofile' for writing");
66 print MA "<key>CFBundleDocumentTypes</key>\n<array>\n\n";
67 open(IA,">$i4jautofile") or die ("Could not open '$i4jautofile' for writing");
69 open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading");
71 my $file_associations = {};
72 while(my $line = <IN>) {
74 $line =~ s/(^ | $)//g;
75 if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) {
76 my $shortname = lc($1);
77 next if (grep($_ eq $shortname, @dontaddshortname));
80 $extensions =~ s/\s+//g;
81 my @possextensions = split(m/,/,$extensions);
83 my $addext = $add_extensions->{$shortname};
84 if (ref($addext) eq "ARRAY") {
85 push(@possextensions, @$addext);
87 for my $possext (@possextensions) {
88 next if grep($_ eq $possext, @extensions);
89 next if grep($_ eq $possext, @dontaddextension);
90 push(@extensions,$possext);
92 next unless scalar(@extensions);
93 $file_associations->{$shortname} = {
94 shortname => $shortname,
96 extensions => \@extensions
98 warn("Adding file association for $shortname\n");
103 my %all_associations = (%$file_associations, %$add_associations);
105 for my $shortname (@put_first, sort keys %all_associations) {
106 my $a = $all_associations{$shortname};
107 if (ref($a) ne "HASH") {
111 my $name = $a->{name};
112 my $extensions = $a->{extensions};
113 my $mimetype = $mimetypes->{$shortname};
114 $mimetype = "text/x-$shortname" unless $mimetype;
116 my $iconfile = $a->{iconfile};
117 $iconfile = "Jalview-File" unless $iconfile;
119 my @extensions = @$extensions;
120 #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n");
122 my $macentry = $mactemplate;
123 my $i4jentry = $i4jtemplate;
125 $macentry =~ s/\$\$NAME\$\$/$name/g;
126 $macentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
127 $macentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
128 $macentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
130 $i4jentry =~ s/\$\$NAME\$\$/$name/g;
131 $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
132 $i4jentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
133 $i4jentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
135 while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) {
139 for my $ext (@extensions) {
140 $macextensions .= $pre.$ext.$post;
142 $macentry =~ s/\$\$${pre}EXTENSIONS${post}\$\$/$macextensions/g;
146 for my $ext (@extensions) {
147 my $i4jextentry = $i4jentry;
148 $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g;
149 $i4jextentry =~ s/\$\$ID\$\$/$id/g;
152 print IA $i4jextentry;
155 delete $all_associations{$shortname};
159 print MA "</array>\n";