Move steam game playtime transfer code down to the steam service.

It makes GOG crash, and probably other services too!
This commit is contained in:
Daniel Johnson 2024-01-12 17:01:37 -05:00
parent 0cca6e1bd5
commit 30b62ab94a
2 changed files with 12 additions and 7 deletions

View file

@ -1,5 +1,4 @@
"""Generic service utilities"""
import json
import os
import shutil
from gettext import gettext as _
@ -219,12 +218,6 @@ class BaseService(GObject.Object):
conditions={"id": game["id"]}
)
# Copy playtimes from Steam's data
for game in get_games(filters={"service": self.id, "service_id": service_game["appid"]}):
steam_game_playtime = json.loads(service_game["details"]).get("playtime_forever")
playtime = steam_game_playtime / 60
sql.db_update(PGA_DB, "games", {"playtime": playtime}, conditions={"id": game["id"]})
def match_games(self):
"""Matching of service games to lutris games"""
service_games = {

View file

@ -8,6 +8,7 @@ from gi.repository import Gio
from lutris import settings
from lutris.config import LutrisConfig, write_game_config
from lutris.database import sql
from lutris.database.games import add_game, get_game_by_field, get_games
from lutris.database.services import ServiceGameCollection
from lutris.game import Game
@ -21,6 +22,8 @@ from lutris.util.steam.appmanifest import AppManifest, get_appmanifests
from lutris.util.steam.config import get_active_steamid64, get_steam_library, get_steamapps_dirs
from lutris.util.strings import slugify
PGA_DB = settings.PGA_DB
class SteamBanner(ServiceMedia):
service = "steam"
@ -107,6 +110,15 @@ class SteamService(BaseService):
self.match_games()
return steam_games
def match_game(self, service_game, lutris_game):
super().match_game(service_game, lutris_game)
# Copy playtimes from Steam's data
for game in get_games(filters={"service": self.id, "service_id": service_game["appid"]}):
steam_game_playtime = json.loads(service_game["details"]).get("playtime_forever")
playtime = steam_game_playtime / 60
sql.db_update(PGA_DB, "games", {"playtime": playtime}, conditions={"id": game["id"]})
def get_installer_files(self, installer, _installer_file_id, _selected_extras):
steam_uri = "$STEAM:%s:."
appid = str(installer.script["game"]["appid"])