From 6e4d7bae8d11a18de750fe38b05f712e64768351 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 18 May 2025 20:16:22 -0400 Subject: [PATCH] More conversion to a modular system. --- .includes/desktop.sh | 35 ++++++++++++ .includes/functions.sh | 61 ++++++++++++++++++++ .includes/help.sh | 27 +++++++++ audiogame-manager.sh | 126 ----------------------------------------- 4 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 .includes/desktop.sh diff --git a/.includes/desktop.sh b/.includes/desktop.sh new file mode 100644 index 0000000..b881de2 --- /dev/null +++ b/.includes/desktop.sh @@ -0,0 +1,35 @@ +# Create desktop launcher file +desktop_launcher() { + local desktopFile="${HOME}/audiogame-manager.desktop" + if [[ -e "${desktopFile}" ]]; then + echo "the file ${desktopFile} exists. Cannot create the launcher." + exit 1 + fi + local dotDesktop + local terminal + # Try to find an accessible terminal + for i in mate-terminal lxterminal terminator gnome-terminal ; do + if command -v $i &> /dev/null ; then + terminal="$i" + break + fi + done + dotDesktop=('[Desktop Entry]' + 'Name=Audiogame manager' + 'GenericName=Audiogame Manager' + 'Comment=Play audio games' + "Exec=${terminal} -t \"Audiogame Manager\" -e \"/usr/bin/bash -c 'nohup $(readlink -e "$0") 2> /dev/null'\"" + 'Terminal=false' + 'Type=Application' + 'StartupNotify=false' + 'Keywords=game;' + 'Categories=Game;' + 'Version=1.0') + for i in "${dotDesktop[@]}" ; do + echo "$i" >> "${desktopFile}" + done + desktop-file-install --dir "${HOME}/.local/share/applications" -m 755 "${desktopFile}" + xdg-desktop-icon install ~/.local/share/applications/audiogame-manager.desktop + rm "${desktopFile}" + exit 0 +} diff --git a/.includes/functions.sh b/.includes/functions.sh index dd40b8c..6a39edf 100644 --- a/.includes/functions.sh +++ b/.includes/functions.sh @@ -22,6 +22,67 @@ check_requirements() { return 0 } +download() { + local source=($@) + for i in "${source[@]}" ; do + local dest="${i##*/}" + dest="${dest//%20/ }" + dest="${dest#*\?filename=}" + dest="${dest%\?*}" + # Remove the destination file if it is empty. + [[ -s "${cache}/${dest}" ]] || rm -f "${cache}/${dest}" 2> /dev/null + if [[ "${redownload}" == "true" ]] && [[ -e "${cache}/${dest}" ]]; then + rm -v "${cache}/${dest}" + fi + # Skip if the item is in cache. + [[ -e "${cache}/${dest}" ]] && continue + { if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then + echo "Could not download \"$i\"..." + exit 1 + fi; } | dialog --backtitle "Audio Game Manager" \ + --progressbox "Downloading \"$dest\" from \"$i\"" -1 -1 + local downloadError=1 + case "${dest##*.}" in + "pk3"|"zip") + unzip -tq "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ + --progressbox "Validating ${dest##*.} file" -1 -1 --stdout + downloadError=$? + ;; + "7z") + 7z t "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ + --progressbox "Validating 7z file" -1 -1 --stdout + downloadError=$? + ;; + "exe") + # Check if it's a valid Windows executable by looking at the MZ header + hexdump -n 2 -v -e '/1 "%02X"' "${cache}/${dest}" | grep -q "4D5A" + downloadError=$? + ;; + "wad") + if [[ "$(file -b --mime-type "${cache}/${dest}")" != "application/octet-stream" ]]; then + downloadError=0 + fi + ;; + *) + # Add HTML check for other file types + if file -b "${cache}/${dest}" | grep -q "HTML document" ; then + echo "File not found: \"$i\" (HTML document probably 404)" + downloadError=1 + else + downloadError=0 + fi + ;; + esac + if [[ $downloadError -ne 0 ]]; then + rm -fv "${cache}/${dest}" + dialog --backtitle "Audio Game Manager" \ + --infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout + alert + exit 1 + fi + done +} + # Function to open urls across OS. open_url() { if [[ "$(uname)" == "Darwin" ]]; then diff --git a/.includes/help.sh b/.includes/help.sh index e710959..3ee8097 100644 --- a/.includes/help.sh +++ b/.includes/help.sh @@ -56,6 +56,33 @@ echo "Loading documentation, please wait..." exit 0 } +help() { + echo "${0##*/}" + echo "Released under the terms of the Common Public Attribution License Version 1.0" + echo -e "This is a Stormux project: https://stormux.org\n" + echo -e "Usage:\n" + echo "With no arguments, open the game launcher." + for i in "${!command[@]}" ; do + echo "-${i/:/ }: ${command[${i}]}" + done | sort + echo + echo "Some settings that are often used can be stored in a settings.conf file." + echo "If wanted, place it at the following location:" + echo "${configFile%/*}/settings.conf" + echo "The syntax is variable=\"value\"" + echo + echo "ipfsGateway=\"https://ipfs.stormux.org\" # Gateway to be used for ipfs downloads." + echo "noCache=\"true\" # Do not keep downloaded items in the cache." + echo "noqjoypad=\"true\" # Do not launch qjoypad." + echo "norh=\"true\" # Do not install RHVoice." + echo "redownload=\"true\" # Redownload sources, do not use the version stored in cache." + echo "voiceName=\"voicename\" # Select the voice to be installed (default Bdl)." + echo "defaultVoice=\"voicename\" # Select the default voice to use for the bottle, e.g. MSMike or RHVoice." + echo "defaultRate=\"Default voice rate for the bottle, default 7, may not work in all games. Values 1-9 or A." + echo "winedebug=\"flag(s)\" # Set wine debug flags, useful for development." + exit 0 +} + license() { cat << EOF â– The contents of this file are subject to the Common Public Attribution diff --git a/audiogame-manager.sh b/audiogame-manager.sh index 14bc1e2..8bdc0ae 100755 --- a/audiogame-manager.sh +++ b/audiogame-manager.sh @@ -3,44 +3,6 @@ # Dialog accessibility export DIALOGOPTS='--no-lines --visit-items' - -# Create desktop launcher file -desktop_launcher() { - local desktopFile="${HOME}/audiogame-manager.desktop" - if [[ -e "${desktopFile}" ]]; then - echo "the file ${desktopFile} exists. Cannot create the launcher." - exit 1 - fi - local dotDesktop - local terminal - # Try to find an accessible terminal - for i in mate-terminal lxterminal terminator gnome-terminal ; do - if command -v $i &> /dev/null ; then - terminal="$i" - break - fi - done - dotDesktop=('[Desktop Entry]' - 'Name=Audiogame manager' - 'GenericName=Audiogame Manager' - 'Comment=Play audio games' - "Exec=${terminal} -t \"Audiogame Manager\" -e \"/usr/bin/bash -c 'nohup $(readlink -e "$0") 2> /dev/null'\"" - 'Terminal=false' - 'Type=Application' - 'StartupNotify=false' - 'Keywords=game;' - 'Categories=Game;' - 'Version=1.0') - for i in "${dotDesktop[@]}" ; do - echo "$i" >> "${desktopFile}" - done - desktop-file-install --dir "${HOME}/.local/share/applications" -m 755 "${desktopFile}" - xdg-desktop-icon install ~/.local/share/applications/audiogame-manager.desktop - rm "${desktopFile}" - exit 0 -} - - # Wine configuration section clear_cache() { @@ -63,67 +25,6 @@ clear_cache() { echo "Cache deleted." } -download() { - local source=($@) - for i in "${source[@]}" ; do - local dest="${i##*/}" - dest="${dest//%20/ }" - dest="${dest#*\?filename=}" - dest="${dest%\?*}" - # Remove the destination file if it is empty. - [[ -s "${cache}/${dest}" ]] || rm -f "${cache}/${dest}" 2> /dev/null - if [[ "${redownload}" == "true" ]] && [[ -e "${cache}/${dest}" ]]; then - rm -v "${cache}/${dest}" - fi - # Skip if the item is in cache. - [[ -e "${cache}/${dest}" ]] && continue - { if ! curl -L4 -C - --retry 10 --output "${cache}/${dest}" "${i}" ; then - echo "Could not download \"$i\"..." - exit 1 - fi; } | dialog --backtitle "Audio Game Manager" \ - --progressbox "Downloading \"$dest\" from \"$i\"" -1 -1 - local downloadError=1 - case "${dest##*.}" in - "pk3"|"zip") - unzip -tq "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ - --progressbox "Validating ${dest##*.} file" -1 -1 --stdout - downloadError=$? - ;; - "7z") - 7z t "${cache}/${dest}" | dialog --backtitle "Audio Game Manager" \ - --progressbox "Validating 7z file" -1 -1 --stdout - downloadError=$? - ;; - "exe") - # Check if it's a valid Windows executable by looking at the MZ header - hexdump -n 2 -v -e '/1 "%02X"' "${cache}/${dest}" | grep -q "4D5A" - downloadError=$? - ;; - "wad") - if [[ "$(file -b --mime-type "${cache}/${dest}")" != "application/octet-stream" ]]; then - downloadError=0 - fi - ;; - *) - # Add HTML check for other file types - if file -b "${cache}/${dest}" | grep -q "HTML document" ; then - echo "File not found: \"$i\" (HTML document probably 404)" - downloadError=1 - else - downloadError=0 - fi - ;; - esac - if [[ $downloadError -ne 0 ]]; then - rm -fv "${cache}/${dest}" - dialog --backtitle "Audio Game Manager" \ - --infobox "Error downloading \"${dest}\". Installation cannot continue." -1 -1 --stdout - alert - exit 1 - fi - done -} - get_bottle() { # Handles games that use the same wine bottle case "${game}" in @@ -289,33 +190,6 @@ get_steam() { exit 1; } } -help() { - echo "${0##*/}" - echo "Released under the terms of the Common Public Attribution License Version 1.0" - echo -e "This is a Stormux project: https://stormux.org\n" - echo -e "Usage:\n" - echo "With no arguments, open the game launcher." - for i in "${!command[@]}" ; do - echo "-${i/:/ }: ${command[${i}]}" - done | sort - echo - echo "Some settings that are often used can be stored in a settings.conf file." - echo "If wanted, place it at the following location:" - echo "${configFile%/*}/settings.conf" - echo "The syntax is variable=\"value\"" - echo - echo "ipfsGateway=\"https://ipfs.stormux.org\" # Gateway to be used for ipfs downloads." - echo "noCache=\"true\" # Do not keep downloaded items in the cache." - echo "noqjoypad=\"true\" # Do not launch qjoypad." - echo "norh=\"true\" # Do not install RHVoice." - echo "redownload=\"true\" # Redownload sources, do not use the version stored in cache." - echo "voiceName=\"voicename\" # Select the voice to be installed (default Bdl)." - echo "defaultVoice=\"voicename\" # Select the default voice to use for the bottle, e.g. MSMike or RHVoice." - echo "defaultRate=\"Default voice rate for the bottle, default 7, may not work in all games. Values 1-9 or A." - echo "winedebug=\"flag(s)\" # Set wine debug flags, useful for development." - exit 0 -} - install_wine() { # Requires wine version, e.g. 7.7 and architecture, 32|64 if [[ $# -ne 2 ]]; then