[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/;
|
---|
[10069] | 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 | }
|
---|
[7736] | 45 | if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"\)/)
|
---|
[2808] | 46 | {
|
---|
| 47 | my $i = $1;
|
---|
[10069] | 48 | $i = "styles/standard/$i" if $i eq "misc/no_icon";
|
---|
[2808] | 49 | ++$icons{$i};
|
---|
| 50 | }
|
---|
[4172] | 51 | while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
|
---|
| 52 | {
|
---|
| 53 | my $i = $1;
|
---|
| 54 | ++$icons{$i};
|
---|
| 55 | }
|
---|
| 56 | while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
|
---|
| 57 | {
|
---|
| 58 | my $i = "$1$2";
|
---|
| 59 | ++$icons{$i};
|
---|
| 60 | }
|
---|
[2808] | 61 | if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
|
---|
| 62 | {
|
---|
| 63 | my $i = "statusline/$1";
|
---|
| 64 | ++$icons{$i};
|
---|
| 65 | }
|
---|
| 66 | if($l =~ /createPreferenceTab\(\"(.*?)\"/)
|
---|
| 67 | {
|
---|
| 68 | my $i = "preferences/$1";
|
---|
| 69 | ++$icons{$i};
|
---|
| 70 | }
|
---|
[10069] | 71 | if($l =~ /setIcon\(\"(.*?)\"/)
|
---|
[2808] | 72 | {
|
---|
[10069] | 73 | my $i = "statusline/$1";
|
---|
| 74 | ++$icons{$i};
|
---|
| 75 | }
|
---|
| 76 | if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
|
---|
| 77 | {
|
---|
[2808] | 78 | my $i = "$1/$2";
|
---|
| 79 | ++$icons{$i};
|
---|
| 80 | }
|
---|
[10069] | 81 | if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
|
---|
| 82 | {
|
---|
| 83 | my $i = "$1/$2";
|
---|
| 84 | ++$icons{$i};
|
---|
| 85 | }
|
---|
[2811] | 86 | if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
|
---|
[2808] | 87 | {
|
---|
[2811] | 88 | my $i = $1;
|
---|
| 89 | ++$icons{$i};
|
---|
| 90 | }
|
---|
| 91 | if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
|
---|
| 92 | {
|
---|
[2808] | 93 | my $i = "cursor/modifier/$2";
|
---|
| 94 | ++$icons{$i};
|
---|
| 95 | $i = "cursor/$1";
|
---|
| 96 | ++$icons{$i};
|
---|
| 97 | }
|
---|
[2811] | 98 | if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
|
---|
| 99 | {
|
---|
| 100 | my $i = "cursor/$1";
|
---|
| 101 | ++$icons{$i};
|
---|
| 102 | }
|
---|
[4172] | 103 | if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
|
---|
| 104 | {
|
---|
| 105 | my $i = "dialogs/$1";
|
---|
| 106 | ++$icons{$i};
|
---|
| 107 | }
|
---|
[2808] | 108 | if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
|
---|
| 109 | {
|
---|
| 110 | my $i = "$extends$1";
|
---|
| 111 | ++$icons{$i};
|
---|
| 112 | }
|
---|
[2981] | 113 | if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
|
---|
| 114 | {
|
---|
| 115 | my $i = "$extends$1";
|
---|
| 116 | ++$icons{$i};
|
---|
| 117 | }
|
---|
[2811] | 118 | if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
|
---|
| 119 | {
|
---|
| 120 | my $i = "markers/$1";
|
---|
| 121 | ++$icons{$i};
|
---|
| 122 | }
|
---|
| 123 | if($l =~ /\"(.*?)\",\s*parentLayer/s)
|
---|
| 124 | {
|
---|
| 125 | my $i = "markers/$1";
|
---|
| 126 | ++$icons{$i};
|
---|
| 127 | }
|
---|
[10069] | 128 | if($l =~ /setButtonIcons.*\{(.*)\}/)
|
---|
[2808] | 129 | {
|
---|
| 130 | my $t = $1;
|
---|
| 131 | while($t =~ /\"(.*?)\"/g)
|
---|
| 132 | {
|
---|
| 133 | my $i = $1;
|
---|
| 134 | ++$icons{$i};
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | if($l =~ /extends MapMode/)
|
---|
| 138 | {
|
---|
| 139 | $extends = "mapmode/";
|
---|
| 140 | }
|
---|
[7668] | 141 | elsif($l =~ /extends ToggleDialog/)
|
---|
[2808] | 142 | {
|
---|
| 143 | $extends = "dialogs/";
|
---|
| 144 | }
|
---|
[10069] | 145 | elsif($l =~ /extends JosmAction/)
|
---|
| 146 | {
|
---|
| 147 | $extends = "";
|
---|
| 148 | }
|
---|
[2808] | 149 | }
|
---|
| 150 | close FILE;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | my %haveicons;
|
---|
| 155 |
|
---|
[7668] | 156 | for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
|
---|
[2808] | 157 | {
|
---|
| 158 | for my $ifile (sort @ifiles)
|
---|
| 159 | {
|
---|
| 160 | $ifile =~ s/^images\///;
|
---|
| 161 | $haveicons{$ifile} = 1;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | for my $img (sort keys %icons)
|
---|
| 166 | {
|
---|
[7668] | 167 | if($img =~ /\.(png|svg)/)
|
---|
| 168 | {
|
---|
| 169 | print STDERR "File $img does not exist!\n" if(!-f "images/$img");
|
---|
| 170 | delete $haveicons{$img};
|
---|
| 171 | }
|
---|
| 172 | else
|
---|
| 173 | {
|
---|
| 174 | print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
|
---|
| 175 | delete $haveicons{"$img.svg"};
|
---|
| 176 | delete $haveicons{"$img.png"};
|
---|
| 177 | }
|
---|
[2808] | 178 | }
|
---|
| 179 |
|
---|
| 180 | for my $img (sort keys %haveicons)
|
---|
| 181 | {
|
---|
| 182 | print "$img\n";
|
---|
| 183 | }
|
---|