This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# FIXME: Currently missing dosbox variants: ece, svn, stock | |
# Unhandled: | |
#CTorOCh "./eXoDOS/CTorOCh/dosbox/dosbox.exe" -conf "eXoDOS/\!dos/CTorOCh/dosbox.conf" -noconsole -exit | |
#FatmanTh "./eXoDOS/FatmanTh/dosbox.exe" -conf "eXoDOS/\!dos/FatmanTh/dosbox.conf" -noconsole -exit | |
#ThemPark "./eXoDOS/ThemPark/ece/DOSBox.exe" -conf "eXoDOS/\!dos/ThemPark/dosbox.conf" -noconsole -exit -nomenu | |
#btroot "./eXoDOS/btroot/dosbox/dosbox.exe" -conf "eXoDOS/\!dos/btroot/dosbox.conf" -noconsole -exit | |
#MinosAdv "./eXoDOS/MinosAdv/DOSBox-0.73/dosbox.exe" -conf "eXoDOS/\!dos/MinosAdv/dosbox.conf" -noconsole -exit | |
set -euo pipefail | |
usage() { | |
echo >&2 "${0##*/} [options]" | |
echo >&2 | |
echo >&2 "Print commandlines to launch installed eXo games natively on macOS." | |
echo >&2 | |
echo >&2 "Options:" | |
echo >&2 " -a List all games, not just installed." | |
} | |
process_arguments() { | |
all=0 | |
while getopts ah opt; do | |
case "$opt" in | |
a) | |
all=1 | |
;; | |
\? | h) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
} | |
list_all_games() { | |
find eXo*/\!* -type d -mindepth 1 -maxdepth 1 | while read -r dir; do | |
type="${dir%%/*}" | |
name="$(basename "$dir")" | |
gamedir="$type/$name" | |
printf '%s\t%s\n' "$dir" "$gamedir" | |
done | |
} | |
list_games() { | |
find eXo* -type d -mindepth 1 -maxdepth 1 -not -iname \!\* | while read -r gamedir; do | |
type="${gamedir%%/*}" | |
name="$(basename "$gamedir")" | |
dir="$(find "$type" -type d -iwholename "$type/\!*/$name")" | |
if ! [ -e "$dir" ]; then | |
continue | |
fi | |
printf '%s\t%s\n' "$dir" "$gamedir" | |
done | |
} | |
scummvm_detect() { | |
./scummvm-macos/ScummVM.app/Contents/MacOS/scummvm -p "$1" --detect --recursive 2>/dev/null | | |
tail -n +3 | | |
sed -e 's#\([^ ]*\).*\('"$2"'/.*\)#\1 \2#' | |
} | |
no_batch() { | |
local dir="$1" | |
local gamedir="$2" | |
local type="${dir%%/*}" | |
case "$type" in | |
eXoDOS | eXoWin3x) | |
find "$dir" -iname dosbox\*.conf | | |
while read -r conf; do | |
printf "./dosbox-x-macos/dosbox-x-sdl2 -conf '%s' -noconsole -exit\n" "$conf" | |
done | |
;; | |
eXoScummVM) | |
scummvm_detect "$gamedir" "$type" | | |
while read -r id subdir; do | |
printf './scummvm-macos/ScummVM.app/Contents/MacOS/scummvm 2>/dev/null -f -g2x --platform=pc --opl-driver=nuked -emt32 --multi-midi --extrapath=./mt32/rev0 --output-rate=44100 --aspect-ratio -p "%s" %s\n' "$subdir" "$id" | |
done | |
;; | |
*) | |
printf '%s\t%s\n' "$dir" "$gamedir" | |
;; | |
esac | |
} | |
get_commands() { | |
local bat="$1" | |
local dir="$2" | |
local name="$3" | |
# shellcheck disable=SC2016 | |
grep -iE '\.(bat|exe)' "$bat" | | |
grep -Ev 'install\.bat|setconsole|GBC|taskkill' | | |
grep -v '^rem ' | | |
sed -e 's$%var%$'"$dir"'$g' \ | |
-e 's$%GameDir%$'"$name"'$g' \ | |
-e 's#\\#/#g' | | |
tr -d $'\r' | | |
cut -d: -f2- | |
} | |
identify() { | |
local ident= | |
local sdir | |
local name="$1" | |
local command="$2" | |
case "$command" in | |
*scmvm* | *scummvm*) | |
local suffix=ScummVM | |
# shellcheck disable=SC2001 | |
local id="${command##* }" | |
if [ "$id" != "$command" ]; then | |
suffix="$suffix, $id" | |
fi | |
ident="$name [$suffix]" | |
sdir="$(echo "$command" | sed -e 's#\\#/#g' | sed -n -e 's/.* -p *"\([^"]*\)".*/\1/p')" | |
if [ -n "$sdir" ]; then | |
ident="${sdir##*/} [$suffix]" | |
fi | |
;; | |
*dos*) | |
ident="$name [DOS]" | |
;; | |
esac | |
if echo "$command" | grep -qi fluidsynth; then | |
ident="$ident [fluidsynth]" | |
elif echo "$command" | grep -qi mt32; then | |
ident="$ident [mt32]" | |
fi | |
printf '%s\n' "$ident" | |
} | |
win_command_to_mac() { | |
sed -e 's#"./scmvm/scummvm.exe" --no-console#./scummvm-macos/ScummVM.app/Contents/MacOS/scummvm#' \ | |
-e 's#"./scummvm/scummvm.exe" --no-console#./scummvm-macos/ScummVM.app/Contents/MacOS/scummvm#' \ | |
-e 's#"./dosbox/ece/dosbox.exe"#./dosbox-x-macos/dosbox-x-sdl2#' \ | |
-e 's#"./dosbox/ECE/dosbox.exe"#./dosbox-x-macos/dosbox-x-sdl2#' \ | |
-e 's#"./dosbox/x/dosbox.exe"#./dosbox-x-macos/dosbox-x-sdl2#' \ | |
-e 's#"./dosbox/svn/dosbox.exe"#./dosbox-x-macos/dosbox-x-sdl2#' \ | |
-e 's#"./dosbox/dosbox.exe"#./dosbox-x-macos/dosbox-x-sdl2#' \ | |
-e 's#!#\\!#g' | |
} | |
main() { | |
process_arguments "$@" | |
shift $((OPTIND - 1)) | |
tmpdir="$(mktemp -d -t "${0##*/}.XXXXXX")" | |
trap 'rm -rf "$tmpdir"' EXIT INT TERM | |
if [ $all -eq 1 ]; then | |
list_all_games | |
else | |
list_games | |
fi | while IFS=$'\t' read -r dir gamedir; do | |
type="${dir%%/*}" | |
typesuffix="${type#eXo}" | |
name="$(basename "$dir")" | |
bat="$(find "$dir" -mindepth 1 -maxdepth 1 -iname \*.bat -not -iname install.bat -type f | head -n 1)" | |
if [ -z "$bat" ]; then | |
title="${dir##*/}" | |
printf '# %s [%s]\n' "$title" "$typesuffix" | |
no_batch "$dir" "$gamedir" | |
else | |
title="$(echo "$bat" | sed -e 's#.*/##; s#\.bat$##;')" | |
printf '# %s [%s]\n' "$title" "$typesuffix" | |
get_commands "$bat" "$dir" "$name" >"$tmpdir/commands" | |
# shellcheck disable=SC2046 | |
if [ $(wc -l <"$tmpdir/commands") -eq 1 ]; then | |
printf '%s\t%s\n' "$name" "$(cat "$tmpdir/commands")" | |
else | |
cat "$tmpdir/commands" | | |
while read -r command; do | |
ident="$(identify "$name" "$command")" | |
printf '%s\t%s\n' "$ident" "$command" | |
done | |
fi | | |
win_command_to_mac | |
fi | | |
sort -fu | | |
if ! [ -e "$gamedir" ]; then | |
sed -e '/^#/n; s/^/#/' | |
else | |
cat | |
fi | |
echo | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment