update
[brisk.git] / bin / preload.sh
1 #!/bin/bash
2 #
3 #  brisk - preload.sh
4 #
5 #  Copyright (C) 2006 matteo.nastasi@milug.org
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details. You should have received a
16 # copy of the GNU General Public License along with this program; if
17 # not, write to the Free Software Foundation, Inc, 59 Temple Place -
18 # Suite 330, Boston, MA 02111-1307, USA.
19 #
20 #
21
22
23 OUTFILE=web/preload_img.js
24 IMGPATH=../brisk-img
25
26 # (
27 # echo '<?php'
28 # echo 'header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1'
29 # echo 'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past'
30 # echo '?>'
31 # ) > $OUTFILE
32
33 rm -f $OUTFILE
34
35 (
36 echo "var g_preload_img_arr = new Array( "
37 first=1
38 spa="            "
39 ltri="`echo "$IMGPATH" | wc -c`"
40 for i in `find $IMGPATH -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`; do
41    if [ $first -ne 1 ]; then
42       echo -n ", "
43       if [ $ct -eq 3 ]; then
44          echo
45          echo -n "$spa"
46          ct=0
47       fi
48    else
49       echo -n "$spa"
50    fi
51    outna="`echo "$i" | cut -c $((ltri + 1))-`"
52    echo -n "\"$outna\""
53    ct=$((ct + 1))
54    first=0
55 done
56
57 echo ");"
58 ) >> $OUTFILE
59
60 (
61 echo "var g_preload_imgsz_arr = new Array( "
62 first=1
63 sum=0
64 spa="            "
65 tot=0
66 for i in `find $IMGPATH -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`; do
67    sz="`stat -c '%s' $IMGPATH/$i`"
68    tot=$((tot + sz))
69 done
70
71 for i in `find $IMGPATH -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`; do
72    if [ $first -ne 1 ]; then
73       echo -n ", "
74       if [ $ct -eq 8 ]; then
75          echo
76          echo -n "$spa"
77          ct=0
78       fi
79    else
80       echo -n "$spa"
81    fi
82    sz="`stat -c '%s' $IMGPATH/$i`"
83    sum=$((sum + sz))
84    cur="`echo "100.0 * $sum / $tot" | bc -l | sed 's/\(\.[0-9]\)[0-9]*/\1/g'`"
85    echo -n "\"$cur\""
86    ct=$((ct + 1))
87    first=0
88 done
89
90 echo ");"
91 ) >> $OUTFILE
92
93 exit 0