81 lines
2.3 KiB
Bash
81 lines
2.3 KiB
Bash
#!/bin/bash
|
|
# rich presence and track loading handler to a Wine installation of foobar2000
|
|
|
|
# declare variables
|
|
enque=false
|
|
|
|
#paths
|
|
|
|
FOOBAR_HOME="$HOME/foobar on linux/foobar2000"
|
|
#the folder the foobar2000 executable folder is located in
|
|
|
|
# trigger wine discord IPC bridge script (optional)
|
|
<<bridge
|
|
|
|
PATH_BRIDGE="$HOME/foobar on linux"
|
|
#the folder the bridge executable folder is located in
|
|
|
|
{
|
|
# path to bridge executable
|
|
# Define the path to the flag file
|
|
FLAG_FILE="/tmp/.discordwineipcbridge_flag"
|
|
|
|
#Check if the flag file exists
|
|
if [ -f "$FLAG_FILE" ]; then
|
|
echo "bridge is active."
|
|
exit 1
|
|
fi
|
|
|
|
#make flag
|
|
touch "$FLAG_FILE"
|
|
|
|
# run ipc bridge
|
|
wine "$PATH_BRIDGE/bridge.exe"
|
|
|
|
# delete flag file when the ipc bridge dies for no reason eventually
|
|
rm $FLAG_FILE
|
|
} &
|
|
bridge
|
|
|
|
# Go through args, convert paths to existing files to Windows style without using winepath (cause its bad and doesnt work properly with long paths)
|
|
# i barely know how this thing works so if you have issues good luck
|
|
# also contains enque logic (idk this bad code but i dont care)
|
|
i=0
|
|
args=()
|
|
|
|
for arg in "$@"; do
|
|
# If the argument is "enque", skip it and don't add it to the args array
|
|
if [[ "$arg" == "enque" ]]; then
|
|
enque=true
|
|
continue
|
|
fi
|
|
# If the argument is a valid file or directory, handle it as a path
|
|
if [ -e "$arg" ]; then
|
|
if [[ "$arg" =~ ^/mnt/[a-zA-Z]/ ]]; then
|
|
# Convert /mnt/c/... to C:\...
|
|
win_path=$(echo "$arg" | sed -E 's|^/mnt/([a-zA-Z])|\\\1|;s|/|\\|g')
|
|
else
|
|
# For other Unix paths, replace slashes with backslashes
|
|
win_path=$(echo "$arg" | sed 's|/|\\|g')
|
|
fi
|
|
args[$i]="$win_path"
|
|
else
|
|
# If it's not a valid file, just use the argument as is
|
|
args[$i]="$arg"
|
|
fi
|
|
|
|
((++i))
|
|
done
|
|
|
|
#add drive letter and make it into a UNC path or smth i forgor
|
|
for i in "${!args[@]}"; do
|
|
args[$i]="\\\\?\\Z:\\${args[$i]}"
|
|
done
|
|
|
|
# Launch foobar2000 with a high process prio to prevent audio lag and hitching (only really noticable when doing high processor demanding tasks)
|
|
# if the argument "enque" has been submitted it will enque
|
|
if $enque; then
|
|
nice -n -20 wine "$FOOBAR_HOME/foobar2000.exe" "/add" "${args[@]}" 2>/dev/null &
|
|
else
|
|
nice -n -20 wine "$FOOBAR_HOME/foobar2000.exe" "${args[@]}" 2>/dev/null &
|
|
fi
|