Created
June 6, 2025 07:31
-
-
Save sschr15/81f88a1e14323f975157436b74d186b9 to your computer and use it in GitHub Desktop.
A small tool for people who don't know Steam app IDs off the top of their heads but mess with compatdata files anyway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Creates symbolic links for every folder in Steam's `compatdata` directory | |
such that each link's name is the name of the game | |
""" | |
from requests import get | |
from os import symlink, listdir | |
from os.path import isdir, exists | |
from sys import argv | |
from pathlib import Path | |
def load_games() -> dict[str, str]: | |
"""Load the games from the Steam API.""" | |
url = "https://api.steampowered.com/ISteamApps/GetAppList/v2/" | |
response = get(url) | |
if response.status_code != 200: | |
raise Exception("Failed to fetch game list from Steam API") | |
return {str(game['appid']): game['name'] for game in response.json()['applist']['apps']} | |
def create_symlinks(compatdata_path: Path, games: dict[str, str]) -> None: | |
"""Create symbolic links for each game in the compatdata directory.""" | |
for entry in listdir(compatdata_path): | |
entry_path = compatdata_path / entry | |
if isdir(entry_path) and entry in games: | |
link_name = games[entry] | |
if any(char in link_name for char in ('/', '\\')): | |
print(f"Skipping invalid link name: {link_name}") | |
continue | |
link_path = compatdata_path / link_name | |
if not exists(link_path): | |
symlink(entry_path, link_path) | |
print(f"Created symlink: {link_name} -> {entry}") | |
def main(): | |
if len(argv) != 2: | |
cwd = Path.cwd() | |
if not (cwd / 'compatdata').exists(): | |
print("Usage: compatlinks.py <path_to_compatdata>") | |
print(f"Current working directory does not contain 'compatdata': {cwd}") | |
return | |
compatdata_path = cwd / 'compatdata' | |
else: | |
compatdata_path = Path(argv[1]) | |
if not compatdata_path.exists() or not compatdata_path.is_dir(): | |
print(f"Error: {compatdata_path} does not exist or is not a directory.") | |
return | |
if not compatdata_path.is_absolute(): | |
compatdata_path = Path.cwd() / compatdata_path | |
if not compatdata_path.exists(): | |
print(f"Error: {compatdata_path} does not exist.") | |
return | |
if not compatdata_path.is_dir(): | |
print(f"Error: {compatdata_path} is not a directory.") | |
return | |
try: | |
games = load_games() | |
except Exception as e: | |
print(f"Error loading games from Steam API: {e}") | |
return | |
create_symlinks(compatdata_path, games) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment