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

Non-Steam Game: Add non-steam|nsg filter to list Command #1121

Merged
merged 5 commits into from
Jun 8, 2024
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
138 changes: 84 additions & 54 deletions steamtinkerlaunch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
PREFIX="/usr"
PROGNAME="SteamTinkerLaunch"
NICEPROGNAME="Steam Tinker Launch"
PROGVERS="v14.0.20240608-1"
PROGVERS="v14.0.20240609-1"
PROGCMD="${0##*/}"
PROGINTERNALPROTNAME="Proton-stl"
SHOSTL="stl"
Expand Down Expand Up @@ -7779,80 +7779,101 @@ function pickGameWindowNameMeta {

# 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"
# - `steamtinkerlaunch list owned/installed/non-steam` - Returns "Game Name (AppID)"
# - `steamtinkerlaunch list owned/installed/non-steam id/name/path/full` - Returns either AppID, Game Name, Game Paths, or all in the format "Game Name (AppID) -> /path/to/game"
#
# This function is not very efficient, Non-Steam Games in particular are inefficient because we read shortcuts.vdf each time we want to parse info
# We parse it once to get the IDs, then again in each `getTitleFromID` and `getGameDir` call. This makes it pretty slow
# It works for now, but in future we should enhance it
#
# One potential way to enhance this function is to split it out into a separate function for each filter type, but we would need
# to consider how this function is used by other parts of the codebase and if that could be disruptive.
function listSteamGames {
function getGameCount {
TOTALGAMESOWNEDPRINTFSTR=""

if [ "$LSFILTER" == "owned" ] || [ "$LSFILTER" == "o" ]; then
printf "Total games owned: %s\n" "${#LISTAIDSARR[@]}"
TOTALGAMESOWNEDPRINTFSTR="Total games owned"
elif [ "$LSFILTER" == "non-steam" ] || [ "$LSFILTER" == "nsg" ]; then
TOTALGAMESOWNEDPRINTFSTR="Total Non-Steam Games in library"
else
printf "Total games installed: %s\n" "${#LISTAIDSARR[@]}"
TOTALGAMESOWNEDPRINTFSTR="Total games installed"
fi

printf "${TOTALGAMESOWNEDPRINTFSTR}: %s\n" "${#LISTAIDSARR[@]}"
}

LSFILTER="$1" # e.g. "owned", "installed"
LSFILTER="$1" # e.g. "owned", "installed", "non-steam"
LSTYPE="$2" # e.g. "id", "name", "path", "count", "full"
LISTAIDS=""

SEARCHSTEAMSHORTCUTS="0"

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
LISTAIDS="$( listInstalledGameIDs )"
elif [ "$LSFILTER" == "non-steam" ] || [ "$LSFILTER" == "nsg" ]; then
LISTAIDS="$( listNonSteamGameIDs )"
SEARCHSTEAMSHORTCUTS="1" # Only search Steam Shortcuts if we passed that filter type
else
writelog "INFO" "${FUNCNAME[0]} - Unknown argument passed to 'list' command - '$LSFILTER'"
echo "unknown argument passed to 'list' command - '$LSFILTER'"

exit
fi

if [ -n "$LISTAIDS" ]; then
readarray -t LISTAIDSARR <<<"$LISTAIDS"
if [ -z "$LISTAIDS" ]; then
writelog "SKIP" "${FUNCNAME[0]} - No games found for given filter '$LSFILTER'"
echo "No games found for filter '$LSFILTER'."

if [ "$LSTYPE" == "id" ]; then
for AID in "${LISTAIDSARR[@]}"; do
echo "$AID"
done
elif [ "$LSTYPE" == "name" ]; then
exit
fi

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}" "${SEARCHSTEAMSHORTCUTS}"
done
elif [ "$LSTYPE" == "path" ]; then
if [ "$LSFILTER" == "owned" ] || [ "$LSFILTER" == "o" ]; then
echo "Cannot use 'path' option when returning 'owned' games, as not all owned games will have an installation path!"
echo "Use another option instead, or leave blank to only return path for games which have an installation path."

exit
else
for AID in "${LISTAIDSARR[@]}"; do
getTitleFromID "${AID}"
getGameDir "$AID" "1" "${SEARCHSTEAMSHORTCUTS}"
done
elif [ "$LSTYPE" == "path" ]; then
if [ "$LSFILTER" == "owned" ] || [ "$LSFILTER" == "o" ]; then
echo "Cannot use 'path' option when returning 'owned' games, as not all owned games will have an installation path!"
echo "Use another option instead, or leave blank to only return path for games which have an installation path."
else
for AID in "${LISTAIDSARR[@]}"; do
getGameDir "$AID" "1"
done
fi
elif [ "$LSTYPE" == "count" ]; then
printf "\n%s" "$( getGameCount )"
elif [ "$LSTYPE" == "full" ] || [ -z "$LSTYPE" ]; then # This is the default if id/name/path/full is not passed
for AID in "${LISTAIDSARR[@]}"; do
GAMDIR="$( getGameDir "$AID" )"
GAMDIREXISTS=$?

# Only display game dir if the game is installed, i.e. if getGameDir does not return 1
# This means we won't return an error if we're returning OWNED games, as some owned games may not have paths
if [ "$GAMDIREXISTS" -eq 1 ]; then
GAMNAM="$( getTitleFromID "$AID" )"
GAMNAMEXISTS=$?
if [ "$GAMNAMEXISTS" -eq 1 ]; then
echo "$AID" # Game name unknown, probably never installed before? Just return AppID in this case
else
echo "$GAMNAM ($AID)"
fi
fi
elif [ "$LSTYPE" == "count" ]; then
printf "\n%s\n" "$( getGameCount )"
elif [ "$LSTYPE" == "full" ] || [ -z "$LSTYPE" ]; then # This is the default if id/name/path/full is not passed
for AID in "${LISTAIDSARR[@]}"; do
GAMDIR="$( getGameDir "$AID" "" "${SEARCHSTEAMSHORTCUTS}" )"
GAMDIREXISTS=$?

# Only display game dir if the game is installed, i.e. if getGameDir does not return 1
# This means we won't return an error if we're returning OWNED games, as some owned games may not have paths
if [ "$GAMDIREXISTS" -eq 1 ]; then
GAMNAM="$( getTitleFromID "$AID" "${SEARCHSTEAMSHORTCUTS}" )"
GAMNAMEXISTS=$?
if [ "$GAMNAMEXISTS" -eq 1 ]; then
echo "$AID" # Game name unknown, probably never installed before? Just return AppID in this case
else
echo "$GAMDIR"
echo "$GAMNAM ($AID)"
fi
done
else
echo "$GAMDIR"
fi
done

printf "\n%s" "$( getGameCount )" # Show total for "full"
fi
printf "\n%s\n" "$( getGameCount )" # Show total for "full"
fi
}

