Esempio n. 1
0
    def synchronize(self):
        if not self.is_authenticated():
            print("ListsSynchronizer: not authenticated")
            return

        if self.stop_check():
            return

        if "lists" not in self.context.meta:
            # Haven't looked up synchronization information from the server.
            return

        self.set_status(gettext("Updating game lists..."))

        database = Database.instance()
        cursor = database.cursor()
        cursor.execute("SELECT uuid, name, sync FROM game_list")
        # existing_lists = {}
        existing_syncs = {}
        for row in cursor:
            uuid, name, sync = row
            # existing_lists[uuid] = {
            #     "name": name,
            #     "sync": sync,
            # }
            existing_syncs[uuid] = sync
        # existing_syncs.sort()

        for list_uuid, list_info in self.context.meta["lists"].items():
            if list_info["sync"] == existing_syncs.get(list_uuid, None):
                print("[SYNC] List {} already synced".format(list_uuid))
            else:
                self.set_status(
                    gettext("Updating list '{0}'...".format(list_info["name"]))
                )
                self.synchronize_list(database, list_uuid, list_info)

        for existing_list_uuid in existing_syncs:
            for list_uuid in self.context.meta["lists"]:
                if list_uuid == existing_list_uuid:
                    break
            else:
                # this old list should be removed
                self.set_status(
                    gettext("Removing list {0}".format(existing_list_uuid))
                )
                self.remove_list(database, existing_list_uuid)

        database.commit()
 def populate_list(self):
     database = Database.instance()
     self.game_lists = database.get_game_lists()
     if len(self.game_lists) > 0:
         self.game_lists.insert(0, ["", self.ITEM_SEPARATOR])
     self.game_lists.insert(0, [Database.GAME_LIST_GAMES, gettext("Games")])
     self.game_lists.insert(
         0, [Database.GAME_LIST_CONFIGS, gettext("Configs")]
     )
     self.game_lists.insert(0, ["", gettext("Configs and Games")])
     self.clear()
     for item in self.game_lists:
         list_name = item[1]
         if list_name == "Favorites":
             list_name = gettext("Favorites")
         self.add_item(list_name)
 def set_rating_for_variant(variant_uuid, rating):
     # FIXME: Do asynchronously, add to queue
     client = OGDClient()
     result = client.rate_variant(variant_uuid, like=rating)
     like_rating = result.get("like", 0)
     work_rating = result.get("work", 0)
     database = Database.instance()
     cursor = database.cursor()
     cursor.execute("DELETE FROM rating WHERE game_uuid = ?",
                    (variant_uuid, ))
     cursor.execute(
         "INSERT INTO rating (game_uuid, work_rating, like_rating) "
         "VALUES (?, ?, ?)",
         (variant_uuid, work_rating, like_rating),
     )
     database.commit()
     LauncherSettings.set("__variant_rating", str(like_rating))
Esempio n. 4
0
 def create_game_items(cls, words, args=None, filters=None, list_uuid=None):
     if filters is None:
         filters = []
     search = " ".join(words)
     item_list = []
     local_game_database = Database.instance()
     for game in local_game_database.find_games_new(search=search,
                                                    database_only=True,
                                                    list_uuid=list_uuid):
         item = GameItem(game)
         for filter in filters:
             pass
             # if not filter(game):
             #     break
         else:
             item_list.append(item)
     return item_list
