Esempio n. 1
0
 def test_game_with_same_slug_is_updated(self):
     games_db.add_game(name="some game", runner="linux")
     game = games_db.get_game_by_field("some-game", "slug")
     self.assertFalse(game['directory'])
     games_db.add_or_update(name="some game", runner='linux', directory="/foo")
     game = games_db.get_game_by_field("some-game", "slug")
     self.assertEqual(game['directory'], '/foo')
Esempio n. 2
0
 def test_get_game_list(self):
     self.game_id = games_db.add_game(name="LutrisTest", runner="Linux")
     game_list = games_db.get_games()
     self.assertEqual(game_list[0]['id'], self.game_id)
     self.assertEqual(game_list[0]['slug'], 'lutristest')
     self.assertEqual(game_list[0]['name'], 'LutrisTest')
     self.assertEqual(game_list[0]['runner'], 'Linux')
Esempio n. 3
0
 def install_from_steam(self, manifest):
     """Create a new Lutris game based on an existing Steam install"""
     if not manifest.is_installed():
         return
     appid = manifest.steamid
     if appid in self.excluded_appids:
         return
     service_game = ServiceGameCollection.get_game(self.id, appid)
     if not service_game:
         return
     lutris_game_id = "%s-%s" % (self.id, appid)
     existing_game = get_game_by_field(lutris_game_id, "slug")
     if existing_game:
         return
     game_config = LutrisConfig().game_level
     game_config["game"]["appid"] = appid
     configpath = write_game_config(lutris_game_id, game_config)
     game_id = add_game(
         name=service_game["name"],
         runner="steam",
         slug=slugify(service_game["name"]),
         installed=1,
         installer_slug=lutris_game_id,
         configpath=configpath,
         platform="Linux",
         service=self.id,
         service_id=appid,
     )
     return game_id
Esempio n. 4
0
    def on_game_duplicate(self, _widget):
        confirm_dlg = QuestionDialog({
            "parent":
            self.window,
            "question":
            _("Do you wish to duplicate %s?\nThe configuration will be duplicated, "
              "but the games files will <b>not be duplicated</b>.") %
            gtk_safe(self.game.name),
            "title":
            _("Duplicate game?"),
        })
        if confirm_dlg.result != Gtk.ResponseType.YES:
            return

        assigned_name = get_unusued_game_name(self.game.name)
        old_config_id = self.game.game_config_id
        if old_config_id:
            new_config_id = duplicate_game_config(self.game.slug,
                                                  old_config_id)
        else:
            new_config_id = None

        db_game = get_game_by_field(self.game.id, "id")
        db_game["name"] = assigned_name
        db_game["configpath"] = new_config_id
        db_game.pop("id")
        # Disconnect duplicate from service- there should be at most
        # 1 PGA game for a service game.
        db_game.pop("service", None)
        db_game.pop("service_id", None)

        game_id = add_game(**db_game)
        new_game = Game(game_id)
        new_game.save()
Esempio n. 5
0
 def install_from_origin(self, origin_game, manifest):
     offer_id = manifest["id"].split("@")[0]
     logger.debug("Installing Origin game %s", offer_id)
     service_game = ServiceGameCollection.get_game("origin", offer_id)
     if not service_game:
         logger.error(
             "Aborting install, %s is not present in the game library.",
             offer_id)
         return
     lutris_game_id = slugify(service_game["name"]) + "-" + self.id
     existing_game = get_game_by_field(lutris_game_id, "installer_slug")
     if existing_game:
         return
     game_config = LutrisConfig(
         game_config_id=origin_game["configpath"]).game_level
     game_config["game"]["args"] = get_launch_arguments(manifest["id"])
     configpath = write_game_config(lutris_game_id, game_config)
     game_id = add_game(
         name=service_game["name"],
         runner=origin_game["runner"],
         slug=slugify(service_game["name"]),
         directory=origin_game["directory"],
         installed=1,
         installer_slug=lutris_game_id,
         configpath=configpath,
         service=self.id,
         service_id=offer_id,
     )
     return game_id
