From 5df4da7ea79654d93cbf9cbffebf6b2a5a819156 Mon Sep 17 00:00:00 2001 From: Roy <88516395+moraroy@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:17:57 -0800 Subject: [PATCH] Update NonSteamLaunchers.sh ~better way to parse the .vdf for login users --- NonSteamLaunchers.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/NonSteamLaunchers.sh b/NonSteamLaunchers.sh index 6a89f9a..41d60a7 100755 --- a/NonSteamLaunchers.sh +++ b/NonSteamLaunchers.sh @@ -2556,14 +2556,28 @@ steam_dir="${logged_in_home}/.local/share/Steam" # Check if the loginusers.vdf file exists if [[ -f "${logged_in_home}/.steam/root/config/loginusers.vdf" ]]; then - # Extract the block of text for the most recent user - most_recent_user=$(sed -n '/"users"/,/"MostRecent" "1"/p' "${logged_in_home}/.steam/root/config/loginusers.vdf") + # Extract the blocks of text for all users + all_users=$(sed -n '/"users"/,/}/p' "${logged_in_home}/.steam/root/config/loginusers.vdf") - # Extract the SteamID from the block of text for the most recent user - steamid=$(echo "$most_recent_user" | grep -o '[0-9]\{17\}') + # Initialize variables to store the most recent user's SteamID and timestamp + most_recent_steamid="" + most_recent_timestamp=0 - # Convert steamid to steamid3 - steamid3=$((steamid - 76561197960265728)) + # Loop over each user block + while read -r user_block; do + # Extract the SteamID and timestamp from the user block + steamid=$(echo "$user_block" | grep -o '[0-9]\{17\}') + timestamp=$(echo "$user_block" | grep -o '"Timestamp"[[:space:]]"[0-9]\+"' | grep -o '[0-9]\+') + + # If this user's timestamp is more recent than the most recent timestamp so far, update the most recent SteamID and timestamp + if ((timestamp > most_recent_timestamp)); then + most_recent_steamid=$steamid + most_recent_timestamp=$timestamp + fi + done < <(echo "$all_users" | awk '/{/,/}/') + + # Convert most_recent_steamid to steamid3 + steamid3=$((most_recent_steamid - 76561197960265728)) # Initialize the userdata_folder variable userdata_folder="" @@ -2583,6 +2597,7 @@ fi + # Check if userdata folder was found if [[ -n "$userdata_folder" ]]; then # Userdata folder was found