Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust extractor scripts #519

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 68 additions & 73 deletions contrib/extractor_scripts/ExtractResources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,36 @@ AD_RES=""
VMAP_RES=""
NUM_THREAD=""

if [ "$1" != "a" ] && [ "x$1" != "x" ]
then
if [ "$1" != "a" ] && [ "x$1" != "x" ]; then
CLIENT_PATH="$1"
OUTPUT_PATH="$2"
elif [ "x$2" != "x" ]
then
elif [ "x$2" != "x" ]; then
CLIENT_PATH="$2"
OUTPUT_PATH="$3"
fi

if [ "x${CLIENT_PATH}" != "x" ]
then
if [ ! -d "${CLIENT_PATH}/Data" ]
then
if [ "x${CLIENT_PATH}" != "x" ]; then
if [ ! -d "${CLIENT_PATH}/Data" ]; then
echo "Data folder not found in provided client path [${CLIENT_PATH}]. Plese provide a correct client path."
exit 1
fi
else
if [ ! -d "$(pwd)/Data" ]
then
if [ ! -d "$(pwd)/Data" ]; then
echo "Data folder not found. Make sure you have copied the script to the client folder and the 'Data' folder has the correct case."
exit 1
fi
fi

if [ "x${OUTPUT_PATH}" != "x" ]
then
if [ ! -d "${OUTPUT_PATH}" ]
then
if [ "x${OUTPUT_PATH}" != "x" ]; then
if [ ! -d "${OUTPUT_PATH}" ]; then
echo "Provided OUTPUT_PATH=${OUTPUT_PATH} does not exist, please create it before"
exit 1
fi
LOG_FILE="${OUTPUT_PATH:-.}/${LOG_FILE}"
DETAIL_LOG_FILE="${OUTPUT_PATH:-.}/${DETAIL_LOG_FILE}"
fi

if [ "$1" = "a" ]
then
if [ "$1" = "a" ]; then
## extract all
USE_AD="1"
USE_VMAPS="1"
Expand All @@ -80,8 +72,7 @@ else
echo "Welcome to helper script to extract required dataz for MaNGOS!"
echo "Should all dataz (dbc, maps, vmaps and mmaps) be extracted? (y/n)"
read line
if [ "$line" = "y" ]
then
if [ "$line" = "y" ]; then
## extract all
USE_AD="1"
USE_VMAPS="1"
Expand All @@ -101,48 +92,31 @@ else
echo "Should mmaps be extracted? (y/n)"
echo "WARNING! This may take several hours with small number of CPU threads!"
read line
if [ "$line" = "y" ]
then
USE_MMAPS="1";
if [ "$line" = "y" ]; then
USE_MMAPS="1"
else
echo
echo "Only reextract offmesh tiles for mmaps? (y/n)"
read line
if [ "$line" = "y" ]
then
USE_MMAPS_OFFMESH="1";
if [ "$line" = "y" ]; then
USE_MMAPS_OFFMESH="1"
fi
fi
fi
fi

if [ "x$CLIENT_PATH" != "x" ]
then
AD_OPT_RES="-i $CLIENT_PATH"
VMAP_OPT_RES="-d $CLIENT_PATH/Data"
fi

if [ "x$OUTPUT_PATH" != "x" ] && [ -d "$OUTPUT_PATH" ]
then
AD_OPT_RES="$AD_OPT_RES -o $OUTPUT_PATH"
VMAP_OPT_RES="$VMAP_OPT_RES -o $OUTPUT_PATH"
fi

## Special case: Only reextract offmesh tiles
if [ "$USE_MMAPS_OFFMESH" = "1" ]
then
if [ "$USE_MMAPS_OFFMESH" = "1" ]; then
echo "Only extracting offmesh tiles"
"$PREFIX"/MoveMapGen.sh offmesh "$OUTPUT_PATH" "$LOG_FILE" "$DETAIL_LOG_FILE"
exit 0
fi

