Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -o nounset
- if [ "$#" -ne 2 ]; then
- echo -e "Usage:\n\t$0 <fla file OR folder containing xfl> <swf file>\n"
- exit 1;
- fi
- FLA_PATH=$(pwd)/$(basename $1)
- SWF=$(basename "$2")
- SWF_PATH=$(pwd)/$SWF
- count_asset_named_placements()
- {
- ASSET_CLASS=$1
- DUMP_FILE=$2
- EXPORT_ID=$(grep "exports [0-9]\+ as \"$ASSET_CLASS\"" $DUMP_FILE | awk '{ print $2 }')
- if [ -z "$EXPORT_ID" ]
- then
- echo 0
- exit
- fi
- grep "places id $EXPORT_ID .* name " $DUMP_FILE | wc | awk '{ print $1 }'
- }
- SWF_DUMP_TMP=$(mktemp)
- swfdump -u "$SWF_PATH" > $SWF_DUMP_TMP
- echo "Swfdump: $SWF_DUMP_TMP"
- if [ -d $FLA_PATH ]
- then
- pushd $FLA_PATH > /dev/null
- DELETE_FLA_TMP_FOLDER=false
- else
- FLA_TMP_FOLDER=$(mktemp -d "${TMPDIR:-/tmp/}"$(basename $0).XXXXXX)
- DELETE_FLA_TMP_FOLDER=true
- pushd $FLA_TMP_FOLDER > /dev/null
- unzip -qq "$FLA_PATH" 2>/dev/null
- fi
- BUILD_BAD=false
- FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep -l linkageClassName {} \+ | sed 's/^LIBRARY\/\(.*\)\.xml/\1/')
- #
- # First perform some useful analysis
- #
- declare -A ASSET_TO_CLASS
- declare -A CLASS_TO_ASSET
- declare -A IS_ASSET_LINKED
- declare -A IS_CLASS_LINKED
- IFS=$'\n'
- for ASSET in $FLA_ASSETS
- do
- CLASS=$(grep linkageClassName "LIBRARY/${ASSET}.xml" | sed 's/.*linkageClassName="\([^"]*\)".*/\1/')
- ASSET_TO_CLASS[$ASSET]=$CLASS
- CLASS_TO_ASSET[$CLASS]=$ASSET
- LINKED=$(grep "exports .*$CLASS" $SWF_DUMP_TMP | wc | awk '{ print $1 }')
- IS_ASSET_LINKED[$ASSET]=$LINKED
- IS_CLASS_LINKED[$CLASS]=$LINKED
- done
- for FLA_ASSET in $FLA_ASSETS
- do
- #echo -e "Asset: $FLA_ASSET\n Class: ${ASSET_TO_CLASS[$FLA_ASSET]}\n Linked: ${IS_ASSET_LINKED[$FLA_ASSET]}"
- #
- # If the asset isn't linked into the swf, check if it should be. For example sometimes the AS3 component skins are simply missing
- # if they aren't otherwise referenced by linkage class in the source.
- #
- if [ "${IS_ASSET_LINKED[$FLA_ASSET]}" == 0 ]
- then
- PLACED_BY_FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep "libraryItemName=\"$FLA_ASSET\"" {} \+ | grep Instance | sed 's/^LIBRARY\/\(.*\)\.xml.*/\1/' | sort -u)
- for PLACED_BY_FLA_ASSET in $PLACED_BY_FLA_ASSETS
- do
- if [ "${IS_ASSET_LINKED[$PLACED_BY_FLA_ASSET]}" == 1 ]
- then
- echo "ERROR: $FLA_ASSET is not linked but is placed by linked asset $PLACED_BY_FLA_ASSET" 1>&2
- BUILD_BAD=true
- fi
- done
- continue
- fi
- #
- # Sometimes an asset will be linked but wont be correctly associated with instances given a name at design time.
- #
- NAMED_BY_FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep "libraryItemName=\"$FLA_ASSET\"" {} \+ | grep Instance | grep name=\" | sed 's/^LIBRARY\/\(.*\)\.xml.*/\1/' | sort -u)
- if [ -z "$NAMED_BY_FLA_ASSETS" ]
- then
- continue
- fi
- NAMED_USES=0
- for NAMED_BY_FLA_ASSET in $NAMED_BY_FLA_ASSETS
- do
- if [ "${IS_ASSET_LINKED[$NAMED_BY_FLA_ASSET]}" == 1 ]
- then
- #echo " named by linked asset $NAMED_BY_FLA_ASSET"
- NAMED_USES=$((NAMED_USES + 1))
- fi
- done
- if [ "$NAMED_USES" == 0 ]
- then
- continue
- fi
- #
- # The asset is named at least once in another asset that is linked into the swf.
- #
- FLA_ASSET_CLASS=${ASSET_TO_CLASS[$FLA_ASSET]}
- SWF_USES=$(count_asset_named_placements $FLA_ASSET_CLASS $SWF_DUMP_TMP)
- if [ "$SWF_USES" != 0 ] || [ "$NAMED_USES" != 0 ]
- then
- if [ "$SWF_USES" != "$NAMED_USES" ]
- then
- echo "ERROR: $FLA linked as $FLA_ASSET_CLASS with $NAMED_USES expected named uses, found $SWF_USES named uses in swf" 1>&2
- BUILD_BAD=true
- #else
- #echo " linked as $FLA_ASSET_CLASS with $NAMED_USES expected named uses, found $SWF_USES named uses in swf"
- fi
- fi
- done
- popd > /dev/null
- #
- # Cleanup
- #
- if $DELETE_FLA_TMP_FOLDER
- then
- rm -rf "$FLA_TMP_FOLDER"
- fi
- if $BUILD_BAD
- then
- echo -e "\nBuild is bad."
- exit 2
- else
- echo -e "\nBuild is good!"
- fi
Advertisement
Add Comment
Please, Sign In to add comment