2025-01-23 02:23:47 +00:00
# Source the global.sh script if not already sourced
if [ -z " ${ GLOBAL_SOURCED +x } " ] ; then
source /app/libexec/global.sh
fi
2024-03-19 23:26:35 +00:00
2023-12-19 11:43:08 +00:00
# Define the IWAD files list
2023-11-24 13:01:40 +00:00
IWAD_FILES = ( "DOOM1.WAD" "DOOM.WAD" "DOOM2.WAD" "DOOM2F.WAD" "DOOM64.WAD" "TNT.WAD"
"PLUTONIA.WAD" "HERETIC1.WAD" "HERETIC.WAD" "HEXEN.WAD" "HEXDD.WAD"
"STRIFE0.WAD" "STRIFE1.WAD" "VOICES.WAD" "CHEX.WAD"
2023-12-19 11:43:08 +00:00
"CHEX3.WAD" "HACX.WAD" "freedoom1.wad" "freedoom2.wad" "freedm.wad"
"doom_complete.pk3"
)
2023-11-23 09:59:00 +00:00
2023-12-19 11:43:08 +00:00
# Function to check if a file is an IWAD
is_iwad( ) {
local file = " $1 "
2023-12-19 12:56:53 +00:00
local lowercase_file = " $( basename " ${ file ,, } " ) "
2025-01-23 02:23:47 +00:00
# Loop through the list of IWAD files
2023-12-19 11:43:08 +00:00
for iwad in " ${ IWAD_FILES [@] } " ; do
2025-01-23 02:23:47 +00:00
# Check if the lowercase version of the IWAD file matches the input file
2023-12-19 12:56:53 +00:00
if [ [ " ${ iwad ,, } " = = " $lowercase_file " ] ] ; then
2023-12-19 11:43:08 +00:00
echo "true"
return
fi
done
echo "false"
}
2023-11-23 15:11:55 +00:00
2023-12-19 11:43:08 +00:00
# Function to search for files recursively
search_file_recursive( ) {
local file = " $1 "
local directory = " $2 "
local found_file = ""
# Check if the file exists in the current directory
if [ [ -e " $directory / $file " ] ] ; then
found_file = " $directory / $file "
else
# Search recursively
2023-12-19 12:56:53 +00:00
local lowercase_file = " $( echo " $file " | tr '[:upper:]' '[:lower:]' ) "
found_file = $( find " $directory " -type f -iname " $lowercase_file " | head -n 1)
2023-12-19 11:43:08 +00:00
fi
echo " $found_file "
}
2023-11-30 08:37:26 +00:00
2023-12-19 11:43:08 +00:00
# Main script
2025-01-23 02:23:47 +00:00
log d "RetroDECK GZDOOM wrapper init"
# Check if the filename contains a single quote
if [ [ " $1 " = = *"'" * ] ] ; then
log e " Invalid filename: \" $1 \" contains a single quote.\nPlease rename the file in a proper way before continuing. "
rd_zenity --error --no-wrap \
--window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK" \
--text= " <span foreground=' $purple '><b>Invalid filename\n\n</b></span>\" $1 \" contains a single quote.\nPlease rename the file in a proper way before continuing. "
exit 1
fi
2023-12-19 11:43:08 +00:00
# Check if $1 is not a .doom file
if [ [ " ${ 1 ##*. } " != "doom" ] ] ; then
# Check if the file is in the IWAD list
if [ [ $( is_iwad " $1 " ) = = "true" ] ] ; then
command = " gzdoom -config /var/config/gzdoom/gzdoom.ini -iwad $1 "
2023-11-30 08:37:26 +00:00
else
2023-12-19 11:43:08 +00:00
command = " gzdoom -config /var/config/gzdoom/gzdoom.ini -file $1 "
2023-11-30 08:37:26 +00:00
fi
2023-12-19 11:43:08 +00:00
# Log the command
2024-01-04 16:34:02 +00:00
log i " Loading: \" $1 \" "
log i " Executing command \" $command \" "
2023-12-19 11:43:08 +00:00
2025-01-23 02:23:47 +00:00
# Execute the command with double quotes
2023-12-19 11:43:08 +00:00
eval " $command "
# Check if $1 is a .doom file
else
doom_file = " $1 "
2024-01-04 16:34:02 +00:00
log i " Found a doom file: \" $1 \" "
2023-12-19 11:43:08 +00:00
# Check if the .doom file exists
if [ [ ! -e " $doom_file " ] ] ; then
2024-01-04 16:34:02 +00:00
log e " doom file not found in \" $doom_file \" "
2024-06-28 20:07:35 +00:00
rd_zenity --error --no-wrap \
2023-12-19 11:48:44 +00:00
--window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK" \
--text= " File \" $doom_file \" not found. Quitting. "
2023-12-19 11:43:08 +00:00
exit 1
fi
# Read the .doom file and compose the command
command = "gzdoom -config /var/config/gzdoom/gzdoom.ini"
while IFS = read -r line; do
2025-01-23 02:23:47 +00:00
# Check if the line contains a single quote
if [ [ " $line " = = *"'" * ] ] ; then
log e " Invalid filename: A file containined in \" $1 \" contains a single quote "
rd_zenity --error --no-wrap \
--window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK" \
--text= " <span foreground=' $purple '><b>Invalid filename\n\n</b></span>A file containined in \" $1 \" contains a single quote.\nPlease rename the file and fix its name in the .doom file. "
exit 1
fi
2023-12-19 11:43:08 +00:00
# Search for the file recursively
found_file = $( search_file_recursive " $line " " $( dirname " $doom_file " ) " )
# If the file is not found, exit with an error
if [ [ -z " $found_file " ] ] ; then
2023-12-19 12:56:53 +00:00
log " [ERROR] File not found in \" $line \" "
2024-06-28 20:07:35 +00:00
rd_zenity --error --no-wrap \
2023-12-19 12:56:53 +00:00
--window-icon= "/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK" \
--text= " File \" $doom_file \" not found. Quitting. "
2023-12-19 11:43:08 +00:00
exit 1
fi
# Check if the file is an IWAD
if [ [ $( is_iwad " $found_file " ) = = "true" ] ] ; then
command += " -iwad $found_file "
2024-01-04 16:34:02 +00:00
log i " Appending the param \"-iwad $found_file \" "
2023-12-19 11:43:08 +00:00
else
command += " -file $found_file "
2024-01-04 16:34:02 +00:00
log i " Appending the param \"-file $found_file \" "
2023-12-19 11:43:08 +00:00
fi
done < " $doom_file "
# Log the command
2024-01-04 16:34:02 +00:00
log i " Executing command \" $command \" "
2023-12-19 11:43:08 +00:00
2025-01-23 02:23:47 +00:00
# Execute the command with double quotes
2023-12-19 11:43:08 +00:00
eval " $command "
2023-11-24 23:13:07 +00:00
fi