コード例 #1
0
    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

        values = self.game.set_from_variant_uuid(database_name, variant_uuid)
        if not values:
            return False

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

        from fsgs.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
コード例 #2
0
ファイル: main.py プロジェクト: EdwardBetts/fs-uae-launcher
def main():
    Application("fs-uae-game-system")

    if "--unsupported" in sys.argv:
        if "--http-server" in sys.argv:
            from fsgs.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()
コード例 #3
0
 def find_preferred_game_variant(self, game_uuid):
     print("find_preferred_game_variant 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 = []
     for variant in variants:
         variant["like_rating"], variant["work_rating"] = \
             database.get_ratings_for_game(variant["uuid"])
         variant["personal_rating"], ignored = \
             database.get_ratings_for_game(variant["uuid"])
         variant_uuid = variant["uuid"]
         variant_name = variant["name"]
         variant_name = variant_name.replace("\n", " (")
         variant_name = variant_name.replace(" \u00b7 ", ", ")
         variant_name += ")"
         ordered_list.append(
             ((1 - bool(variant["have"]), 1000 - variant["personal_rating"],
               1000 - variant["like_rating"]), (variant_uuid,
                                                variant_name)))
     ordered_list.sort()
     print("ordered variant list:")
     for variant in ordered_list:
         print("-", variant[1][1])
     # item.configurations = [x[1] for x in ordered_list]
     return ordered_list[0][1][0]
コード例 #4
0
 def find_preferred_game_variant(self, game_uuid):
     print("find_preferred_game_variant 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 = []
     for variant in variants:
         variant["like_rating"], variant["work_rating"] = \
             database.get_ratings_for_game(variant["uuid"])
         variant["personal_rating"], ignored = \
             database.get_ratings_for_game(variant["uuid"])
         variant_uuid = variant["uuid"]
         variant_name = variant["name"]
         variant_name = variant_name.replace("\n", " (")
         variant_name = variant_name.replace(" \u00b7 ", ", ")
         variant_name += ")"
         ordered_list.append(
             ((1 - bool(variant["have"]),
               1000 - variant["personal_rating"],
               1000 - variant["like_rating"]),
              (variant_uuid, variant_name)))
     ordered_list.sort()
     print("ordered variant list:")
     for variant in ordered_list:
         print("-", variant[1][1])
     # item.configurations = [x[1] for x in ordered_list]
     return ordered_list[0][1][0]
コード例 #5
0
    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
コード例 #6
0
    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

        values = self.game.set_from_variant_uuid(database_name, variant_uuid)
        if not values:
            return False

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

        from fsgs.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
コード例 #7
0
 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"]
         name = name.replace("\n", " (")
         name = name.replace(" \u00b7 ", ", ")
         name += ")"
         # ordered_list.append(
         #     ((1 - bool(variant["have"]),
         #       1000 - variant["personal_rating"],
         #       1000 - variant["like_rating"]),
         #      (variant_uuid, variant_name)))
         sort_key = (0, 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
コード例 #8
0
 def set_rating_for_variant(variant_uuid, rating):
     # FIXME: Do asynchronously, add to queue
     client = OAGDClient()
     client.rate_variant(variant_uuid, like=rating)
     like_rating = client.get("like", 0)
     work_rating = client.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()
     LauncherConfig.set("variant_rating", str(like_rating))
コード例 #9
0
 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()
     LauncherConfig.set("variant_rating", str(like_rating))
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
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
コード例 #13
0
ファイル: items.py プロジェクト: FrodeSolheim/fs-uae-launcher
 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
コード例 #14
0
ファイル: lists.py プロジェクト: bopopescu/fs-uae-debian
    def synchronize(self):
        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()
コード例 #15
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
コード例 #16
0
ファイル: items.py プロジェクト: EdwardBetts/fs-uae-launcher
 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
コード例 #17
0
ファイル: items.py プロジェクト: EdwardBetts/fs-uae-launcher
    def create_game_items(cls, words, args=None, filters=None):
        if filters is None:
            filters = []
        search = " ".join(words)
        # query = "SELECT id, name, config, platform, " \
        #         "imageratio, screenratio, year, publisher, developer,
        # subtitle " \
        #        "FROM Game WHERE 1 = 1 {0} ORDER BY sort_key".format(clause)
        # print(query, args)
        # Database.cursor.execute(query, args)
        # item_list = []
        # last_item = None
        # for row in Database.cursor:
        #     if last_item:
        #         if last_item.name == row[1] and last_item.platform == row[3]:
        #             last_item.configurations.append(row[2])
        #             continue
        #     for filter in filters:
        #         if not filter(row):
        #             break
        #     else:
        #         item = GameItem(id=row[0], name=row[1], configurations=[
        # row[2]],
        #                 platform=row[3], ratio=row[4], screenratio=row[5],
        #                 year=row[6], publisher=row[7], developer=row[8],
        #                 subtitlepos=row[9])
        #         item_list.append(item)
        #         last_item = item
        # return item_list

        item_list = []
        local_game_database = Database.instance()
        for game in local_game_database.find_games_new(
                search=search, database_only=True):
            item = GameItem(game)
            item_list.append(item)
        return item_list
コード例 #18
0
 def database(self):
     return Database.instance()
コード例 #19
0
ファイル: items.py プロジェクト: FrodeSolheim/fs-uae-launcher
 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
コード例 #20
0
 def database(self):
     return Database.instance()
コード例 #21
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
コード例 #22
0
def main():
    Application("fs-uae-game-system")

    if "--unsupported" in sys.argv:
        if "--http-server" in sys.argv:
            from fsgs.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()