Expand Down Expand Up @@ -8320,6 +8341,13 @@ function getSteamShortcutsVdfFileHex {
xxd -p -c 0 "$SCPATH"
}

function listNonSteamGameIDs {
writelog "INFO" "${FUNCNAME[0]} - Reading all Non-Steam AppIDs from shortcuts.vdf"
while read -r SCVDFE; do
parseSteamShortcutEntryAppID "$SCVDFE"
done <<< "$( getSteamShortcutHex )"
}

function haveAnySteamShortcuts {
if [ "$( getSteamShortcutHex | wc -c )" -gt 0 ]; then
return 0
Expand Down Expand Up @@ -22160,16 +22188,18 @@ function howto {
echo " Note that this will not remove your mods or installed Winetricks"
echo " lang=<option> Mostly to get translated configs on inital setup."
echo " <option> can be a language file name without suffix or an path to a valid language file"
echo " launcher <args> Start the Game Launcher"
echo " launcher <args> Start the Game Launcher"
echo " COLLECTION Show only installed games from Steam collection COLLECTION"
echo " menu Open Steam Collection Menu"
echo " last Open last Game as 'Menu'"
echo " auto Create/Download data for all installed games first"
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 " list <owned|installed|non-steam> List info on <owned|o,installed|i,non-steam|nsg> games"
echo " <id|name|path|count|full> Optionally specify whether you want to see"
echo " each game's <id|name|path|count|full>"
echo " NOTE: Non-Steam Games will NOT be included in <installed,owned>,"
echo " they will only show up for <non-steam|nsg>"
echo " listproton|lp List name and path of all Proton versions known to SteamTinkerLaunch"
echo " name|n Only list the Proton version names"
echo " path|p Only list paths to the Proton versions"
Expand Down