2015-10-06 07:20:58 +02:00
|
|
|
#!/bin/bash -e
|
2012-12-03 19:00:17 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# VCMI data builder script
|
|
|
|
# Extracts game data from various sources and creates a tree with the right files
|
|
|
|
#
|
|
|
|
# Authors: listed in file AUTHORS in main folder
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
|
|
|
|
# no console arguments - print help
|
|
|
|
if [ $# -eq 0 ] ; then
|
|
|
|
print_help=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# command line parsing
|
|
|
|
# can't use system getopt which is not cross-platform (BSD/Mac)
|
|
|
|
# can't use built-in getopts which can't parse long options (too difficult to avoid - e.g. CD1/CD2)
|
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
--cd1) cd1_dir=$2 ; shift 2 ;;
|
|
|
|
--cd2) cd2_dir=$2 ; shift 2 ;;
|
|
|
|
--gog) gog_file=$2 ; shift 2 ;;
|
|
|
|
--data) data_dir=$2 ; shift 2 ;;
|
2013-02-09 15:34:49 +03:00
|
|
|
--dest) dest_dir=$2 ; shift 2 ;;
|
2013-04-25 17:03:35 +03:00
|
|
|
--convertMP3) useffmpeg=true; shift 1 ;;
|
2014-09-21 19:42:05 +03:00
|
|
|
# --download) download=true ; shift 1 ;;
|
2012-12-03 19:00:17 +03:00
|
|
|
--validate) validate=true ; shift 1 ;;
|
|
|
|
*) print_help=true ; shift 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -n "$print_help" ]]
|
|
|
|
then
|
|
|
|
echo "VCMI data builder utility"
|
|
|
|
echo "Usage: vcmibuilder <options>"
|
|
|
|
echo "Options:"
|
|
|
|
echo " --cd1 DIRECTORY " "Path to mounted first CD with Heroes 3 install files"
|
|
|
|
echo " " "Requires unshield"
|
|
|
|
echo
|
|
|
|
echo " --cd2 DIRECTORY " "Path to second CD with Heroes 3 data files."
|
|
|
|
echo
|
|
|
|
echo " --gog EXECUTABLE " "Path to gog.com executable"
|
|
|
|
echo " " "Requires innoextract ( http://constexpr.org/innoextract/ )"
|
|
|
|
echo
|
|
|
|
echo " --data DIRECTORY " "Path to installed Heroes 3 data"
|
|
|
|
echo
|
2013-04-25 17:03:35 +03:00
|
|
|
echo " --convertMP3 " "Convert all mp3 files into ogg/vorbis"
|
2014-03-20 21:17:40 +03:00
|
|
|
echo " " "Requires ffmpeg or avconv"
|
2013-04-25 17:03:35 +03:00
|
|
|
echo
|
2014-09-21 19:42:05 +03:00
|
|
|
# echo " --download " "Automatically download optional package using wget"
|
|
|
|
# echo " " "Requires wget and Internet connection"
|
|
|
|
# echo
|
2014-11-16 19:48:29 +02:00
|
|
|
echo " --dest DIRECTORY " "Path where resulting data will be placed. Default is ~/.local/share/vcmi"
|
2013-02-09 15:34:49 +03:00
|
|
|
echo
|
2013-04-25 17:03:35 +03:00
|
|
|
echo " --validate " "Run basic validness checks"
|
2013-02-09 15:34:49 +03:00
|
|
|
exit 0
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
2018-01-28 07:00:03 +02:00
|
|
|
# test if a program version ($1) is less than the required one ($2)
|
|
|
|
verlt() {
|
|
|
|
[ "$1" = "$2" ] && return 1 || \
|
|
|
|
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
|
|
|
|
}
|
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
# test presence of program $1, $2 will be passed as parameters to test presence
|
|
|
|
test_utility ()
|
|
|
|
{
|
|
|
|
$1 $2 > /dev/null 2>&1 || { echo "$1 was not found. Please install it" 1>&2 ; exit 1; }
|
2015-10-06 07:20:58 +02:00
|
|
|
}
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2018-01-28 07:00:03 +02:00
|
|
|
# print error message and exit
|
2012-12-03 19:00:17 +03:00
|
|
|
fail ()
|
|
|
|
{
|
|
|
|
$2
|
|
|
|
echo "$1" 1>&2
|
2013-02-09 15:34:49 +03:00
|
|
|
rm -rf "$temp_dir"
|
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# print warning to stderr.
|
|
|
|
warning ()
|
|
|
|
{
|
|
|
|
echo "$1" 1>&2
|
|
|
|
warn_user=true
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if selected options are correct.
|
|
|
|
|
|
|
|
if [[ -n "$data_dir" ]]
|
|
|
|
then
|
|
|
|
if [[ -n "$gog_file" ]] || [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
|
|
|
|
then
|
|
|
|
warning "Warning: Installed data dir was specified. Both gog and cd options will be ignored"
|
|
|
|
unset gog_file cd1_dir cd2_dir
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$gog_file" ]]
|
|
|
|
then
|
|
|
|
test_utility "innoextract"
|
|
|
|
if [[ -n "$cd1_dir" ]] || [[ -n "$cd2_dir" ]]
|
|
|
|
then
|
|
|
|
warning "Warning: Both gog and cd options were specified. cd options will be ignored"
|
|
|
|
unset cd1_dir cd2_dir
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-01-28 07:00:03 +02:00
|
|
|
if [[ -n "$gog_file" ]]
|
|
|
|
then
|
|
|
|
currentver="$(innoextract --version | head -n1 | cut -d ' ' -f2)"
|
|
|
|
requiredver="1.6"
|
|
|
|
if verlt $currentver $requiredver;
|
|
|
|
then
|
|
|
|
fail "innoextract version is $currentver, update it to version $requiredver or higher"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-10-06 07:20:58 +02:00
|
|
|
if [[ -n "$useffmpeg" ]]
|
2013-04-25 17:03:35 +03:00
|
|
|
then
|
2014-03-20 21:17:40 +03:00
|
|
|
ffmpeg -version > /dev/null 2>&1 && AUDIO_CONV=ffmpeg
|
|
|
|
avconv -version > /dev/null 2>&1 && AUDIO_CONV=avconv
|
|
|
|
if [[ -z "$AUDIO_CONV" ]]
|
|
|
|
then
|
|
|
|
fail "Error: neither ffmpeg nor avconv were found. Please install it."
|
|
|
|
fi
|
2013-04-25 17:03:35 +03:00
|
|
|
fi
|
|
|
|
|
2015-10-06 07:20:58 +02:00
|
|
|
if [[ -n "$cd1_dir" ]]
|
2012-12-03 19:00:17 +03:00
|
|
|
then
|
|
|
|
test_utility "unshield" "-V"
|
|
|
|
fi
|
|
|
|
|
2014-09-21 19:42:05 +03:00
|
|
|
if [[ -n "$download" ]]
|
2012-12-03 19:00:17 +03:00
|
|
|
then
|
|
|
|
test_utility "unzip"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$gog_file" ]] && [[ -z "$data_dir" ]] && ( [[ -z "$cd1_dir" ]] || [[ -z "$cd2_dir" ]] )
|
|
|
|
then
|
|
|
|
warning "Warning: Selected options will not create complete Heroes 3 data!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if at least one warning has been printed - ask for confirmation
|
|
|
|
if [[ -n "$warn_user" ]]
|
|
|
|
then
|
|
|
|
read -p "Do you wish to continue? (y/n) " -n 1
|
|
|
|
echo #print eol
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-02-09 15:34:49 +03:00
|
|
|
if [[ -z "$dest_dir" ]]
|
|
|
|
then
|
2014-03-04 17:51:10 +03:00
|
|
|
if [[ -z "$XDG_DATA_HOME" ]]
|
|
|
|
then
|
|
|
|
dest_dir="$HOME/.local/share/vcmi"
|
|
|
|
else
|
|
|
|
dest_dir="$XDG_DATA_HOME/vcmi"
|
|
|
|
fi
|
2013-02-09 15:34:49 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
temp_dir="$dest_dir"/buildertmp
|
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
# start installation
|
|
|
|
|
2013-02-09 15:34:49 +03:00
|
|
|
mkdir -p "$dest_dir"
|
|
|
|
mkdir -p "$temp_dir"
|
2012-12-03 19:00:17 +03:00
|
|
|
|
|
|
|
if [[ -n "$gog_file" ]]
|
|
|
|
then
|
2020-09-12 14:34:18 +02:00
|
|
|
data_dir="$temp_dir"/app
|
2022-04-28 09:53:51 +02:00
|
|
|
mkdir -p "$data_dir"
|
2020-09-12 14:34:18 +02:00
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
# innoextract always reports error (iconv 84 error). Just test file for presence
|
2013-02-09 15:34:49 +03:00
|
|
|
test -f "$gog_file" || fail "Error: gog.com executable was not found!"
|
2015-10-06 07:20:58 +02:00
|
|
|
gog_file="$(cd "$(dirname "$gog_file")"; pwd)/$(basename "$gog_file")"
|
2020-09-12 14:34:18 +02:00
|
|
|
cd "$data_dir" && innoextract "$gog_file"
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$cd1_dir" ]]
|
|
|
|
then
|
2013-02-09 15:34:49 +03:00
|
|
|
data_dir="$temp_dir"/cddir
|
2015-10-06 07:20:58 +02:00
|
|
|
mkdir -p "$data_dir"
|
2013-02-09 15:34:49 +03:00
|
|
|
unshield -d "$data_dir" x "$cd1_dir"/_setup/data1.cab || fail "Error: failed to extract from Install Shield installer!" "rm -rf $data_dir"
|
2013-02-23 15:22:23 +03:00
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
# a bit tricky - different releases have different root directory. Move extracted files to data_dir
|
2015-10-06 07:20:58 +02:00
|
|
|
if [ -d "$data_dir"/Heroes3 ]
|
2012-12-03 19:00:17 +03:00
|
|
|
then
|
2015-10-06 07:20:58 +02:00
|
|
|
mv "$data_dir"/Heroes3/* "$data_dir"
|
|
|
|
elif [ -d "$data_dir""/Program_Files" ]
|
2012-12-03 19:00:17 +03:00
|
|
|
then
|
2015-10-06 07:20:58 +02:00
|
|
|
mv "$data_dir"/Program_Files/* "$data_dir"
|
2014-11-18 10:55:27 +02:00
|
|
|
elif [ -d "$data_dir""/LangInde_Program_Files" ]
|
|
|
|
then
|
|
|
|
mv "$data_dir"/LangInde_Program_Files/* "$data_dir"
|
2012-12-03 19:00:17 +03:00
|
|
|
else
|
|
|
|
echo "Error: failed to find extracted game files!"
|
|
|
|
echo "Extracted directories are: "
|
2015-10-06 07:20:58 +02:00
|
|
|
ls -la "$data_dir"
|
2012-12-03 19:00:17 +03:00
|
|
|
echo "Please report this on vcmi.eu"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$cd2_dir" ]]
|
|
|
|
then
|
2013-02-09 15:34:49 +03:00
|
|
|
mkdir -p "$dest_dir"/Data
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2013-02-09 15:34:49 +03:00
|
|
|
if [ -d "$cd2_dir"/heroes3 ]
|
2012-12-03 19:00:17 +03:00
|
|
|
then
|
2013-02-27 18:46:14 +03:00
|
|
|
cp "$cd2_dir"/heroes3/Data/Heroes3.vid "$dest_dir"/Data/Heroes3.vid
|
2013-02-09 15:34:49 +03:00
|
|
|
cp "$cd2_dir"/heroes3/Data/Heroes3.snd "$dest_dir"/Data/Heroes3-cd2.snd
|
2012-12-03 19:00:17 +03:00
|
|
|
else
|
2013-02-27 18:46:14 +03:00
|
|
|
cp "$cd2_dir"/Heroes3/Data/Heroes3.vid "$dest_dir"/Data/Heroes3.vid
|
2013-02-09 15:34:49 +03:00
|
|
|
cp "$cd2_dir"/Heroes3/Data/Heroes3.snd "$dest_dir"/Data/Heroes3-cd2.snd
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$data_dir" ]]
|
|
|
|
then
|
|
|
|
# this folder is named differently from time to time
|
2014-11-28 18:43:16 +02:00
|
|
|
# bash also has `shopt -s nocaseglob` but we don't want this to
|
|
|
|
# accidentally influence other parts of this script
|
|
|
|
# since the directory names are short, we use this pattern matching
|
2015-10-06 07:20:58 +02:00
|
|
|
cp -r "$data_dir"/[Dd][Aa][Tt][Aa] "$dest_dir"
|
2014-11-28 18:43:16 +02:00
|
|
|
cp -r "$data_dir"/[Mm][Aa][Pp][Ss] "$dest_dir"
|
|
|
|
cp -r "$data_dir"/[Mm][Pp]3 "$dest_dir"
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$download" ]]
|
|
|
|
then
|
2014-09-21 19:42:05 +03:00
|
|
|
wget "http://download.vcmi.eu/core.zip" -O "$temp_dir"/core.zip || fail "Error: failed to download VCMI archive!" "rm -f core.zip"
|
|
|
|
vcmi_archive="$temp_dir"/core.zip
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$vcmi_archive" ]]
|
|
|
|
then
|
|
|
|
echo "decompressing $vcmi_archive"
|
2013-02-09 15:34:49 +03:00
|
|
|
unzip -qo "$vcmi_archive" -d "$dest_dir" || fail "Error: failed to extract VCMI archive!"
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
if [[ -n "$useffmpeg" ]]
|
|
|
|
then
|
2014-09-21 19:42:05 +03:00
|
|
|
# now when all music files were installed convert them to ogg
|
2013-04-25 17:03:35 +03:00
|
|
|
echo "Converting mp3 files..."
|
|
|
|
|
|
|
|
OIFS="$IFS"
|
2015-10-06 07:20:58 +02:00
|
|
|
IFS=$'\n'
|
2013-04-25 17:03:35 +03:00
|
|
|
|
2014-03-08 19:05:23 +03:00
|
|
|
for file in `find "$dest_dir" -type f -iname "*.mp3"`
|
2013-04-25 17:03:35 +03:00
|
|
|
do
|
|
|
|
echo "Converting $file"
|
|
|
|
ogg=${file%.*}
|
2014-03-20 21:17:40 +03:00
|
|
|
$AUDIO_CONV -y -i "$file" -acodec libvorbis "$ogg".ogg 2>/dev/null || fail "Error: failed to convert $file to ogg/vorbis using $AUDIO_CONV" "rm -f "$ogg".ogg"
|
2013-04-25 17:03:35 +03:00
|
|
|
rm -f $file
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS="$OIFS"
|
|
|
|
fi
|
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
if [[ -n "$validate" ]]
|
|
|
|
then
|
2013-02-09 15:34:49 +03:00
|
|
|
test -f "$dest_dir"/Data/H3bitmap.lod || fail "Error: Heroes 3 data files are missing!"
|
|
|
|
test -f "$dest_dir"/Data/H3sprite.lod || fail "Error: Heroes 3 data files are missing!"
|
|
|
|
test -f "$dest_dir"/Data/VIDEO.VID || fail "Error: Heroes 3 data files (CD2) are missing!"
|
|
|
|
test -d "$dest_dir"/Mods/vcmi/Data || fail "Error: VCMI data files are missing!"
|
2012-12-03 19:00:17 +03:00
|
|
|
fi
|
|
|
|
|
2013-02-09 15:34:49 +03:00
|
|
|
rm -rf "$temp_dir"
|