When it came time to submit that apps to the Apple AppStore, we found that they were far too large to meet the under 20Mb requirement to download over 3G.
The following script is pretty straight forward to use and supports only a few options. Most usage should simply be:

By default it scans the "src" folder at the current level the command is run from. It will scan any of the popular Adobe AIR file types for references to any of the files that are in the directory you specify (src/assets/backgrounds/ in the above example)
Here's what it looks like when it finds a potential orphaned file:

(If you tack on the -d argument it will automatically delete files that it thinks are orphaned*)
*Orphaned for me, is a file that is not explicitly referenced in code or XML. This script will not find files that are linked dynamically
[bash]
#!/bin/bash
DELETE=false
TRACE=false
filelist=
FOUND=0
MISSING=0
SOURCE_DIR="./src"
until [ -z "$1" ]; do
# use a case statement to test vars. we always test
# test $1 and shift at the end of the for block.
case $1 in
-d )
DELETE=true
echo "Will delete orphaned files"
;;
-t )
TRACE=true
;;
-s )
shift
SOURCE_DIR=$1
;;
-* )
echo "Unrecognized option: $1"
exit 1
;;
* )
filelist=$1
;;
esac
shift
if [ "$#" = "0" ]; then
break
fi
done
if [ -z "$filelist" ]; then
echo "Usage: countImages.sh path [-d] [-t] [-s dir]"
echo "Specify -d if you wish to remove orphaned files."
echo "Specify -t if you wish to show found files"
echo "Specify -s dir if you wish to specify a specific source directory to scan. Default is ./src"
echo "If you wish to find all source files a particular image is referenced in, simple specify a path to a file"
echo "instead of a directory for path."
exit 1
fi
echo "Scanning $SOURCE_DIR for images from $filelist"
for file in $filelist*
do
SHORT_FILE=`basename $file`
RET=`find $SOURCE_DIR -type f \( -name "*.xml" -o -name "*.mxml" -o -name "*.as" \) -exec grep $SHORT_FILE {} \; -print | grep -c "$SHORT_FILE"`
if [ $RET -eq "0" ]
then
echo "$file has no occurences"
MISSING=$[$MISSING+1]
if $DELETE
then
rm $file
if [ $? = 0 ]
then
echo "... removed"
fi
fi
else
if $TRACE; then
echo "Found: $SHORT_FILE ($RET)"
RET2=`find $SOURCE_DIR -type f \( -name "*.xml" -o -name "*.mxml" -o -name "*.as" \) -exec grep $SHORT_FILE {} \; -print `
echo $RET2
fi
FOUND=$[$FOUND+1]
fi
done
echo "Found $FOUND files"
echo "There are $MISSING missing files that are potentially orphans."
[/bash]
1 comment:
Thanks a lot, i found this script simple AMAZING !!! i'm working on a BB mobile app and you can't image how many hours of work and also it helped a lot with the performance !
thanks !!! (y)
Post a Comment