diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-05-28 18:13:05 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-05-28 18:13:05 +0200 |
commit | 9204f4ed27573517f7204e1024c8b32bef760ae5 (patch) | |
tree | 4c22f75453d0d6fdafc48edc9a0a43fc730eca16 | |
parent | b1881726ec15c7c6ab6cc0d14c1f436f2a80fc03 (diff) | |
download | tf2sgu-master.tar.gz tf2sgu-master.tar.bz2 tf2sgu-master.zip |
-rwxr-xr-x | tf2sgu | 37 |
1 files changed, 34 insertions, 3 deletions
@@ -55,6 +55,7 @@ class Profile: def __init__(self, path): self.path = path + self._name = None def __repr__(self): return f"<Profile path={self.path!r}>" @@ -69,6 +70,25 @@ class Profile: """Gives the folder (as Path) for the savegames.""" return self.path / GAME_ID / "local" / "save" + def name(self): + """Gets the personal name of the user.""" + if self._name is not None: + return self._name + + long_id = steam_32_to_64(int(self.user_id)) + loginusers_path = STEAM_PATH / "config" / "loginusers.vdf" + # This should probably be done with a vdf parser, but we want to stay + # away from 3rd party dependencies + with open(loginusers_path, "r") as loginusers: + correct_section = False + for line in loginusers: + if f'"{long_id}"' in line: + correct_section = True + if correct_section and '"PersonaName"' in line: + raw_name = line.split()[1] + self._name = raw_name[1:-1] + return self._name + def saves(self): """Returns a list of all saves available in this profile.""" return read_saves(self.save_dir) @@ -109,6 +129,15 @@ def ask_choice(items, labels=None): print("Invalid choice") +def steam_32_to_64(steam_id): + """Convert a short (32 bit) Steam ID to a long (64 bit) Steam ID.""" + # This is the magic number to convert a 32 bit steam ID (as found in the + # userdata folder) to a 64 bit steam id (as used in the loginusers.vdf). + # For reference, see for example here: + # https://github.com/gorangajic/steam-id-convertor + return steam_id + 76561197960265728 + + def get_steam_profiles(): """Returns steam profiles that have data for Transport Fever 2 assigned.""" profiles = [] @@ -143,7 +172,7 @@ def select_profile(args): return profiles[0] else: labels = [ - f"{profile.user_id}: {len(profile.saves())} savegames" + f"{profile.name()}: {len(profile.saves())} savegames" for profile in profiles ] print("Select your profile:") @@ -161,7 +190,9 @@ def cmd_list_profiles(_args): """List available Steam profiles (with Transport Fever 2 installed).""" profiles = get_steam_profiles() for profile in profiles: - print(profile.user_id, len(profile.saves()), "savegames") + print( + f"{profile.user_id} - {profile.name()} ({len(profile.saves())} savegames)" + ) def cmd_list_locals(args): @@ -376,7 +407,7 @@ def _tui_select_profile(screen, profiles): height, width = screen.getmaxyx() - names = [profile.user_id for profile in profiles] + names = [profile.name() for profile in profiles] view = TuiListView(screen.derwin(height - 5, width, 5, 0), names) view.activate() view.render() |