Esempio n. 5
0
 def activate(self, menu):
     print("PlatformMenuItem.activate")
     new_menu = create_item_menu(gettext("Select Platform"))
     menu_path = self.create_menu_path(menu)
     new_menu.update_path(menu_path)
     with Database.instance() as database:
         cursor = database.cursor()
         cursor.execute(
             "SELECT DISTINCT platform FROM game WHERE have >= 3 "
             "ORDER BY platform")
         items = []
         for row in cursor:
             if not row[0]:
                 continue
             item = PlatformItem(row[0])
             items.append((item.sort_title, item))
         for sort_title, item in sorted(items):
             new_menu.append(item)
     return new_menu
    def load_game_variant(self, variant_uuid):
        # game_database = fsgs.get_game_database()
        # values = game_database.get_game_values_for_uuid(variant_uuid)

        from .Database import Database

        database = Database.instance()
        try:
            database_name = database.find_game_database_for_game_variant(
                variant_uuid
            )
        except LookupError:
            return False

        try:
            values = self.game.set_from_variant_uuid(
                database_name, variant_uuid
            )
        except KeyError:
            # It is possible that the variant is found without game entry,
            # which raises a KeyError.
            return False
        if not values:
            return False

        # print("")
        # for key in sorted(values.keys()):
        #     print(" * {0} = {1}".format(key, values[key]))
        # print("")

        from fsgamesys.platforms.platform import PlatformHandler

        platform_handler = PlatformHandler.create(self.game.platform.id)
        loader = platform_handler.get_loader(self)
        self.config.load(loader.load_values(values))
        return True
    def get_ordered_game_variants(self, game_uuid):
        print("get_ordered_game_variants game_uuid =", game_uuid)
        from .Database import Database

        database = Database.instance()
        variants = database.find_game_variants_new(game_uuid=game_uuid)
        print(variants)
        # ordered_list = []
        # FIXME: Merge code with VariantsBrowser.py
        sortable_items = []
        for i, variant in enumerate(variants):
            game_database = self.game_database(variant["database"])
            (
                variant["like_rating"],
                variant["work_rating"],
            ) = game_database.get_ratings_for_game(variant["uuid"])
            (
                variant["personal_rating"],
                ignored,
            ) = database.get_ratings_for_game(variant["uuid"])
            # variant_uuid = variant["uuid"]

            name = variant["name"]
            # FIXME: name replacement needed any more?
            name = name.replace("\n", " (")
            name = name.replace(" \u00b7 ", ", ")
            name += ")"

            if variant["published"] == 0:
                primary_sort = 1
                variant["name"] = "[UNPUBLISHED] " + variant["name"]
            else:
                primary_sort = 0
            sort_key = (
                primary_sort,
                1000000 - variant["like_rating"],
                1000000 - variant["work_rating"],
                name,
            )
            sortable_items.append((sort_key, i, variant))
        ordered_list = [x[2] for x in sorted(sortable_items)]
        print("ordered variant list:")
        for variant in ordered_list:
            print("-", variant["name"])
        # item.configurations = [x[1] for x in ordered_list]
        select_index = None
        if select_index is None:
            # default index selection
            for i, variant in enumerate(ordered_list):
                if variant["personal_rating"] == 5:
                    select_index = i
                    break
            else:
                for i, variant in enumerate(ordered_list):
                    if variant["have"] >= 3:
                        select_index = i
                        break
                else:
                    for i, variant in enumerate(ordered_list):
                        if variant["have"] >= 1:
                            select_index = i
                            break
                    else:
                        if len(ordered_list) > 0:
                            select_index = 0
        # return ordered_list[select_index]["uuid"]
        if select_index and select_index > 0:
            ordered_list.insert(0, ordered_list.pop(select_index))
        return ordered_list
 def database(self):
     return Database.instance()
Esempio n. 9
0
 def get_game_lists(cls):
     result = []
     local_game_database = Database.instance()
     for list_uuid, list_name in local_game_database.get_game_lists():
         result.append((list_name, list_uuid))
     return result
Esempio n. 10
0
def main():
    Application("fs-uae-game-system")

    if "--unsupported" in sys.argv:
        if "--http-server" in sys.argv:
            from fsgamesys.http.server import http_server_main

            return http_server_main()

    if len(sys.argv) < 3:
        print("")
        print("usage: fsgs run <game>")
        print("")
        print("game:")
        print(" - search term(s) identifying a single game")
        print(" - path to a .fsgs file")
        print(" - path to a recognized cartridge ROM or disk file format")
        print("")
        sys.exit(1)
    assert sys.argv[1] == "run"
    game_arg = " ".join(sys.argv[2:])
    print(game_arg)
    if os.path.exists(game_arg):
        load_file(game_arg)
    else:
        search = game_arg.lower()
        database = Database.instance()
        # cursor.execute("SELECT id FROM game WHERE name like")
        terms = GameNameUtil.extract_search_terms(search)
        found_games = database.find_games_new(" ".join(terms))
        games = []
        for game in found_games:
            print(list(game))
            if game[0]:
                # only process entries with a game uuid
                games.append(game)
        game_uuid = None
        if len(games) == 0:
            print("no games found")
            sys.exit(2)
        if len(games) > 1:
            matches = 0
            for row in games:
                if row[1].lower() == search:
                    if game_uuid is None:
                        game_uuid = row[0]
                        matches += 1
            if matches != 1:
                print("")
                print("More than one game matches:")
                print("")
                for row in games:
                    print("    {0} ({1})".format(row[1], row[2]))
                    print("        {0}".format(row[0]))
                print("")
                sys.exit(3)
        game_uuid = games[0][0]
        assert game_uuid
        variant_uuid = find_preferred_variant(game_uuid)
        load_game_variant(variant_uuid)
    fsgs.run_game()