Esempio n. 6
0
    def install_from_ubisoft(self, ubisoft_connect, game):
        app_name = game["name"]

        lutris_game_id = slugify(game["name"]) + "-" + self.id
        existing_game = get_game_by_field(lutris_game_id, "installer_slug")
        if existing_game:
            logger.debug("Ubisoft Connect game %s is already installed",
                         app_name)
            return
        logger.debug("Installing Ubisoft Connect game %s", app_name)
        game_config = LutrisConfig(
            game_config_id=ubisoft_connect["configpath"]).game_level
        game_config["game"]["args"] = f"uplay://launch/{game['appid']}"
        configpath = write_game_config(lutris_game_id, game_config)
        game_id = add_game(
            name=game["name"],
            runner=self.runner,
            slug=slugify(game["name"]),
            directory=ubisoft_connect["directory"],
            installed=1,
            installer_slug=lutris_game_id,
            configpath=configpath,
            service=self.id,
            service_id=game["appid"],
        )
        return game_id
Esempio n. 7
0
 def install_from_egs(self, egs_game, manifest):
     """Create a new Lutris game based on an existing EGS install"""
     app_name = manifest["AppName"]
     logger.debug("Installing EGS game %s", app_name)
     service_game = ServiceGameCollection.get_game("egs", app_name)
     if not service_game:
         logger.error("Aborting install, %s is not present in the game library.", app_name)
         return
     lutris_game_id = slugify(service_game["name"]) + "-" + self.id
     existing_game = get_game_by_field(lutris_game_id, "installer_slug")
     if existing_game:
         return
     game_config = LutrisConfig(game_config_id=egs_game["configpath"]).game_level
     game_config["game"]["args"] = get_launch_arguments(app_name)
     configpath = write_game_config(lutris_game_id, game_config)
     game_id = add_game(
         name=service_game["name"],
         runner=egs_game["runner"],
         slug=slugify(service_game["name"]),
         directory=egs_game["directory"],
         installed=1,
         installer_slug=lutris_game_id,
         configpath=configpath,
         service=self.id,
         service_id=app_name,
     )
     return game_id
Esempio n. 8
0
def scan_directory(dirname):
    files = os.listdir(dirname)
    folder_extentions = {os.path.splitext(filename)[1] for filename in files}
    core_matches = {}
    for core in RECOMMENDED_CORES:
        for ext in RECOMMENDED_CORES[core].get("extensions", []):
            if ext in folder_extentions:
                core_matches[ext] = core
    added_games = []
    for filename in files:
        name, ext = os.path.splitext(filename)
        if ext not in core_matches:
            continue
        for flag in ROM_FLAGS:
            name = name.replace(" (%s)" % flag, "")
        for flag in EXTRA_FLAGS:
            name = name.replace("[%s]" % flag, "")
        if ", The" in name:
            name = "The %s" % name.replace(", The", "")
        name = name.strip()
        print("Importing '%s'" % name)
        slug = slugify(name)
        core = core_matches[ext]
        config = {
            "game": {
                "core": core_matches[ext],
                "main_file": os.path.join(dirname, filename)
            }
        }
        installer_slug = "%s-libretro-%s" % (slug, core)
        existing_game = get_games(filters={
            "installer_slug": installer_slug,
            "installed": "1"
        })
        if existing_game:
            game = Game(existing_game[0]["id"])
            game.remove()
        configpath = write_game_config(slug, config)
        game_id = add_game(name=name,
                           runner="libretro",
                           slug=slug,
                           directory=dirname,
                           installed=1,
                           installer_slug=installer_slug,
                           configpath=configpath)
        print("Imported %s" % name)
        added_games.append(game_id)
    return added_games
Esempio n. 9
0
 def simple_install(self, db_game):
     """A simplified version of the install method, used when a game doesn't need any setup"""
     installer = self.generate_installer(db_game)
     configpath = write_game_config(db_game["slug"], installer["script"])
     game_id = add_game(
         name=installer["name"],
         runner=installer["runner"],
         slug=installer["game_slug"],
         directory=self.get_game_directory(installer),
         installed=1,
         installer_slug=installer["slug"],
         configpath=configpath,
         service=self.id,
         service_id=db_game["appid"],
     )
     return game_id
