#!/bin/bash

EXPORTID=37

#wine like patch:
MPQAPP="Z:\\a\\www\\wowpreklad\\Modules\\Export\\mpq.exe"
TMP="Z:\\a\\www\\wowpreklad\\tmp\\mpq\\"
MPQFILENAME="patch-5.MPQ"
MPQARCH="${TMP}${MPQFILENAME}"
#linux patch:
TMPDIR="/a/www/wowpreklad/tmp/"
WORKDIR="${TMPDIR}mpq"
           
echo "==================================="
echo "Workdir: $WORKDIR"
echo "==================================="
cd $WORKDIR
echo "==================================="
echo "Export files from database:"
echo "==================================="
echo "Lua scripty:"
php /a/www/wowpreklad/Modules/Export/cmdmpqexport.php lua=$EXPORTID
echo "Dbc soubory:"
php /a/www/wowpreklad/Modules/Export/cmdmpqexport.php dbc=$EXPORTID
echo "Addon:"
php /a/www/wowpreklad/Modules/Export/cmdmpqexport.php addon=$EXPORTID

echo "==================================="
echo "Generation Readme file:"
echo "==================================="
php /a/www/wowpreklad/Modules/Export/cmdmpqexport.php ExportId=$EXPORTID > CzechWoW.htm 2> /dev/null
echo "Hotovo"

echo "==================================="
echo "Copy files to tmp:"
echo "==================================="
mkdir CzWoW -p
mkdir dbc -p
mkdir lua -p
cp ${TMPDIR}Export/${EXPORTID}/lua/* lua/ -R 
cp ${TMPDIR}Export/${EXPORTID}/dbc/* dbc/ -R 
cp ${TMPDIR}Export/${EXPORTID}/CzWoW/* CzWoW / -R 
echo "hotovo"

echo "==================================="
echo "Archive files to $MPQFILENAME :" 
echo "==================================="
for f in dbc/*.dbc
do
  wine cmd /C "$MPQAPP patch-5.MPQ DBFilesClient\\$(basename ${f}) ${f}";
done

for f in lua/Global*.lua      
do
                                                
  wine cmd /C "$MPQAPP patch-5.MPQ Interface\\FrameXML\\$(basename ${f}) ${f}";
done
for f in lua/Glue*.lua
do
  wine cmd /C "$MPQAPP patch-5.MPQ Interface\\GlueXML\\$(basename ${f}) ${f}";
done
echo "==================================="
echo "Creating Instalation file:"
echo "==================================="

makensis Instalace_CzechWoW.nsi

echo "HOTOVO!" 
 
