From ab1e89fd6b44b09249ec890354b62c3403bf8138 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 27 Apr 2021 20:32:08 -0400 Subject: [PATCH] Added a documentation button that will hopefully load the game's documentation in w3m. This is the first attempt but it seems to be working pretty well so far. --- audiogame-manager.sh | 52 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/audiogame-manager.sh b/audiogame-manager.sh index 940d9c2..1ee449c 100755 --- a/audiogame-manager.sh +++ b/audiogame-manager.sh @@ -197,6 +197,11 @@ checklist() { else errorList+=("Warning: unix2dos is not installed. Some games need a configuration file in dos format before they will run.") fi + if command -v w3m &> /dev/null ; then + echo "W3m is installed." + else + errorList+=("Warning: w3m is not installed. W3m is used to view game documentation.") + fi if command -v xclip &> /dev/null ; then echo "Xclip is installed." else @@ -266,6 +271,43 @@ help() { exit 0 } +documentation() { + if [[ "$2" == "Become a Patron" ]]; then + return + fi + if [[ "$2" == "Donate" ]]; then + return + fi + if ! command -v w3m &> /dev/null ; then + echo "This feature of audiogame-manager requires w3m. Please install it before continuing." + fi + export WINEPREFIX="$1" +echo "Loading documentation, please wait..." + # Try to find documentation based on common naming conventions. + local gamePath="$(winepath -u "$2" 2> /dev/null)" + gamePath="${gamePath%/*}" + local gameDoc="$(find "$gamePath" -type f -iname 'user_manual.html')" + if [[ -z "$gameDoc" ]]; then + gameDoc="$(find "$gamePath" -type f -iname 'manual.html')" + fi + if [[ -z "$gameDoc" ]]; then + gameDoc="$(find "$gamePath" -type f -iname 'readme.html')" + fi + if [[ -z "$gameDoc" ]]; then + gameDoc="$(find "$gamePath" -type f -iname 'manual.txt')" + fi + if [[ -z "$gameDoc" ]]; then + gameDoc="$(find "$gamePath" -type f -iname 'readme.txt')" + fi + # Display documentation if available. + if [[ -n "$gameDoc" ]]; then + w3m "$gameDoc" + else + echo "No documentation found." + fi + exit 0 +} + install_wine_bottle() { # 32 bit installations work best and are the default here, if you need to override it, do it in the game specific installation steps. export WINEARCH="${WINEARCH:-win32}" @@ -421,10 +463,18 @@ game_launcher() { done menuList+=("Donate" "Donate") menuList+=("Become a Patron" "Become a Patron") - local game="$(dialog --backtitle "Audio Game Launcher" \ + game="$(dialog --backtitle "Audio Game Launcher" \ --clear \ + --extra-button \ + --extra-label "Documentation" \ --no-tags \ --menu "Please select a game to play" 0 0 0 "${menuList[@]}" --stdout)" + local menuCode=$? + if [[ $menuCode -eq 1 ]]; then + exit 0 + elif [[ $menuCode -eq 3 ]]; then + documentation "${HOME}/.local/wine/${game%|*}" "$(echo "$game" | cut -d '|' -f2)" + fi else local game="$(grep "^${1}|" "${configFile}" 2> /dev/null)" game="${game%|*}"