3 use File::Copy qw/copy move/;
4 use Digest::file qw/digest_file_hex/;
6 $moveinsteadofcopy = 0;
11 @voidtilesizes = ( 334, 854 );
13 '1cf52aed67c3ebf045f2fd2996ada35545517129e673dba00ef97c7d18275f144aa67b012556ec8a840fca158f6976e7cf30fcae030acd493e26e28fdff10ca3',
14 '1feba96da5f6fa6049d7b40dc72295058eabb7e771040dedc8a69527046aa34fdaaf98e676ed8d02e95770dc635b5d4bf292fdd19be3c381847d3883995d3f3f',
15 '609e45a0c39d961302ed560d9d8bffd798fdbcc912c3875c06ba1faa1fab83cce8d97f257d572138898d2d99fb5a7af80801080bb7be9688e029fce4a9c56f5f'
18 # Par. 0: Level on which this gets printed
21 if ($verblev >= $_[0]) {
26 sub showhelpandexit() {
27 print("Syntax: $0 sourcedirectoy destinationdirectory\n");
36 unless (opendir($dh, $srcdir)) {
37 print(STDERR "failed to read sourcedirectoy '$srcdir' for zoomlevel $z.\n");
41 printlev(2, "MKDIR 'dstdir'\n");
42 unless (mkdir($dstdir)) {
43 print(STDERR "Destination directory '$dstdir' for zoomlevel $z does not exist and could not be created: $!\n");
47 while (my $de = readdir($dh)) {
48 if ($de =~ m/^(\d+)\.png$/) { # just a number dot png => handle this.
50 my $correctedynr = ((2 ** $z) - 1) - $ynr;
51 my $srcname = $srcdir . '/' . $de;
52 my $dstname = sprintf("%s/%d.png", $dstdir, $correctedynr);
55 printlev(2, "SKIP '$srcname' ('$dstname' already exists)\n");
60 my $fsize = -s $srcname;
61 if ($fsize ~~ @voidtilesizes) { # One of the relevant filesizes, no
62 # point in even computing the hash otherwise.
63 my $sha512 = digest_file_hex($srcname, "SHA-512");
64 printlev(3, "HASH $srcname -> $sha512\n");
65 if ($sha512 ~~ @voidtilehashes) { # OK, one of the void hashes -> skip
66 printlev(2, "SKIP '$srcname' (it has the hash of a void file)\n");
71 if ($moveinsteadofcopy) {
72 printlev(2, "MOVE '$srcname' '$dstname'\n");
73 move($srcname, $dstname);
75 printlev(2, "COPY '$srcname' '$dstname'\n");
76 copy($srcname, $dstname);
83 sub handlezoomdir($$$) {
85 my $srcdir = $_[0] . '/' . $z;
86 my $dstdir = $_[1] . '/' . $z;
88 printlev(1, "sourcedirectoy '$srcdir' for zoomlevel $z does not exist, skipping.\n");
92 unless (opendir($dh, $srcdir)) {
93 print(STDERR "failed to read sourcedirectoy '$srcdir' for zoomlevel $z.\n");
97 printlev(2, "MKDIR '$dstdir'\n");
98 unless (mkdir($dstdir)) {
99 print(STDERR "Destination directory '$dstdir' for zoomlevel $z does not exist and could not be created: $!\n");
103 while (my $de = readdir($dh)) {
104 if ($de =~ m/^\d+$/) { # just a number -> handle this directory.
105 handlexdir($srcdir . '/' . $de, $dstdir . '/' . $de, $z);
114 if ($a eq '--move') {
115 $moveinsteadofcopy = 1;
116 } elsif ($a eq '--noreplace') {
118 } elsif ($a eq '--skipvoidtiles') {
120 } elsif ($a eq '--help') {
122 } elsif ($a eq '-q') {
124 } elsif ($a eq '-v') {
126 } else { # This will be interpreted as a directory name
127 if (!defined($srcdir)) {
129 } elsif (!defined($dstdir)) {
131 } else { # More than 2 directory names? That is wrong.
136 unless (-d $srcdir) {
137 print(STDERR "Source directory '$srcdir' does not seem to exist or is not a directory?\n");
140 unless (-d $dstdir) {
141 unless (mkdir($dstdir)) {
142 print(STDERR "Destination directory '$dstdir' does not exist and could not be created: $!\n");
146 for (my $z = 0; $z < 30; $z++) {
147 handlezoomdir($srcdir, $dstdir, $z);