## MMap Extraction specific
if [ "$1" = "a" ]
then
if [ "$1" = "a" ]; then
NUM_THREAD="all"
USE_MMAPS_DELAY=""
elif [ "$USE_MMAPS" = "1" ]
then
elif [ "$USE_MMAPS" = "1" ]; then
## Obtain number of processes
echo "How many CPU threads should be used for extracting mmaps? (leave empty to use all available threads)"
read line
Expand Down Expand Up @@ -174,8 +148,7 @@ then
fi

## Check if user want to do high resolution extraction of maps
if [ "$1" = "a" ]
then
if [ "$1" = "a" ]; then
AD_RES=""
elif [ "$USE_AD" = "1" ]; then
echo
Expand All @@ -189,8 +162,7 @@ elif [ "$USE_AD" = "1" ]; then
fi

## Check if user want to do high resolution extraction of vmaps
if [ "$1" = "a" ]
then
if [ "$1" = "a" ]; then
VMAP_RES=""
elif [ "$USE_VMAPS" = "1" ]; then
echo
Expand All @@ -208,38 +180,34 @@ echo
echo "Current Settings:"
echo "Extract DBCs/maps: $USE_AD, Extract vmaps: $USE_VMAPS, Extract mmaps: $USE_MMAPS, Processes for mmaps: $NUM_THREAD"
if [ "$USE_AD" = "1" ] && [ "$AD_RES" = "-f 0" ]; then
echo "maps extraction will be high-resolution";
echo "maps extraction will be high-resolution"
fi
if [ "$USE_VMAPS" = "1" ] && [ "$VMAP_RES" = "-l" ]; then
echo "vmaps extraction will be high-resolution";
echo "vmaps extraction will be high-resolution"
fi
if [ "$USE_MMAPS_DELAY" != "" ]; then
echo "MMap Extraction will be started delayed by $USE_MMAPS_DELAY"
fi
echo
if [ "$1" != "a" ]
then
if [ "$1" != "a" ]; then
echo "Press (Enter) to continue, or interrupt with (CTRL+C)"
read line
fi

echo "$(date): Start extracting dataz for MaNGOS" | tee "$LOG_FILE"

## Handle log messages
if [ "$USE_AD" = "1" ];
then
if [ "$USE_AD" = "1" ]; then
echo "DBC and map files will be extracted" | tee -a "$LOG_FILE"
else
echo "DBC and map files won't be extracted!" | tee -a "$LOG_FILE"
fi
if [ "$USE_VMAPS" = "1" ]
then
if [ "$USE_VMAPS" = "1" ]; then
echo "Vmaps will be extracted" | tee -a "$LOG_FILE"
else
echo "Vmaps won't be extracted!" | tee -a "$LOG_FILE"
fi
if [ "$USE_MMAPS" = "1" ]
then
if [ "$USE_MMAPS" = "1" ]; then
echo "Mmaps will be extracted using $NUM_THREAD CPU threads" | tee -a "$LOG_FILE"
else
echo "Mmaps files won't be extracted!" | tee -a "$LOG_FILE"
Expand All @@ -250,53 +218,80 @@ echo "$(date): Start extracting MaNGOS data: DBCs/maps $USE_AD, vmaps $USE_VMAPS
echo | tee -a "$DETAIL_LOG_FILE"

## Extract dbcs and maps
if [ "$USE_AD" = "1" ]
then
echo "$(date): Start extraction of DBCs and map files..." | tee -a "$LOG_FILE"
"$PREFIX"/ad $AD_RES $AD_OPT_RES | tee -a "$DETAIL_LOG_FILE"
echo "$(date): Extracting of DBCs and map files finished" | tee -a "$LOG_FILE"
echo | tee -a "$LOG_FILE"
echo | tee -a "$DETAIL_LOG_FILE"
if [ "$USE_AD" = "1" ]; then
echo "$(date): Start extraction of DBCs and map files..." | tee -a "$LOG_FILE"
# Prepare ad arguments
set -- $AD_RES
if [ "x$CLIENT_PATH" != "x" ]; then
set -- "$@" "-i" "$CLIENT_PATH"
fi
if [ "x$OUTPUT_PATH" != "x" ] && [ -d "$OUTPUT_PATH" ]; then
set -- "$@" "-o" "$OUTPUT_PATH"
fi
file=$(mktemp)
{
"$PREFIX"/ad "$@"
echo $? >"$file"
} | tee -a "$DETAIL_LOG_FILE"
exit_code=$(cat "$file")
rm "$file"
if [ "$exit_code" -ne "0" ]; then
echo "$(date): Extraction of DBCs and map files failed with errors. Aborting extraction. See the log file for more details."
exit "$exit_code"
fi
echo "$(date): Extracting of DBCs and map files finished" | tee -a "$LOG_FILE"
echo | tee -a "$LOG_FILE"
echo | tee -a "$DETAIL_LOG_FILE"
fi

