[2808] | 1 | #! /usr/bin/perl -w
|
---|
| 2 | # short tool to find out all used icons and allows deleting unused icons
|
---|
| 3 | # when building release files
|
---|
| 4 |
|
---|
| 5 | my @default = (
|
---|
| 6 | "styles/standard/*.xml",
|
---|
[4172] | 7 | "styles/standard/*.mapcss",
|
---|
[2967] | 8 | "data/*.xml",
|
---|
[2808] | 9 | "src/org/openstreetmap/josm/*.java",
|
---|
| 10 | "src/org/openstreetmap/josm/*/*.java",
|
---|
| 11 | "src/org/openstreetmap/josm/*/*/*.java",
|
---|
| 12 | "src/org/openstreetmap/josm/*/*/*/*.java",
|
---|
| 13 | "src/org/openstreetmap/josm/*/*/*/*/*.java",
|
---|
| 14 | "src/org/openstreetmap/josm/*/*/*/*/*/*.java"
|
---|
| 15 | );
|
---|
| 16 |
|
---|
| 17 | my %icons;
|
---|
| 18 |
|
---|
| 19 | my $o = $/;
|
---|
| 20 |
|
---|
| 21 | for my $arg (@ARGV ? @ARGV : @default)
|
---|
| 22 | {
|
---|
| 23 | for my $file (glob($arg))
|
---|
| 24 | {
|
---|
| 25 | open(FILE,"<",$file) or die "Could not open $file\n";
|
---|
| 26 | #print "Read file $file\n";
|
---|
| 27 | $/ = $file =~ /\.java$/ ? ";" : $o;
|
---|
| 28 | my $extends = "";
|
---|
| 29 | while(my $l = <FILE>)
|
---|
| 30 | {
|
---|
[7668] | 31 | next if $l =~ /NO-ICON/;
|
---|
[7669] | 32 | if($l =~ /icon\s*[:=]\s*["']([^+]+?)["']/)
|
---|
[2808] | 33 | {
|
---|
| 34 | ++$icons{$1};
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[7670] | 37 | if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
|
---|
[4172] | 38 | {
|
---|
[7670] | 39 | my $val = $2;
|
---|
| 40 | my $img = "styles/standard/$val";
|
---|
| 41 | $img = "styles/$val" if((!-f "images/$img") && -f "images/styles/$val");
|
---|
| 42 | $img = $val if((!-f "images/$img") && -f "images/$val");
|
---|
[4172] | 43 | ++$icons{$img};
|
---|
| 44 | }
|
---|
[2808] | 45 | if($l =~ /ImageProvider\.get\(\"([^\"]*?)\"\)/)
|
---|
| 46 | {
|
---|
| 47 | my $i = $1;
|
---|
| 48 | ++$icons{$i};
|
---|
| 49 | }
|
---|
[4172] | 50 | while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
|
---|
| 51 | {
|
---|
| 52 | my $i = $1;
|
---|
| 53 | ++$icons{$i};
|
---|
| 54 | }
|
---|
| 55 | while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
|
---|
| 56 | {
|
---|
| 57 | my $i = "$1$2";
|
---|
| 58 | ++$icons{$i};
|
---|
| 59 | }
|
---|
[2808] | 60 | if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
|
---|
| 61 | {
|
---|
| 62 | my $i = "statusline/$1";
|
---|
| 63 | ++$icons{$i};
|
---|
| 64 | }
|
---|
| 65 | if($l =~ /createPreferenceTab\(\"(.*?)\"/)
|
---|
| 66 | {
|
---|
| 67 | my $i = "preferences/$1";
|
---|
| 68 | ++$icons{$i};
|
---|
| 69 | }
|
---|
[2811] | 70 | if($l =~ /ImageProvider\.get\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
|
---|
[2808] | 71 | {
|
---|
| 72 | my $i = "$1/$2";
|
---|
| 73 | ++$icons{$i};
|
---|
| 74 | }
|
---|
[2811] | 75 | if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
|
---|
[2808] | 76 | {
|
---|
[2811] | 77 | my $i = $1;
|
---|
| 78 | ++$icons{$i};
|
---|
| 79 | }
|
---|
| 80 | if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
|
---|
| 81 | {
|
---|
[2808] | 82 | my $i = "cursor/modifier/$2";
|
---|
| 83 | ++$icons{$i};
|
---|
| 84 | $i = "cursor/$1";
|
---|
| 85 | ++$icons{$i};
|
---|
| 86 | }
|
---|
[2811] | 87 | if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
|
---|
| 88 | {
|
---|
| 89 | my $i = "cursor/$1";
|
---|
| 90 | ++$icons{$i};
|
---|
| 91 | }
|
---|
[4172] | 92 | if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
|
---|
| 93 | {
|
---|
| 94 | my $i = "dialogs/$1";
|
---|
| 95 | ++$icons{$i};
|
---|
| 96 | }
|
---|
[2808] | 97 | if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
|
---|
| 98 | {
|
---|
| 99 | my $i = "$extends$1";
|
---|
| 100 | ++$icons{$i};
|
---|
| 101 | }
|
---|
[2981] | 102 | if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
|
---|
| 103 | {
|
---|
| 104 | my $i = "$extends$1";
|
---|
| 105 | ++$icons{$i};
|
---|
| 106 | }
|
---|
[2811] | 107 | if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
|
---|
| 108 | {
|
---|
| 109 | my $i = "markers/$1";
|
---|
| 110 | ++$icons{$i};
|
---|
| 111 | }
|
---|
| 112 | if($l =~ /\"(.*?)\",\s*parentLayer/s)
|
---|
| 113 | {
|
---|
| 114 | my $i = "markers/$1";
|
---|
| 115 | ++$icons{$i};
|
---|
| 116 | }
|
---|
[2808] | 117 | if($l =~ /\.setButtonIcons.*\{(.*)\}/)
|
---|
| 118 | {
|
---|
| 119 | my $t = $1;
|
---|
| 120 | while($t =~ /\"(.*?)\"/g)
|
---|
| 121 | {
|
---|
| 122 | my $i = $1;
|
---|
| 123 | ++$icons{$i};
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | if($l =~ /extends MapMode/)
|
---|
| 127 | {
|
---|
| 128 | $extends = "mapmode/";
|
---|
| 129 | }
|
---|
[7668] | 130 | elsif($l =~ /extends ToggleDialog/)
|
---|
[2808] | 131 | {
|
---|
| 132 | $extends = "dialogs/";
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | close FILE;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | my %haveicons;
|
---|
| 140 |
|
---|
[7668] | 141 | for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
|
---|
[2808] | 142 | {
|
---|
| 143 | for my $ifile (sort @ifiles)
|
---|
| 144 | {
|
---|
| 145 | $ifile =~ s/^images\///;
|
---|
| 146 | $haveicons{$ifile} = 1;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | for my $img (sort keys %icons)
|
---|
| 151 | {
|
---|
[7668] | 152 | if($img =~ /\.(png|svg)/)
|
---|
| 153 | {
|
---|
| 154 | print STDERR "File $img does not exist!\n" if(!-f "images/$img");
|
---|
| 155 | delete $haveicons{$img};
|
---|
| 156 | }
|
---|
| 157 | else
|
---|
| 158 | {
|
---|
| 159 | print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
|
---|
| 160 | delete $haveicons{"$img.svg"};
|
---|
| 161 | delete $haveicons{"$img.png"};
|
---|
| 162 | }
|
---|
[2808] | 163 | }
|
---|
| 164 |
|
---|
| 165 | for my $img (sort keys %haveicons)
|
---|
| 166 | {
|
---|
| 167 | print "$img\n";
|
---|
| 168 | }
|
---|