#!/usr/bin/env bash
PRODUCTNAME="OpenRGB"
VENDOR=${PRODUCTNAME}
TLD="org"
WEBSITE="https://${PRODUCTNAME,,}.${TLD}"
NAMESPACE=$(uuidgen -n @url -N ${WEBSITE} --sha1 | awk '{ print toupper($0) }')
VENDOR_ID="${TLD}.${VENDOR}"
APP_ID="${VENDOR_ID}.${PRODUCTNAME,,}"
GITURL="https://gitlab.com/CalcProgrammer1/OpenRGB/-"
GITPARAM="?inline=false"
ICONFILE="qt/OpenRGB.ico"
LICENSEFILE="scripts/License.rtf"
BANNERIMAGE="scripts/banner.bmp"
DIALOGBACKGROUND="scripts/dialog_background.bmp"
PROJECT_FILE="OpenRGB.pro"
XMLOUTFILE=${PRODUCTNAME,,}".wxs"
VERSION=$(qmake ${PROJECT_FILE} 2>&1 | grep VERSION_WIX | cut -d ':' -f 3 | tr -d ' ')
#If the suffix is not empty set the channel to "-git"
CHANNEL=$(grep SUFFIX\ ${PROJECT_FILE} | cut -d= -f 2)
if [[ -n $CHANNEL ]];
then
CHANNEL="-git"
fi
#The Upgrade code has to be consistent to allow upgrades between channels
#This value is roughly equivalent to "provides" in Linux packaging
UPGRADECODE=$(uuidgen -n ${NAMESPACE} -N ${APP_ID} --sha1 | awk '{ print toupper($0) }')
#The ProductID will be unique per build
PRODUCTCOMMENT="Open source RGB lighting control that doesn't depend on manufacturer software."
#Print Metadata to the log
echo -e "Icon URL:\t" $GITURL$ICONFILE
echo -e "License URL:\t" $GITURL$LICENSEFILE
echo -e "AppID - Channel:\t" ${APP_ID} " - " ${CHANNEL}
echo -e "Upgrade UUID:\t" ${UPGRADECODE}
echo -e "Product Name:\t" ${PRODUCTNAME}
echo -e "Vendor - VendorID:\t\t" ${VENDOR} " - " ${VENDOR_ID}
echo -e "Version:\t" ${VERSION}
#Wix and / or Wine have issues with the mixed upper and lower case letters
WORKING_PATH="orgb/"
BUILT_PATH="OpenRGB Windows 64-bit/"
mv -T "${BUILT_PATH}" ${WORKING_PATH}
count=1
#############################################################
# Build file list for files in the working path #
#############################################################
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 \n"
elif [ -d "$file" ] ; then
#If this is a directory then we need to add another component
COMPONENTS="${COMPONENTS} \n"
TEMP=" \n \n"
for file2 in "$file"/*;
do
filename2=$(basename "$file2")
TEMP="$TEMP \n"
count=$((count+1))
done
DIRECTORIES="$DIRECTORIES$TEMP \n \n"
else
#Any other file to files list
FILES="$FILES \n"
count=$((count+1))
fi
done
#############################################################
# Create the Wix XML file #
# Set IFS to the empty string to allow arbitrary spacing #
# within the XML_FILE variable, then set it back to a #
# space character after we print the XML file #
#############################################################
IFS=""
XML_FILE=""
XML_FILE+="\r\n"
XML_FILE+="\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" VersionNT64\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+="\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+="${FILES}\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+="${DIRECTORIES}\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+="${COMPONENTS}\r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=" \r\n"
XML_FILE+=""
echo -e $XML_FILE > $XMLOUTFILE
IFS=" "
#############################################################
# Print the XML for debugging #
#############################################################
cat $XMLOUTFILE
#############################################################
# Once the XML file manifest is created, create the package #
#############################################################
candle -arch x64 ${PRODUCTNAME,,}.wxs
light -sval -ext WixUIExtension ${PRODUCTNAME,,}.wixobj -out ${PRODUCTNAME}_Windows_64.msi