## Extract vmaps
if [ "$USE_VMAPS" = "1" ]
then
if [ "$USE_VMAPS" = "1" ]; then
# We need to save the exit code for vmap_extractor and vmap_assembler so it doesn't get swallowed by tee. For this we create a temporary file.
file=$(mktemp)
echo "$(date): Start extraction of vmaps..." | tee -a "$LOG_FILE"
# Prepare vmap_extractor arguments
set -- $VMAP_RES
if [ "x$CLIENT_PATH" != "x" ]; then
set -- "$@" "-d" "$CLIENT_PATH/Data"
fi
if [ "x$OUTPUT_PATH" != "x" ] && [ -d "$OUTPUT_PATH" ]; then
set -- "$@" "-o" "$OUTPUT_PATH"
fi
# We group command and echo to file so we can save the exit code ($?) before execution of tee overwrites it.
{ "$PREFIX"/vmap_extractor $VMAP_RES $VMAP_OPT_RES; echo $? > "$file"; } | tee -a "$DETAIL_LOG_FILE"
{
"$PREFIX"/vmap_extractor "$@"
echo $? >"$file"
} | tee -a "$DETAIL_LOG_FILE"
exit_code=$(cat "$file")
if [ "$exit_code" -ne "0" ]; then
echo "$(date): Extraction of vmaps failed with errors. Aborting extraction. See the log file for more details."
rm "$file"
exit "$exit_code"
fi
echo "$(date): Extracting of vmaps finished" | tee -a "$LOG_FILE"
if [ ! -d "${OUTPUT_PATH:-.}/vmaps" ]
then
if [ ! -d "${OUTPUT_PATH:-.}/vmaps" ]; then
mkdir "${OUTPUT_PATH:-.}/vmaps"
fi
echo "$(date): Start assembling of vmaps..." | tee -a "$LOG_FILE"
# We group command and echo to file so we can save the exit code ($?) before execution of tee overwrites it.
{ "$PREFIX"/vmap_assembler "${OUTPUT_PATH:-.}/Buildings" "${OUTPUT_PATH:-.}/vmaps"; echo $? > "$file"; } | tee -a "$DETAIL_LOG_FILE"
{
"$PREFIX"/vmap_assembler "${OUTPUT_PATH:-.}/Buildings" "${OUTPUT_PATH:-.}/vmaps"
echo $? >"$file"
} | tee -a "$DETAIL_LOG_FILE"
exit_code=$(cat "$file")
rm "$file"
if [ "$exit_code" -ne "0" ]; then
echo "$(date): Assembling of vmaps failed with errors. Aborting extraction. See the log file for more details."
rm "$file"
exit "$exit_code"
fi
rm "$file"
echo "$(date): Assembling of vmaps finished" | tee -a "$LOG_FILE"

echo | tee -a "$LOG_FILE"
echo | tee -a "$DETAIL_LOG_FILE"
fi

## Extract mmaps
if [ "$USE_MMAPS" = "1" ]
then
if [ "$USE_MMAPS" = "1" ]; then
if [ "$USE_MMAPS_DELAY" != "" ]; then
echo "Extracting of MMaps is set to be started delayed by $USE_MMAPS_DELAY"
echo "Current time: $(date)"
Expand Down
Loading