Skip to content

Commit

Permalink
Commandline: Add support for Non-Steam Games to getGameDir (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic2kk authored Nov 8, 2023
1 parent 0ef8ef6 commit 58d708b
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions steamtinkerlaunch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
PREFIX="/usr"
PROGNAME="SteamTinkerLaunch"
NICEPROGNAME="Steam Tinker Launch"
PROGVERS="v14.0.20231108-4"
PROGVERS="v14.0.20231109-1"
PROGCMD="${0##*/}"
PROGINTERNALPROTNAME="Proton-stl"
SHOSTL="stl"
Expand Down Expand Up @@ -7948,6 +7948,8 @@ function getValueFromAppManifest {
# Returns game install directory in the format "Game (AppID) -> /path/to/gamefolder"
function getGameDir {
ONLYPATH="$2"
SEARCHSTEAMSHORTCUTS="${3:-0}" # Default to not searching Steam shortcuts
FOUNDINSTEAMSHORTCUTS=0

if [ -z "$1" ]; then
echo "A Game ID or Game Title is required as argument"
Expand All @@ -7965,23 +7967,56 @@ function getGameDir {

SEARCHMANIFEST="$( listAppManifests | grep -m1 "appmanifest_${SEARCHAID}.acf" )"
if [ -z "$SEARCHMANIFEST" ]; then
writelog "ERROR" "${FUNCNAME[0]} - Could not find game directory for '$1' - Maybe it is not installed"
echo "Could not find game directory for '$1'"
return 1
if [ "$SEARCHSTEAMSHORTCUTS" -eq 0 ]; then
writelog "ERROR" "${FUNCNAME[0]} - Could not find game directory for '$1' - Maybe it is not installed"
echo "Could not find game directory for '$1'"
return 1
else
writelog "WARN" "${FUNCNAME[0]} - Could not find game directory for '$1' - Will search on Steam Shortcuts next"
fi
else
writelog "INFO" "${FUNCNAME[0]} - Found matching App Manifest '$SEARCHMANIFEST'"
fi
else
writelog "INFO" "${FUNCNAME[0]} - Found matching App Manifest file for presumed entered AppID '$1' - Manifest file is '$SEARCHMANIFEST'"
fi

APPMAINSTDIR="$( getValueFromAppManifest "installdir" "$SEARCHMANIFEST" )"
APPMAINSTDIR="$( getValueFromAppManifest "installdir" "$SEARCHMANIFEST" 2>/dev/null )"
APPMALIBFLDR="$( dirname "$SEARCHMANIFEST" )"
GAMINSTDIR="$APPMALIBFLDR/common/$APPMAINSTDIR"
MUSINSTDIR="$APPMALIBFLDR/music/$APPMAINSTDIR" # Fixes a not found error for installed soundtracks

# If still not found, optionally search Steam shortcuts
if [ ! -d "$GAMINSTDIR" ] && [ "$SEARCHSTEAMSHORTCUTS" -eq 1 ] && haveAnySteamShortcuts ; then
while read -r SCVDFE; do
SCVDFEAID="$( parseSteamShortcutEntryAppID "$SCVDFE" )"
SCVDFENAME="$( parseSteamShortcutEntryAppName "$SCVDFE" )"
SCVDFEEXE="$( parseSteamShortcutEntryExe "$SCVDFE" )"

## If we have a match, build a hardcoded compatdata pointing at the Steam Root compatdata dir and if it exists, return that
## Seems like this is always where Steam generates compatdata for Non-Steam Games
## may instead be primary drive which defaults to Steam Root, but for now looks like Steam Root is the main place, so should work most of the time
if [ "$SCVDFEAID" -eq "$1" ] 2>/dev/null || [[ ${SCVDFENAME,,} == *"${1,,}"* ]]; then
APPMAGN="${SCVDFENAME}"
APPMAAID="${SCVDFEAID}"
GAMINSTDIR="$( dirname "${SCVDFEEXE}" )" # Could still fail if EXE dir no longer exists, but edge case

# TODO make this a function later, we use this a lot
GAMINSTDIR="${GAMINSTDIR#\"}"
GAMINSTDIR="${GAMINSTDIR%\"}"

FOUNDINSTEAMSHORTCUTS=1
break
fi
done <<< "$( getSteamShortcutHex )"
fi

if [ -d "$GAMINSTDIR" ] || [ -d "$MUSINSTDIR" ]; then
APPMAGN="$( getValueFromAppManifest "name" "$SEARCHMANIFEST" )"
APPMAAID="$( getValueFromAppManifest "appid" "$SEARCHMANIFEST" )"
# Don't fetch these if we found and set the information already from a Steam shortcuts
if [ "$FOUNDINSTEAMSHORTCUTS" -eq 0 ]; then
APPMAGN="$( getValueFromAppManifest "name" "$SEARCHMANIFEST" )"
APPMAAID="$( getValueFromAppManifest "appid" "$SEARCHMANIFEST" )"
fi

if [ -z "$ONLYPATH" ]; then
printf "%s (%s) -> %s\n" "$APPMAGN" "$APPMAAID" "$GAMINSTDIR"
Expand Down Expand Up @@ -22044,9 +22079,9 @@ function commandline {
getCompatData "$2" "1"
elif [ "$1" == "getgamedir" ] || [ "$1" == "gg" ]; then
if [ "$3" == "only" ]; then
getGameDir "$2" "X"
getGameDir "$2" "X" "1"
else
getGameDir "$2"
getGameDir "$2" "" "1"
fi
elif [ "$1" == "help" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
howto
Expand Down

0 comments on commit 58d708b

Please sign in to comment.