Exemplo n.º 1
0
    def get_service_games(self, service_name):
        """Switch the current service to service_name and return games if available"""
        service_games = ServiceGameCollection.get_for_service(service_name)
        if service_name == "lutris":
            lutris_games = {g["slug"]: g for g in games_db.get_games()}
        else:
            lutris_games = {
                g["service_id"]: g
                for g in games_db.get_games(
                    filters={"service": self.service.id})
            }

        def get_sort_value(game):
            sort_defaults = {
                "name": "",
                "year": 0,
                "lastplayed": 0.0,
                "installed_at": 0.0,
                "playtime": 0.0,
            }
            lutris_game = lutris_games.get(game["appid"])
            if not lutris_game:
                return sort_defaults[self.view_sorting]
            value = lutris_game[self.view_sorting]
            if value:
                return value
            return sort_defaults[self.view_sorting]

        return [
            self.combine_games(game, lutris_games.get(game["appid"]))
            for game in sorted(service_games,
                               key=get_sort_value,
                               reverse=not self.view_sorting_ascending)
            if self.game_matches(game)
        ]
Exemplo n.º 2
0
 def match_games(self):
     """Matching of service games to lutris games"""
     service_games = {
         str(game["appid"]): game
         for game in ServiceGameCollection.get_for_service(self.id)
     }
     logger.debug("Matching games %s", service_games)
     lutris_games = api.get_api_games(list(service_games.keys()),
                                      service=self.id)
     for lutris_game in lutris_games:
         for provider_game in lutris_game["provider_games"]:
             if provider_game["service"] != self.id:
                 continue
             self.match_game(service_games.get(provider_game["slug"]),
                             lutris_game)
     unmatched_service_games = get_games(
         searches={"installer_slug": self.matcher},
         excludes={"service": self.id})
     for lutris_game in api.get_api_games(
             game_slugs=[g["slug"] for g in unmatched_service_games]):
         for provider_game in lutris_game["provider_games"]:
             if provider_game["service"] != self.id:
                 continue
             self.match_game(service_games.get(provider_game["slug"]),
                             lutris_game)
Exemplo n.º 3
0
 def match_games(self):
     """Matching lutris games is much simpler... No API call needed."""
     service_games = {
         str(game["appid"]): game for game in ServiceGameCollection.get_for_service(self.id)
     }
     for lutris_game in get_games():
         self.match_game(service_games.get(lutris_game["slug"]), lutris_game)
Exemplo n.º 4
0
 def get_games_from_filters(self):
     service_name = self.filters.get("service")
     if service_name in services.get_services():
         self.set_service(service_name)
         service_games = ServiceGameCollection.get_for_service(service_name)
         if service_games:
             return [
                 game
                 for game in sorted(service_games,
                                    key=lambda game: game.get(
                                        self.view_sorting) or game["name"],
                                    reverse=not self.view_sorting_ascending)
                 if self.game_matches(game)
             ]
         if self.service.online and not self.service.is_connected():
             self.show_label(
                 _("Connect your %s account to access your games") %
                 self.service.name)
         return
     self.unset_service()
     dynamic_categories = {
         "running": self.get_running_games,
         "installed": self.get_installed_games
     }
     if self.filters.get("dynamic_category") in dynamic_categories:
         return dynamic_categories[self.filters["dynamic_category"]]()
     if self.filters.get("category"):
         game_ids = categories_db.get_game_ids_for_category(
             self.filters["category"])
         return games_db.get_games_by_ids(game_ids)
     searches, filters, excludes = self.get_sql_filters()
     return games_db.get_games(searches=searches,
                               filters=filters,
                               excludes=excludes,
                               sorts=self.sort_params)
Exemplo n.º 5
0
    def switch_to_service(self, service_name):
        """Switch the current service to service_name and return games if available"""
        def combine_games(service_game, lutris_game):
            if not lutris_game or service_game["appid"] != lutris_game[
                    "service_id"]:
                return service_game
            for field in ("platform", "runner", "year", "installed_at",
                          "lastplayed", "playtime", "installed"):
                service_game[field] = lutris_game[field]
            return service_game

        self.set_service(service_name)
        if service_name == "lutris":
            self.tabs_box.show(
            )  # Only the lutris service has the ability to search through all games.
            if self.website_button.props.active:
                return self.get_api_games()
        else:
            self.tabs_box.hide()

        service_games = ServiceGameCollection.get_for_service(service_name)
        if service_name == "lutris":
            lutris_games = {g["slug"]: g for g in games_db.get_games()}
        else:
            lutris_games = {
                g["service_id"]: g
                for g in games_db.get_games(
                    filters={"service": self.service.id})
            }

        def get_sort_value(game):
            sort_defaults = {
                "name": "",
                "year": 0,
                "lastplayed": 0.0,
                "installed_at": 0.0,
                "playtime": 0.0,
            }
            lutris_game = lutris_games.get(game["appid"])
            if not lutris_game:
                return sort_defaults[self.view_sorting]
            value = lutris_game[self.view_sorting]
            if value:
                return value
            return sort_defaults[self.view_sorting]

        if service_games:
            return [
                combine_games(game, lutris_games.get(game["appid"]))
                for game in sorted(service_games,
                                   key=get_sort_value,
                                   reverse=not self.view_sorting_ascending)
                if self.game_matches(game)
            ]
        if self.service.online and not self.service.is_connected():
            self.show_label(
                _("Connect your %s account to access your games") %
                self.service.name)
        return
