ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/adm/collect_images.pl
Revision: 1.1.1.1 (vendor branch)
Committed: Fri Feb 3 07:14:15 2006 UTC (18 years, 4 months ago) by root
Content type: text/plain
Branch: UPSTREAM
CVS Tags: LAST_C_VERSION, UPSTREAM_2006_03_15, UPSTREAM_2006_02_22, UPSTREAM_2006_02_03, difficulty_fix_merge_060810_2300
Branch point for: difficulty_fix
Changes since 1.1: +0 -0 lines
Log Message:
initial import

File Contents

# Content
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 print $fh "IMAGE $num $length $file.$file1\n";
90 print "Error reading file $filename" if (!read(FILE, $buf, $length));
91 $position = tell $fh;
92 print $fh $buf;
93 close(FILE);
94
95 if ($archive) {
96 # Now figure out the checksum
97 # Same as what is used for the client/server - code basically
98 # taken write form that.
99 $sum = 0;
100 for ($i=0; $i<$length; $i++) {
101 if ($sum & 01) {
102 $sum = ($sum >> 1) | 0x80000000;
103 } else {
104 $sum >>= 1;
105 }
106 $sum += ord(substr $buf, $i, 1);
107 $sum &= 0xffffffff;
108 }
109 # Do some name translation to figure out our output file name.
110 @comps = split /\//, $file;
111 $destfile = $comps[$#comps];
112 push @csums, "$destfile.$file1 $sum crossfire.$extension[$count]\@$position:$length\n";
113 } # if archive
114 }
115 elsif ($count==0) {
116 # set 0 should have all the sets
117 print "Error: Image $filename not found for set 0!\n";
118 }
119
120 }
121 }
122 for ($count=0; $count<=$#extension; $count++) {
123 close($ESRV[$count]);
124 }
125 close(BMAPS);
126
127 if ($archive) {
128 open(OUT,">$DESTDIR/bmaps.client") || die("Can not open $DESTDIR/bmaps.paths\n");
129 print OUT sort @csums;
130 close(OUT);
131 open(OUT,">$DESTDIR/README") || die("Can not open $DESTDIR/README\n");
132 print OUT "These image files for the client should be located in\n";
133 print OUT "\$prefix/share/crossfire-client. \$prefix is the location given in the -prefix\n";
134 print OUT "option when configure is run to build the client. The default is /usr/local.\n";
135 print OUT "In that case these files should be put in /usr/local/share/crossfire-client\n";
136 print OUT "The client will print a messgae if it is unable to find the image information\n";
137 print OUT "with the location is looked for them.\n";
138 close(OUT);
139
140 for ($count=0; $count<=$#extension; $count++) {
141 system("cp crossfire.$count $DESTDIR/crossfire.$extension[$count]");
142 }
143 system("cd $DESTDIR; tar cf $TMPDIR/$ARCHNAME.tar .");
144 system("mv $TMPDIR/$ARCHNAME.tar ../");
145 system("rm -rf $TMPDIR/$ARCHNAME");
146 }