Esempio n. 10
0
def scan_directory(dirname):
    """Add a directory of ROMs as Lutris games"""
    files = os.listdir(dirname)
    folder_extentions = {os.path.splitext(filename)[1] for filename in files}
    core_matches = {}
    for core in RECOMMENDED_CORES:
        for ext in RECOMMENDED_CORES[core].get("extensions", []):
            if ext in folder_extentions:
                core_matches[ext] = core
    added_games = []
    for filename in files:
        name, ext = os.path.splitext(filename)
        if ext not in core_matches:
            continue
        logger.info("Importing '%s'", name)
        slug = slugify(name)
        core = core_matches[ext]
        config = {
            "game": {
                "core": core_matches[ext],
                "main_file": os.path.join(dirname, filename)
            }
        }
        installer_slug = "%s-libretro-%s" % (slug, core)
        existing_game = get_games(filters={"installer_slug": installer_slug})
        if existing_game:
            game = Game(existing_game[0]["id"])
            game.remove()
        configpath = write_game_config(slug, config)
        game_id = add_game(name=name,
                           runner="libretro",
                           slug=slug,
                           directory=dirname,
                           installed=1,
                           installer_slug=installer_slug,
                           configpath=configpath)
        added_games.append(game_id)
    return added_games
Esempio n. 11
0
 def install_from_egs(self, egs_game, manifest):
     """Create a new Lutris game based on an existing EGS install"""
     app_name = manifest["AppName"]
     service_game = ServiceGameCollection.get_game("egs", app_name)
     lutris_game_id = "egs-" + app_name
     existing_game = get_game_by_field(lutris_game_id, "slug")
     if existing_game:
         return
     game_config = LutrisConfig(
         game_config_id=egs_game["configpath"]).game_level
     game_config["game"]["args"] = get_launch_arguments(app_name)
     configpath = write_game_config(lutris_game_id, game_config)
     game_id = add_game(
         name=service_game["name"],
         runner=egs_game["runner"],
         slug="egs-" + app_name,
         directory=egs_game["directory"],
         installed=1,
         installer_slug="egs-" + app_name,
         configpath=configpath,
         service=self.id,
         service_id=app_name,
     )
     return game_id
Esempio n. 12
0
        name = name.replace("[%s]" % flag, "")
    if ", The" in name:
        name = "The %s" % name.replace(", The", "")
    name = name.strip()
    print("Importing '%s'" % name)
    slug = slugify(name)
    core = core_matches[ext]
    config = {
        "game": {
            "core": core_matches[ext],
            "main_file": os.path.join(dirname, filename)
        }
    }
    installer_slug = "%s-libretro-%s" % (slug, core)
    existing_game = get_games(filters={
        "installer_slug": installer_slug,
        "installed": "1"
    })
    if existing_game:
        game = Game(existing_game[0]["id"])
        game.remove()
    configpath = write_game_config(slug, config)
    game_id = add_game(name=name,
                       runner="libretro",
                       slug=slug,
                       directory=dirname,
                       installed=1,
                       installer_slug=installer_slug,
                       configpath=configpath)
    print("Imported %s" % name)
Esempio n. 13
0
 def setUp(self):
     super(TestPersonnalGameArchive, self).setUp()
     self.game_id = games_db.add_game(name="LutrisTest", runner="Linux")
Esempio n. 14
0
 def test_can_filter_by_installed_games(self):
     games_db.add_game(name="installed_game", runner="Linux", installed=1)
     games_db.add_game(name="bang", runner="Linux", installed=0)
     game_list = games_db.get_games(filters={'installed': 1})
     self.assertEqual(len(game_list), 1)
     self.assertEqual(game_list[0]['name'], 'installed_game')
Esempio n. 15
0
 def test_filter(self):
     games_db.add_game(name="foobar", runner="Linux")
     games_db.add_game(name="bang", runner="Linux")
     game_list = games_db.get_games(searches={"name": 'bang'})
     self.assertEqual(len(game_list), 1)
     self.assertEqual(game_list[0]['name'], 'bang')
Esempio n. 16
0
 def test_delete_game(self):
     game_id = games_db.add_game(name="LutrisTest", runner="Linux")
     games_db.delete_game(game_id)
     game_list = games_db.get_games()
     self.assertEqual(len(game_list), 0)
Esempio n. 17
0
 def test_add_game(self):
     games_db.add_game(name="LutrisTest", runner="Linux")
     game_list = games_db.get_games()
     game_names = [item['name'] for item in game_list]
     self.assertTrue("LutrisTest" in game_names)