#!/bin/bash
# Date : 2024-08-18
# Last revision : see the changelog below
# Wine version used : see the changelog below
# Distribution used to test : macOS Catalina 10.15.4. CPU:Intel I7 5820K. GPU: NVidia GTX760.
# Author : Dvbtec
# License : Shareware (30 day trial)
# Script license : Freeware
# Tested with TS-Doctor 4.1.5 

[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"

TITLE="TS-Doctor 4.1"
PREFIX="TSDoctor4"
EDITOR=""
AUTHOR="Dvbtec"
APP_URL="https://www.cypheros.de/eng/tsdoc4.html"
LOGO="https://www.cypheros.de/img/playonmac.png"
BANNER="https://i.imgur.com/YqdIiG1.png"
DOWNLOAD_URL="https://www.cypheros.de/download.php?f=TSDoctor4Installer.exe"
OSVERSION="win10"
WINEVERSION="21.0.0-cx"
   
STARTPATH="$PWD"
POL_Debug_Message "Start path: $STARTPATH"

#Setup Image
POL_GetSetupImages "$LOGO" "$BANNER" "$TITLE"

# Starting the script
POL_SetupWindow_Init

# Starting debugging API
POL_Debug_Init

# Welcome message
POL_SetupWindow_presentation "$TITLE" "$EDITOR" "$APP_URL" "$AUTHOR" "$PREFIX"

# PlayOnLinux Version Check
POL_RequiredVersion 4.4.4 || POL_Debug_Fatal "$(eval_gettext 'TITLE wont work with $APPLICATION_TITLE $VERSION\nPlease update!')"

# Installer is 32bit and can install 32bit or 64bit version of the application under Windows
# We will have to force 32bit under a 64bit OS
POL_System_SetArch "x86onx64"

## Prefix Creation   
POL_Wine_SelectPrefix "$PREFIX"
POL_Wine_PrefixCreate "$WINEVERSION"
Set_OS "$OSVERSION"

POL_System_TmpCreate "$PREFIX"

## Install dependencies
#Font smoothing
POL_Call POL_Function_FontsSmoothRGB

POL_SetupWindow_InstallMethod "LOCAL,DOWNLOAD"

if [ "$INSTALL_METHOD" = "LOCAL" ]
then
    POL_SetupWindow_browse "Please select the installation file to run." "TS-Doctor 4.1"
    INSTALLER="$APP_ANSWER"
    
    #Change directory to prevent error of regserv32 while registering directshow filters
    cd "$POL_System_TmpDir"
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
then
    cd "$POL_System_TmpDir"
    POL_System_wget "$DOWNLOAD_URL"
    POL_Wine_WaitBefore "$TITLE"
    mv "download.php?f=TSDoctor4Installer.exe" "TSDoctor4Installer.exe"
    INSTALLER="$POL_System_TmpDir/TSDoctor4Installer.exe"
fi

# Install Program
POL_Debug_Message "Installer: $INSTALLER"
POL_Wine "$INSTALLER"
POL_Wine_WaitBefore "$TITLE"

POL_System_TmpDelete

POL_Shortcut "TSDoctor.exe" "TS-Doctor 4.1"
POL_Shortcut "CTSPlayer.exe" "TS-Player 1.1"

POL_SetupWindow_Close
exit 0
