Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'list' Command #728

Merged
merged 5 commits into from
Jan 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 72 additions & 16 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="v12.12.20230127-1"
PROGVERS="v12.12.20230128-5"
PROGCMD="${0##*/}"
SHOSTL="stl"
GHURL="https://github.com"
Expand Down Expand Up @@ -6904,6 +6904,54 @@ function pickGameWindowNameMeta {
fi
}

# General function for the "steamtinkerlaunch list <arg> function"
# Can take two types of commands:
# - `steamtinkerlaunch list owned/installed` - Returns "Game Name (AppID)"
# - `steamtinkerlaunch list owned/installed id/name/path/full` - Returns either AppID, Game Name, Game Paths, or all in the format "Game Name (AppID) -> /path/to/game"
function listSteamGames {
LSFILTER="$1" # e.g. "owned", "installed"
LSTYPE="$2" # e.g. "id", "name", "path", "full"

LISTAIDS=""

if [ "$LSFILTER" == "owned" ] || [ "$LSFILTER" == "o" ]; then
LISTAIDS="$( getOwnedAids )"
elif [ "$LSFILTER" == "installed" ] || [ "$LSFILTER" == "i" ]; then
if [ "$(listInstalledGameIDs | wc -l)" -eq 0 ]; then
writelog "SKIP" "${FUNCNAME[0]} - No installed games found!" "E"
echo "No installed games found!"

exit
else
LISTAIDS="$( listInstalledGameIDs )"
fi
else
echo "unknown argument passed to 'list' command - '$LSFILTER'"
fi

if [ -n "$LISTAIDS" ]; then
readarray -t LISTAIDSARR <<<"$LISTAIDS"

if [ "$LSTYPE" == "id" ]; then
for AID in "${LISTAIDSARR[@]}"; do
echo "$AID"
done
elif [ "$LSTYPE" == "name" ]; then
for AID in "${LISTAIDSARR[@]}"; do
getTitleFromID "${AID}"
done
elif [ "$LSTYPE" == "path" ]; then
for AID in "${LISTAIDSARR[@]}"; do
getGameDir "$AID" "1"
done
elif [ "$LSTYPE" == "full" ] || [ -z "$LSTYPE" ]; then # This is the default if id/name/path/full is not passed
for AID in "${LISTAIDSARR[@]}"; do
getGameDir "${AID}"
done
fi
fi
}

function getIDFromTitle {
if [ -z "$1" ]; then
echo "A Game Title (part of it might be enough) is required as argument"
Expand Down Expand Up @@ -7014,11 +7062,13 @@ function getCompatData {
function getValueFromAppManifest {
KEY="$1"
APPMA="$2"
grep -m1 "$KEY" "$APPMA" | sed "s-\t- -g;s-\"${KEY}\"--g;s-\"--g" | xargs
grep -m1 "$KEY" "$APPMA" | sed "s-\t- -g;s-\"${KEY}\"--g;s-\"--g" | xargs # xargs gets angry when names have single quotes, e.g. "Shantae and the Pirate's Curse"
}

# Returns game install directory in the format "Game (AppID) -> /path/to/gamefolder"
function getGameDir {
ONLYPATH="$2"

if [ -z "$1" ]; then
echo "A Game ID or Game Title is required as argument"
else
Expand Down Expand Up @@ -7048,11 +7098,16 @@ function getGameDir {
APPMAINSTDIR="$( getValueFromAppManifest "installdir" "$SEARCHMANIFEST" )"
APPMALIBFLDR="$( dirname "$SEARCHMANIFEST" )"
GAMINSTDIR="$APPMALIBFLDR/common/$APPMAINSTDIR"
if [ -d "$GAMINSTDIR" ]; then
MUSINSTDIR="$APPMALIBFLDR/music/$APPMAINSTDIR" # Fixes a not found error for installed soundtracks
if [ -d "$GAMINSTDIR" ] || [ -d "$MUSINSTDIR" ]; then
APPMAGN="$( getValueFromAppManifest "name" "$SEARCHMANIFEST" )"
APPMAAID="$( getValueFromAppManifest "appid" "$SEARCHMANIFEST" )"

printf "%s (%s) -> %s\n" "$APPMAGN" "$APPMAAID" "$GAMINSTDIR"
if [ -z "$ONLYPATH" ]; then
printf "%s (%s) -> %s\n" "$APPMAGN" "$APPMAAID" "$GAMINSTDIR"
else
printf "%s\n" "$GAMINSTDIR" # Only output path, used by "listSteamGames"
fi
else
echo "Could not find install directory for '$1'"
fi
Expand Down Expand Up @@ -19568,7 +19623,8 @@ function howto {
echo " getid|gi <gametitle> Print the SteamAppId for <gametitle>"
echo " gettitle|gt <gameid> Print the Game Title for <gameid>"
echo " getcompatdata|gc <gameid/title> Print the Game compatdata path"
echo " getgamedir|gg <gameid/title> Print the Game install directory"
echo " getgamedir|gg <gameid/title> Print the Game install directory with game name and AppID"
echo " only Only display install directory"
echo " hedgemodmanager|hmm HedgeModManager"
echo " install|i install latest stable HedgeModManager"
echo " download|d <channel> download latest HedgeModManager release (stable or nightly)"
Expand Down Expand Up @@ -19601,6 +19657,8 @@ function howto {
echo " update ReCreate all Collection Menus"
echo " Can be combined with auto"
echo " list <owned|installed> List ids of <owned|o,installed|i> games"
echo " <id|name|path|full> Optionally specify whether you want to see"
echo " each game's <id|name|path|full>"
echo " meta Generates/Updates metadata"
echo " for all installed games"
echo " mo2 Mod Organizer 2"
Expand Down Expand Up @@ -19839,7 +19897,11 @@ function commandline {
elif [ "$1" == "getcompatdata" ] || [ "$1" == "gc" ]; then
getCompatData "$2"
elif [ "$1" == "getgamedir" ] || [ "$1" == "gg" ]; then
getGameDir "$2"
if [ "$3" == "only" ]; then
getGameDir "$2" "X"
else
getGameDir "$2"
fi
elif [ "$1" == "help" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
howto
elif [ "$1" == "helpurl" ] || [ "$1" == "hu" ]; then
Expand All @@ -19851,16 +19913,10 @@ function commandline {
elif [ "$1" == "launcher" ]; then
openGameLauncher "$2" "$3"
elif [ "$1" == "list" ]; then
if [ "$2" == "owned" ] || [ "$2" == "o" ]; then
getOwnedAids
elif [ "$2" == "installed" ] || [ "$2" == "i" ]; then
if [ "$(listInstalledGameIDs | wc -l)" -eq 0 ]; then
writelog "SKIP" "${FUNCNAME[0]} - No installed games found!" "E"
else
listInstalledGameIDs
fi
elif [ "$2" == "appmanifests" ] || [ "$2" == "am" ]; then
listAppManifests
if [ -z "$2" ]; then
echo "invalid usage - must pass one additional argument to 'list' command, either 'owned' or 'installed'"
else
listSteamGames "$2" "$3" # 3rd parameter is optional
fi
elif [ "$1" == "meta" ]; then
createMetaData "yes"
Expand Down