Exemplo n.º 6
0
    def get_games_from_filters(self):
        if self.filters.get("service"):
            service_name = self.filters["service"]
            if service_name in services.get_services():
                self.service = services.get_services()[service_name]()
                if self.service.online:
                    self.service.connect("service-login",
                                         self.on_service_games_updated)
                    self.service.connect("service-logout",
                                         self.on_service_logout)
                self.service.connect("service-games-loaded",
                                     self.on_service_games_updated)

                service_games = ServiceGameCollection.get_for_service(
                    service_name)
                if service_games:
                    return [
                        game for game in sorted(
                            service_games,
                            key=lambda game: game.get(self.view_sorting) or
                            game["name"],
                            reverse=not self.view_sorting_ascending,
                        ) if self.game_matches(game)
                    ]

                if not self.service.online or self.service.is_connected():
                    AsyncCall(self.service.load, None)
                    spinner = Gtk.Spinner(visible=True)
                    spinner.start()
                    self.blank_overlay.add(spinner)
                else:
                    self.blank_overlay.add(
                        Gtk.Label(
                            _("Connect your %s account to access your games") %
                            self.service.name,
                            visible=True,
                        ))
                self.blank_overlay.props.visible = True
                return
            self.unset_service()
        dynamic_categories = {
            "running": self.get_running_games,
            "installed": self.get_installed_games,
        }
        if self.filters.get("dynamic_category") in dynamic_categories:
            return dynamic_categories[self.filters["dynamic_category"]]()
        self.unset_service()
        if self.filters.get("category"):
            game_ids = categories_db.get_game_ids_for_category(
                self.filters["category"])
            return games_db.get_games_by_ids(game_ids)

        searches, filters, excludes = self.get_sql_filters()
        return games_db.get_games(
            searches=searches,
            filters=filters,
            excludes=excludes,
            sorts=self.sort_params,
        )
Exemplo n.º 7
0
 def get_media_urls(self):
     """Return URLs for icons and logos from a service"""
     if self.source == "local":
         return {}
     service_games = ServiceGameCollection.get_for_service(self.service)
     medias = {}
     for game in service_games:
         if not game["details"]:
             continue
         details = json.loads(game["details"])
         medias[game["slug"]] = self.url_pattern % details[self.api_field]
     return medias
Exemplo n.º 8
0
 def add_installed_games(self):
     ubisoft_connect = get_game_by_field(self.client_installer, "slug")
     if not ubisoft_connect:
         logger.warning("Ubisoft Connect not installed")
         return
     prefix_path = ubisoft_connect["directory"].split("drive_c")[0]
     prefix = WinePrefixManager(prefix_path)
     for game in ServiceGameCollection.get_for_service(self.id):
         details = json.loads(game["details"])
         install_path = get_ubisoft_registry(prefix,
                                             details.get("registryPath"))
         exe = get_ubisoft_registry(prefix, details.get("exe"))
         if install_path and exe:
             self.install_from_ubisoft(ubisoft_connect, game)
Exemplo n.º 9
0
 def match_games(self):
     """Matching of service games to lutris games"""
     service_games = {
         str(game["appid"]): game
         for game in ServiceGameCollection.get_for_service(self.id)
     }
     lutris_games = api.get_api_games(list(service_games.keys()),
                                      service=self.id)
     for lutris_game in lutris_games:
         for provider_game in lutris_game["provider_games"]:
             if provider_game["service"] != self.id:
                 continue
             self.match_game(service_games.get(provider_game["slug"]),
                             lutris_game["slug"])
Exemplo n.º 10
0
    def get_service_games(self, service_name):
        """Switch the current service to service_name and return games if available"""
        service_games = ServiceGameCollection.get_for_service(service_name)
        if service_name == "lutris":
            lutris_games = {g["slug"]: g for g in games_db.get_games()}
        else:
            lutris_games = {
                g["service_id"]: g
                for g in games_db.get_games(
                    filters={"service": self.service.id})
            }

        def get_sort_value(game):
            sort_defaults = {
                "name": "",
                "year": 0,
                "lastplayed": 0.0,
                "installed_at": 0.0,
                "playtime": 0.0,
            }
            view_sorting = self.view_sorting
            lutris_game = lutris_games.get(game["appid"])
            if not lutris_game:
                return sort_defaults.get(view_sorting, "")
            value = lutris_game.get(view_sorting)
            if value:
                return value
            # Users may have obsolete view_sorting settings, so
            # we must tolerate them. We treat them all as blank.
            return sort_defaults.get(view_sorting, "")

        return [
            self.combine_games(game, lutris_games.get(game["appid"]))
            for game in sorted(service_games,
                               key=get_sort_value,
                               reverse=not self.view_sorting_ascending)
            if self.game_matches(game)
        ]
Exemplo n.º 11
0
 def match_games(self):
     """Matching of service games to lutris games"""
     service_games = {
         str(game["appid"]): game
         for game in ServiceGameCollection.get_for_service(self.id)
     }
     lutris_games = api.get_api_games(list(service_games.keys()),
                                      service=self.id)
     for lutris_game in lutris_games:
         for provider_game in lutris_game["provider_games"]:
             if provider_game["service"] != self.id:
                 continue
             service_game = service_games.get(provider_game["slug"])
             if not service_game:
                 continue
             conditions = {
                 "appid": service_game["appid"],
                 "service": self.id
             }
             sql.db_update(PGA_DB,
                           "service_games",
                           {"lutris_slug": lutris_game["slug"]},
                           conditions=conditions)