1 |
root |
1.1 |
#!/usr/bin/perl |
2 |
|
|
# |
3 |
|
|
# this script goes through and collects the various image sets into crossfire-x.png |
4 |
|
|
# files, where x is the numbers from the image_info file. This |
5 |
|
|
# collects all the images at once, whether or not they have |
6 |
|
|
# been changed or not. |
7 |
|
|
|
8 |
|
|
# This script collects all the images. If given a -archive option, it |
9 |
|
|
# does some additional work - checksumming the images, making a bmaps.client |
10 |
|
|
# file, and then tarring that data up. This data can then be used on the |
11 |
|
|
# client as a fast way to 'bootstrap' the clients images. |
12 |
|
|
|
13 |
|
|
use FileHandle; |
14 |
|
|
|
15 |
|
|
die("No arch directory - will not rebuild $mode image file") if (! -e "arch"); |
16 |
|
|
|
17 |
|
|
$archive = 0; |
18 |
|
|
$TMPDIR="/tmp"; |
19 |
|
|
|
20 |
|
|
# What we will call the collection of images. |
21 |
|
|
$ARCHNAME="crossfire-images"; |
22 |
|
|
$DESTDIR="$TMPDIR/$ARCHNAME"; |
23 |
|
|
|
24 |
|
|
# Maximum expected file |
25 |
|
|
$MAXFILESIZE=100000; |
26 |
|
|
|
27 |
|
|
if ($ARGV[0] eq "-archive") { |
28 |
|
|
$archive =1; |
29 |
|
|
print "Will generate appropriate files for image archive\n"; |
30 |
|
|
die("$DESTDIR already exists - remove if you really want to remake the images") if (-d $DESTDIR); |
31 |
|
|
die("$0: unable to mkdir $DESTDIR: $1\n") if (!mkdir($DESTDIR, 0755)); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
open(IMAGEINFO,"image_info") || die("Can't open image_info file: $!\n"); |
35 |
|
|
while (<IMAGEINFO>) { |
36 |
|
|
# Ignore lines that start with comments or just empty lines |
37 |
|
|
next if /^#/; |
38 |
|
|
next if /^\s*$/; |
39 |
|
|
($setnum, $ext, @rest) = split /:/; |
40 |
|
|
# We don't actually need that data in this script, but may as well do sanity |
41 |
|
|
# checking. |
42 |
|
|
if ($#rest != 4) { |
43 |
|
|
print STDERR "image_info: line is corrupt:\n$_"; |
44 |
|
|
} |
45 |
|
|
if ($extension[$setnum]) { |
46 |
|
|
print STDERR "Warning: set $setnum is duplicated in image_info file\n"; |
47 |
|
|
} |
48 |
|
|
$extension[$setnum] = $ext; |
49 |
|
|
} |
50 |
|
|
close(IMAGEINFO); |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
for ($count=0; $count<=$#extension; $count++) { |
54 |
|
|
$ESRV[$count] = new FileHandle; |
55 |
|
|
$fh = $ESRV[$count]; |
56 |
|
|
open($fh, ">crossfire.$count") || |
57 |
|
|
die("Can't open crossfire.$count for write: $!\n"); |
58 |
|
|
binmode( $fh ); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
open(BMAPS,"bmaps.paths") || die("Can't open bmaps.paths: $!\n"); |
62 |
|
|
$_ = <BMAPS>; |
63 |
|
|
while(<BMAPS>) { |
64 |
|
|
chop; |
65 |
|
|
|
66 |
|
|
# we need to insert the extension for the images between the name |
67 |
|
|
# and the number (.171 or whatever) extension, so split on that. |
68 |
|
|
|
69 |
|
|
die("Unknown line: '$_'\n") unless /^\\(\d{5})\s+(\S+)\.(\w\w\w)$/o; |
70 |
|
|
$num = $1; |
71 |
|
|
$file = $2; |
72 |
|
|
$file1 = $3; |
73 |
|
|
|
74 |
|
|
print "$num $file\n" if ($num % 500) == 0 ; |
75 |
|
|
# This probably isn't the most efficient way to do this if a |
76 |
|
|
# large number of images are added, as we try to open each |
77 |
|
|
# instance. |
78 |
|
|
# OTOH, we are doing one directory |
79 |
|
|
# at a time, so we should be hitting the DNLC at a very high |
80 |
|
|
# rate. |
81 |
|
|
|
82 |
|
|
for ($count=0; $count<=$#extension; $count++) { |
83 |
|
|
$filename = "$file.$extension[$count].$file1.png"; |
84 |
|
|
$fh = $ESRV[$count]; |
85 |
|
|
|
86 |
|
|
$length = -s "$filename"; |
87 |
|
|
if (open(FILE,"$filename")) { |
88 |
|
|
binmode( FILE ); |
89 |
root |
1.2 |
my $path = "$file.$file1"; |
90 |
|
|
$path =~ s/.*\///; |
91 |
|
|
printf $fh "IMAGE %d %d %s\n", $num, $length, $path; |
92 |
root |
1.1 |
print "Error reading file $filename" if (!read(FILE, $buf, $length)); |
93 |
|
|
$position = tell $fh; |
94 |
|
|
print $fh $buf; |
95 |
|
|
close(FILE); |
96 |
|
|
|
97 |
|
|
if ($archive) { |
98 |
|
|
# Now figure out the checksum |
99 |
|
|
# Same as what is used for the client/server - code basically |
100 |
|
|
# taken write form that. |
101 |
|
|
$sum = 0; |
102 |
|
|
for ($i=0; $i<$length; $i++) { |
103 |
|
|
if ($sum & 01) { |
104 |
|
|
$sum = ($sum >> 1) | 0x80000000; |
105 |
|
|
} else { |
106 |
|
|
$sum >>= 1; |
107 |
|
|
} |
108 |
|
|
$sum += ord(substr $buf, $i, 1); |
109 |
|
|
$sum &= 0xffffffff; |
110 |
|
|
} |
111 |
|
|
# Do some name translation to figure out our output file name. |
112 |
|
|
@comps = split /\//, $file; |
113 |
|
|
$destfile = $comps[$#comps]; |
114 |
|
|
push @csums, "$destfile.$file1 $sum crossfire.$extension[$count]\@$position:$length\n"; |
115 |
|
|
} # if archive |
116 |
|
|
} |
117 |
|
|
elsif ($count==0) { |
118 |
|
|
# set 0 should have all the sets |
119 |
|
|
print "Error: Image $filename not found for set 0!\n"; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
for ($count=0; $count<=$#extension; $count++) { |
125 |
|
|
close($ESRV[$count]); |
126 |
|
|
} |
127 |
|
|
close(BMAPS); |
128 |
|
|
|
129 |
|
|
if ($archive) { |
130 |
|
|
open(OUT,">$DESTDIR/bmaps.client") || die("Can not open $DESTDIR/bmaps.paths\n"); |
131 |
|
|
print OUT sort @csums; |
132 |
|
|
close(OUT); |
133 |
|
|
open(OUT,">$DESTDIR/README") || die("Can not open $DESTDIR/README\n"); |
134 |
|
|
print OUT "These image files for the client should be located in\n"; |
135 |
|
|
print OUT "\$prefix/share/crossfire-client. \$prefix is the location given in the -prefix\n"; |
136 |
|
|
print OUT "option when configure is run to build the client. The default is /usr/local.\n"; |
137 |
|
|
print OUT "In that case these files should be put in /usr/local/share/crossfire-client\n"; |
138 |
|
|
print OUT "The client will print a messgae if it is unable to find the image information\n"; |
139 |
|
|
print OUT "with the location is looked for them.\n"; |
140 |
|
|
close(OUT); |
141 |
|
|
|
142 |
|
|
for ($count=0; $count<=$#extension; $count++) { |
143 |
|
|
system("cp crossfire.$count $DESTDIR/crossfire.$extension[$count]"); |
144 |
|
|
} |
145 |
|
|
system("cd $DESTDIR; tar cf $TMPDIR/$ARCHNAME.tar ."); |
146 |
|
|
system("mv $TMPDIR/$ARCHNAME.tar ../"); |
147 |
|
|
system("rm -rf $TMPDIR/$ARCHNAME"); |
148 |
|
|
} |