#!/usr/bin/env bash
GITURL="https://gitlab.com/CalcProgrammer1/OpenRGB/-"
GITPARAM="?inline=false"
WEBSITE="www.openrgb.org"
ICONFILE="qt/OpenRGB.ico"
LICENSEFILE="scripts/License.rtf"
ZIP="/jobs/artifacts/master/download?job=Windows+64"
PRODUCTID=$(uuidgen -n @url -N ${WEBSITE} --sha1 | awk '{ print toupper($0) }')
PRODUCTNAME="OpenRGB"
VENDOR=$PRODUCTNAME
PRODUCTCOMMENT="Open source RGB lighting control that doesn't depend on manufacturer software."
MAJOR=$(grep "MAJOR\ *=" OpenRGB.pro | cut -d= -f 2 | tr -d [:space:])
MINOR=$(grep "MINOR\ *=" OpenRGB.pro | cut -d= -f 2 | tr -d [:space:])
REVISION=$(grep "REVISION\ *=" OpenRGB.pro | cut -d= -f 2 | tr -d [:space:])
#The commit count since last tag. The commit ID can be added with group \3 however Wix only accepts integers
RELEASE=$(git describe --tags --abbrev=8 | sed -E "s/(.*)-([0-9]*)-g(\w*)/\2/g")
VERSION="${MAJOR}.${MINOR}.${REVISION}.${RELEASE}"
XMLOUTFILE=${PRODUCTNAME,,}".wxs"
echo -e "Zip URL:\t" $GITURL$ZIP
echo -e "Icon URL:\t" $GITURL$ICONFILE
echo -e "License URL:\t" $GITURL$LICENSEFILE
echo -e "Product UUID:\t" $PRODUCTID
echo -e "Product:\t" $PRODUCTNAME
echo -e "Vendor:\t\t" $VENDOR
echo -e "Version:\t" $VERSION
ICONID=$(basename "$ICONFILE")
#echo -e "\n\nGetting ${PRODUCTNAME}'s icon from repo:\t"$ICONID
#wget -O ${ICONID} "${GITURL}${ICONFILE}${GITPARAM}"
LICENSEID=$(basename "$LICENSEFILE")
#echo -e "\nGetting ${PRODUCTNAME}'s icon from repo:\t"$LICENSEID
#wget -O ${LICENSEID} "${GITURL}${LICENSEFILE}${GITPARAM}"
#echo -e "\nProcessing latest Windows 64 package from " $GITURL
#ZIPFILE=${PRODUCTNAME,,}".zip";
#echo -e "Zipfile:\t${ZIPFILE}\nZip:\t\t${ZIP}"
#wget -O ${ZIPFILE} "${GITURL}${ZIP}"
#unzip ${ZIPFILE}
#Wix and / or Wine have issues with the mixed upper and lower case letters
WORKING_PATH="orgb/"
ZIP_PATH="OpenRGB Windows 64-bit/"
mv -T "${ZIP_PATH}" ${WORKING_PATH}
EXTENSION="orp"
SAVE_FILE="${PRODUCTNAME}.${EXTENSION}"
count=1
for file in "$WORKING_PATH"/*;
do
filename=$(basename "$file")
if [ $filename == "${PRODUCTNAME}.exe" ] ; then
#If this is the executable treat as a special case as we need the reference for later
EXE_ID=${PRODUCTNAME}00
EXE_FILE=${filename}
#Add special entry to files list
FILES="$FILES\t\t\t\t\t\n"
elif [ -d "$file" ] ; then
#If this is a directory then we need to add another component
COMPONENTS="${COMPONENTS}\t\t\t\n"
TEMP="\t\t\t\t\n\t\t\t\t\t\n"
for file2 in "$file"/*;
do
filename2=$(basename "$file2")
TEMP="$TEMP\t\t\t\t\t\t\n"
count=$((count+1))
done
DIRECTORIES="$DIRECTORIES$TEMP\t\t\t\t\t\n\t\t\t\t\n"
else
#Any other file to files list
FILES="$FILES\t\t\t\t\t\n"
count=$((count+1))
fi
done
echo -e "Building XML:\t" $XMLOUTFILE
XML_PACKAGE="\t\n"
XML_MEDIA="\t\n"
XML_CONDITIONS="\tVersionNT64\n"
XML_ACTION_RUNAS_ADMIN="\t\n"
XML_ACTION_FIRSTRUN="\t\n"
XML_ICON="\t\n"
XML_ACTIONS_EXECUTE="\t\n\t\tNOT Installed\n\t\tNOT Installed\n\t\n"
XML_WIX_UI="\t\n\t\n\t\n"
XML_METADATA="$XML_PACKAGE $XML_MEDIA $XML_CONDITIONS $XML_ACTION_RUNAS_ADMIN $XML_ACTION_FIRSTRUN $XML_ICON $XML_ACTIONS_EXECUTE $XML_WIX_UI"
XML_STARTMENU="\t\t\n"
XML_SHORTCUT="\t\t\t\t\t\n"
XML_ASSOCIATE_FILE="\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n"
XML_DIRECTORIES="\t\n\t\t\n\t\t\t\n\t\t\t\t\n$FILES\n$XML_SHORTCUT\n$XML_ASSOCIATE_FILE\t\t\t\t\n$DIRECTORIES\t\t\t\n\t\t\n$XML_STARTMENU\t\n"
XML_COMPONENTS="\t\n\t\t\n\t\t\t\n$COMPONENTS\t\t\t\n\t\t\n\t\n"
XML_DATA="$XML_DIRECTORIES $XML_COMPONENTS"
#Wipe out any previous XMLOUTFILE and add the header
XML_HEADER="\n\n"
XML_PRODUCT="\t\n$XML_METADATA\n$XML_DATA\n\t\n"
echo -e $XML_HEADER $XML_PRODUCT > $XMLOUTFILE
echo -e "\t...Done!\n\n"
#Once the XML file manifest is created create the package
candle -arch x64 ${PRODUCTNAME,,}.wxs
light -sval -ext WixUIExtension ${PRODUCTNAME,,}.wixobj