moved in briskin5
[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 % 2)) -eq 0 ]; then
44          echo
45          echo -n "$spa"
46       fi
47    else
48       echo -n "$spa"
49    fi
50    outna="`echo "$i" | cut -c $((ltri + 1))-`"
51    echo -n "\"$outna\""
52    ct=$((ct + 1))
53    first=0
54 done
55 echo "CT: $ct" >&2
56 echo ");"
57 ) >> $OUTFILE
58
59 (
60 echo "var g_preload_imgsz_arr = new Array( "
61 first=1
62 sum=0
63 spa="            "
64 tot=0
65 for i in `find $IMGPATH -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`; do
66    sz="`stat -c '%s' $IMGPATH/$i`"
67    tot=$((tot + sz))
68 done
69
70 for i in `find $IMGPATH -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`; do
71    if [ $first -ne 1 ]; then
72       echo -n ", "
73       if [ $((ct % 8)) -eq 0 ]; then
74          echo
75          echo -n "$spa"
76       fi
77    else
78       echo -n "$spa"
79    fi
80    sz="`stat -c '%s' $IMGPATH/$i`"
81    sum=$((sum + sz))
82    cur="`echo "100.0 * $sum / $tot" | bc -l | sed 's/\(\.[0-9]\)[0-9]*/\1/g'`"
83    echo -n "\"$cur\""
84    ct=$((ct + 1))
85    first=0
86 done
87
88 echo "CT2: $ct" >&2
89
90 echo ");"
91 ) >> $OUTFILE
92
93 exit 0