#!/usr/bin/env bash

WINEPREFIX=~/.wine
export WINEPREFIX

set -e

echo "Checking that dxvk-setup is present..."
test -f /usr/bin/dxvk-setup

if [[ -d "$WINEPREFIX" ]]; then
    echo "Removing existing wine prefix..."
    rm -rf $WINEPREFIX
fi

echo "Checking that there is nothing at WINEPREFIX..."
test ! -d $WINEPREFIX

echo "Creating a wine prefix..."
wine64 wineboot

echo "Checking that a wine prefix was created..."
test -d $WINEPREFIX

echo "Running dxvk-setup..."
dxvk-setup install --yes

unix_64bit_dlls_path=$( wine winepath -u c:\\windows\\sysnative 2> /dev/null )
unix_32bit_dlls_path=$( wine winepath -u c:\\windows\\system32 2> /dev/null )

dlls=(
    "dxgi.dll"
    "d3d10.dll"
    "d3d10_1.dll"
    "d3d10core.dll"
    "d3d11.dll"
)

for file in "${dlls[@]}"; do
    full_64bit_file_path=$unix_64bit_dlls_path/$file
	echo "Checking for $full_64bit_file_path..."
    test -f $full_64bit_file_path

    full_32bit_file_path=$unix_32bit_dlls_path/$file
	echo "Checking for $full_32bit_file_path..."
    test -f $full_32bit_file_path
done

echo "Cleaing up WINEPREFIX..."
rm -rf $WINEPREFIX

echo "Checking that WINEPREFIX was removed..."
test ! -d $WINEPREFIX
