5 my $fileformats = $ARGV[0];
6 $fileformats = "../../src/jalview/io/FileFormats.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 = {
42 my $mactemplatefile = "file_associations_template-Info_plist.xml";
43 my $i4jtemplatefile = "file_associations_template-install4j.xml";
46 open(MT,"<$mactemplatefile") or dir("Could not open '$mactemplatefile' for reading");
51 open(IT,"<$i4jtemplatefile") or dir("Could not open '$i4jtemplatefile' for reading");
59 my $macautofile = $mactemplatefile;
60 $macautofile =~ s/template/auto$1/;
61 my $i4jautofile = $i4jtemplatefile;
62 $i4jautofile =~ s/template/auto$1/;
64 open(MA,">$macautofile") or die ("Could not open '$macautofile' for writing");
65 print MA "<key>CFBundleDocumentTypes</key>\n<array>\n\n";
66 open(IA,">$i4jautofile") or die ("Could not open '$i4jautofile' for writing");
68 open(IN, "<$fileformats") or die ("Could not open '$fileformats' for reading");
70 my $file_associations = {};
71 while(my $line = <IN>) {
73 $line =~ s/(^ | $)//g;
74 if ($line =~ m/^(\w+) ?\( ?"([^"]*)" ?, ?"([^"]*)" ?, ?(true|false) ?, ?(true|false) ?\)$/i) {
75 my $shortname = lc($1);
76 next if (grep($_ eq $shortname, @dontaddshortname));
79 $extensions =~ s/\s+//g;
80 my @possextensions = split(m/,/,$extensions);
82 my $addext = $add_extensions->{$shortname};
83 if (ref($addext) eq "ARRAY") {
84 push(@possextensions, @$addext);
86 for my $possext (@possextensions) {
87 next if grep($_ eq $possext, @extensions);
88 next if grep($_ eq $possext, @dontaddextension);
89 push(@extensions,$possext);
91 next unless scalar(@extensions);
92 $file_associations->{$shortname} = {
93 shortname => $shortname,
95 extensions => \@extensions
101 my %all_associations = (%$file_associations, %$add_associations);
103 for my $fa (sort keys %all_associations) {
105 my $a = $all_associations{$fa};
106 my $name = $a->{name};
107 my $extensions = $a->{extensions};
108 my $mimetype = $mimetypes->{$shortname};
109 $mimetype = "text/x-$shortname" unless $mimetype;
111 my $iconfile = $a->{iconfile};
112 $iconfile = "Jalview-File" unless $iconfile;
114 my @extensions = @$extensions;
115 #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n");
117 my $macentry = $mactemplate;
118 my $i4jentry = $i4jtemplate;
120 $macentry =~ s/\$\$NAME\$\$/$name/g;
121 $macentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
122 $macentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
123 $macentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
125 $i4jentry =~ s/\$\$NAME\$\$/$name/g;
126 $i4jentry =~ s/\$\$SHORTNAME\$\$/$shortname/g;
127 $i4jentry =~ s/\$\$MIMETYPE\$\$/$mimetype/g;
128 $i4jentry =~ s/\$\$ICONFILE\$\$/$iconfile/g;
130 while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) {
134 for my $ext (@extensions) {
135 $macextensions .= $pre.$ext.$post;
137 $macentry =~ s/\$\$${pre}EXTENSIONS${post}\$\$/$macextensions/g;
141 for my $ext (@extensions) {
142 my $i4jextentry = $i4jentry;
143 $i4jextentry =~ s/\$\$EXTENSION\$\$/$ext/g;
144 $i4jextentry =~ s/\$\$ID\$\$/$id/g;
147 print IA $i4jextentry;
152 print MA "</array>\n";