im thinking of switching how im writing to the vdf file with this module i got from github is there a more succesfull way? # Set the download directory
download_dir=~/Downloads/NonSteamLaunchersInstallation
Create the download directory if it doesn't exist
mkdir -p "$download_dir"
Download the python-vdf library from GitHub
download_url="https://github.com/ValvePython/vdf/archive/refs/heads/master.zip"
wget -P "downloaddir""download_url"
Extract the downloaded zip file
unzip "downloaddir"/master.zip−d"download_dir" > /dev/null
Move the extracted files to the desired location
mv "downloaddir"/vdf−master/∗"download_dir"
Set the default Steam directory
steam_dir="$HOME/.local/share/Steam"
Check if the config.vdf file exists
if [[ -f "steam_dir/config/config.vdf" ]]; then
# Get the steamid of the currently logged in user
steamid=(grep -oP 'SteamID"\s+"\K[0-9]+' "$steam_dir/config/config.vdf" | head -n 1)
# Print out the value of steamid for debugging purposes
echo "steamid: $steamid"
# Convert steamid to steamid3
steamid3=$((steamid - 76561197960265728))
# Initialize the userdata_folder variable
userdata_folder=""
# Initialize the most_recent variable
most_recent=0
# Loop through all the userdata folders
for USERDATA_FOLDER in ~/.steam/root/userdata/*
do
# Check if the current userdata folder is not the "0" or "anonymous" folder
if [[ "$USERDATA_FOLDER" != *"/0" ]] && [[ "$USERDATA_FOLDER" != *"/anonymous" ]]
then
# Get the access time of the current userdata folder
access_time=$(stat -c %X "$USERDATA_FOLDER")
# Extract steamid3 from userdata folder name
userdata_steamid3=$(basename "$USERDATA_FOLDER")
# Check if userdata_steamid3 matches steamid3 and if access time is more recent than most recent access time
if [[ $userdata_steamid3 -eq $steamid3 ]] && [[ $access_time -gt $most_recent ]]
then
# The access time of current userdata folder is more recent and steamid3 matches
# Set userdata_folder variable
userdata_folder="$USERDATA_FOLDER"
# Update most_recent variable
most_recent=$access_time
fi
fi
done
else
echo "Could not find config.vdf file"
fi
Check if userdata folder was found
if [[ -n "userdata_folder" ]]; then
# Userdata folder was found
echo "Current user's userdata folder found at: userdata_folder"
# Find shortcuts.vdf file for current user
shortcuts_vdf_path=$(find "$userdata_folder" -type f -name shortcuts.vdf)
# Check if shortcuts_vdf_path is not empty
if [[ -n "$shortcuts_vdf_path" ]]; then
# Create backup of shortcuts.vdf file
cp "$shortcuts_vdf_path" "$shortcuts_vdf_path.bak"
else
# Find config directory for current user
config_dir=$(find "$userdata_folder" -type d -name config)
# Check if config_dir is not empty
if [[ -n "$config_dir" ]]; then
# Create new shortcuts.vdf file at expected location for current user
touch "$config_dir/shortcuts.vdf"
shortcuts_vdf_path="$config_dir/shortcuts.vdf"
else
# Create new config directory and new shortcuts.vdf file at expected location for current user
mkdir "$userdata_folder/config/"
touch "$userdata_folder/config/shortcuts.vdf"
config_dir="$userdata_folder/config/"
shortcuts_vdf_path="$config_dir/shortcuts.vdf"
fi
fi
else
# Userdata folder was not found
echo "Current user's userdata folder not found"
fi
Detach script from Steam process
nohup sh -c 'sleep 10; /usr/bin/steam' &
Close all instances of Steam
killall steam
Wait for the steam process to exit
while pgrep steam > /dev/null; do sleep 1; done
Run the Python script to create a new entry for a Steam shortcut
python -c "
import sys
import os
sys.path.insert(0, os.path.expanduser('~/Downloads/NonSteamLaunchersInstallation/vdf'))
import vdf # Updated import
import subprocess
Print the path to the file where the vdf module was loaded from
print(vdf.file)
Load the shortcuts.vdf file
with open('$shortcuts_vdf_path', 'rb') as f:
shortcuts = vdf.binary_load(f)
Check if the 'shortcuts' key exists in the dictionary
if 'shortcuts' not in shortcuts:
# Create an empty 'shortcuts' entry
shortcuts['shortcuts'] = {}
Check the format of the 'shortcuts' entry
if isinstance(shortcuts['shortcuts'], dict):
# The 'shortcuts' entry is a dictionary
for key, value in shortcuts['shortcuts'].items():
# Check the type of the value
if not isinstance(value, (str, int, dict)):
pass
Define the path of the Launchers
epicshortcutdirectory = 'epicshortcutdirectory′gogsgogshortcutdirectory'
originshortcutdirectory = 'uplayshortcutdirectory'
battlenetshortcutdirectory = 'eaappshortcutdirectory'
amazonshortcutdirectory = 'itchioshortcutdirectory'
legacyshortcutdirectory = 'humbleshortcutdirectory'
indieshortcutdirectory = 'rockstarshortcutdirectory'
if epicshortcutdirectory != '':
# Create a new entry for the Steam shortcut
new_entry = {
'appid': '',
'AppName': 'Epic Games',
'Exe': 'epicshortcutdirectory′,epicshortcutdirectory',
'icon': '',
'ShortcutPath': '',
'LaunchOptions': '$epiclaunchoptions',
'IsHidden': 0,
'AllowDesktopConfig': 1,
'AllowOverlay': 1,
'OpenVR': 0,
'Devkit': 0,
'DevkitGameID': '',
'LastPlayTime': 0,
'tags': {
'0': 'favorite'
}
}
# Add the new entry to the shortcuts dictionary
entry_exists = False
if type(shortcuts['shortcuts']) == list:
for entry in shortcuts['shortcuts']:
entry.setdefault('AppName', '')
entry.setdefault('Exe', '')
if entry['AppName'] == new_entry['AppName'] and entry['Exe'] == new_entry['Exe']:
entry_exists = True
break
if not entry_exists:
shortcuts['shortcuts'].append(new_entry)
elif type(shortcuts['shortcuts']) == dict:
for key in shortcuts['shortcuts'].keys():
shortcuts['shortcuts'][key].setdefault('AppName', '')
shortcuts['shortcuts'][key].setdefault('Exe', '')
if shortcuts['shortcuts'][key]['AppName'] == new_entry['AppName'] and shortcuts['shortcuts'][key]['Exe'] == new_entry['Exe']:
entry_exists = True
break
if not entry_exists:
# Check if the shortcuts['shortcuts'] dictionary is empty
if not shortcuts['shortcuts']:
max_key = -1
else:
# Find the highest key value
max_key = max(int(key) for key in shortcuts['shortcuts'].keys())
# Add the new entry with a key value one higher than the current maximum
shortcuts['shortcuts'][str(max_key + 1)] = new_entry