X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=utils%2Finstall4j%2Fauto_file_associations-i4j8.pl;h=31a4afad4ececc767476c4ed14d3b40a2bb6a4f2;hb=066e3a364c358a39a66cf292cb98c9b26b289795;hp=9a607c6050c1ef13b617d6d483d6d6d5b880cba5;hpb=8ee4a20c367cb4fcda616611646710593dc98b60;p=jalview.git diff --git a/utils/install4j/auto_file_associations-i4j8.pl b/utils/install4j/auto_file_associations-i4j8.pl index 9a607c6..31a4afa 100755 --- a/utils/install4j/auto_file_associations-i4j8.pl +++ b/utils/install4j/auto_file_associations-i4j8.pl @@ -23,7 +23,7 @@ my $mimetypes = { scorematrix => "application/x-jalview-scorematrix+text", pdb => "chemical/x-pdb", mmcif => "chemical/x-cif", - mmcif2 => "chemical/x-mcif", + mmcif2 => "chemical/x-mmcif", jalview => "application/x-jalview+xml+zip", jvl => "application/x-jalview-jvl+text", annotations => "application/x-jalview-annotations+text", @@ -37,8 +37,9 @@ my $add_associations = { gff3 => {shortname=>"gff3",name=>"Generic Features Format v3",extensions=>["gff3"]}, features => {shortname=>"features",name=>"Jalview Features",extensions=>["features","jvfeatures"]}, annotations => {shortname=>"annotations",name=>"Jalview Annotations",extensions=>["annotations","jvannotations"]}, + mmcif => {shortname=>"mmcif",name=>"CIF",extensions=>["cif"]}, mmcif2 => {shortname=>"mmcif2",name=>"mmCIF",extensions=>["mcif","mmcif"]}, - jvl => {shortname=>"jvl",name=>"Jalview Launch",extensions=>["jvl"],iconfile=>"Jalview-Launch"}, + jvl => {shortname=>"jvl",name=>"Jalview Launch",extensions=>["jvl"],iconfile=>"jvl_file"}, jnet => {shortname=>"jnet",name=>"JnetFile",extensions=>["concise","jnet"]}, scorematrix => {shortname=>"scorematrix",name=>"Substitution Matrix",extensions=>["mat"]}, }; @@ -47,6 +48,8 @@ my $add_extensions = { }; my @put_first = qw(jalview jvl); +my @non_primary = qw(mmcif mmcif2 pdb); + my $v = ($i4jversion >= 8)?$i4jversion:""; my $i4jtemplatefile = "file_associations_template-install4j${v}.xml"; my $i4jtemplate; @@ -72,6 +75,11 @@ $macautofile =~ s/template/auto$1/; my $i4jautofile = $i4jtemplatefile; $i4jautofile =~ s/template/auto$1/; +for my $key (sort keys %$add_associations) { + my $a = $add_associations->{$key}; + warn("Known file association for $a->{shortname} (".join(",",@{$a->{extensions}}).")\n"); +} + open(MA,">$macautofile") or die ("Could not open '$macautofile' for writing"); print MA "CFBundleDocumentTypes\n\n\n"; @@ -106,34 +114,23 @@ while(my $line = ) { name => $name, extensions => \@extensions }; - warn("Adding file association for $shortname\n"); + warn("Reading file association for $shortname (".join(",",@extensions).")\n"); } } close(IN); my %all_associations = (%$file_associations, %$add_associations); -my $num = 0; -my $i4jcount = 0; -my @ordered = @put_first; +my @ordered = (@put_first, @non_primary); for my $key (sort keys %all_associations) { next if grep($_ eq $key, @ordered); push(@ordered, $key); } -for my $key (@ordered) { - my $a = $all_associations{$key}; - next if (ref($a) ne "HASH"); - - my $extensions = $a->{extensions}; - my @extensions = @$extensions; - for my $ext (@extensions) { - $num++; - } - #delete $all_associations{$shortname}; - #print "NUM: $num\n"; -} +my $num = $#ordered + 1; +warn("--\n"); +my $i4jcount = 0; for my $shortname (@ordered) { my $a = $all_associations{$shortname}; next if (ref($a) ne "HASH"); @@ -142,24 +139,31 @@ for my $shortname (@ordered) { my $extensions = $a->{extensions}; my $mimetype = $mimetypes->{$shortname}; $mimetype = "application/x-$shortname+txt" unless $mimetype; - #$mimetype = "application/x-$shortname" unless $mimetype; my $iconfile = $a->{iconfile}; $iconfile = "Jalview-File" unless $iconfile; + my $primary = (! grep($_ eq $shortname, @non_primary)); + my $primarystring = $primary?"true":"false"; + my $role = $primary?"Editor":"Viewer"; + my @extensions = @$extensions; - #warn("LINE: $line\nFound extensions '".join("', '", @extensions)."' for $name Files ($shortname)'n"); my $xname = xml_escape($name); my $xmimetype = xml_escape($mimetype); my $xshortname = xml_escape($shortname); my $xiconfile = xml_escape($iconfile); + my $xrole = xml_escape($role); + my $xROLE = xml_escape(uc($role)); + my $xprimarystring = xml_escape($primarystring); my $macentry = $mactemplate; $macentry =~ s/\$\$NAME\$\$/$xname/g; $macentry =~ s/\$\$SHORTNAME\$\$/$xshortname/g; $macentry =~ s/\$\$MIMETYPE\$\$/$xmimetype/g; $macentry =~ s/\$\$ICONFILE\$\$/$xiconfile/g; + $macentry =~ s/\$\$ROLE\$\$/$xrole/g; + $macentry =~ s/\$\$PRIMARY\$\$/$xprimarystring/g; while ($macentry =~ m/\$\$([^\$]*)EXTENSIONS([^\$]*)\$\$/) { my $pre = $1; my $post = $2; @@ -177,28 +181,32 @@ for my $shortname (@ordered) { $i4jentry =~ s/\$\$SHORTNAME\$\$/$xshortname/g; $i4jentry =~ s/\$\$MIMETYPE\$\$/$xmimetype/g; $i4jentry =~ s/\$\$ICONFILE\$\$/$xiconfile/g; - - for my $ext (@extensions) { - $i4jcount++; - #print "COUNT: $i4jcount\n"; - my $progresspercent = int(($i4jcount/$num)*100); - #print "PC: $progresspercent\n"; - $progresspercent = 100 if $progresspercent > 100; - my $xext = xml_escape($ext); - my $i4jextentry = $i4jentry; - $i4jextentry =~ s/\$\$EXTENSION\$\$/$xext/g; - $i4jextentry =~ s/\$\$PROGRESSPERCENT\$\$/$progresspercent/g; - $i4jextentry =~ s/\$\$ID\$\$/$id/g; - $id++; - $i4jextentry =~ s/\$\$ID1\$\$/$id/g; - $id++; - $i4jextentry =~ s/\$\$ID2\$\$/$id/g; - $id++; - - print IA $i4jextentry; - } + $i4jentry =~ s/\$\$PRIMARY\$\$/$xprimarystring/g; + $i4jentry =~ s/\$\$MACASSOCIATIONROLE\$\$/$xROLE/g; + + my $ext = join(",",sort(@extensions)); + my $xdisplayext = xml_escape(join(", ", map(".$_",sort(@extensions)))); + my $progresspercent = int(($i4jcount/$num)*100); + $progresspercent = 100 if $progresspercent > 100; + $i4jcount++; + my $xext = xml_escape($ext); + my $addunixextension = "true"; + + $i4jentry =~ s/\$\$ADDUNIXEXTENSION\$\$/$addunixextension/g; + $i4jentry =~ s/\$\$EXTENSION\$\$/$xext/g; + $i4jentry =~ s/\$\$DISPLAYEXTENSION\$\$/$xdisplayext/g; + $i4jentry =~ s/\$\$PROGRESSPERCENT\$\$/$progresspercent/g; + $i4jentry =~ s/\$\$ID\$\$/$id/g; + $id++; + $i4jentry =~ s/\$\$ID1\$\$/$id/g; + $id++; + $i4jentry =~ s/\$\$ID2\$\$/$id/g; + $id++; + + print IA $i4jentry; delete $all_associations{$shortname}; + warn("Writing entry for $name (".join(",",@$extensions).": $mimetype)\n"); } close(IA); @@ -208,6 +216,6 @@ close(MA); sub xml_escape { my $x = shift; # stolen from Pod::Simple::XMLOutStream in base distro - $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg; + $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}a-zA-Z0-9])/'&#'.(ord($1)).';'/eg; return $x; }