def config_startup_scan(cls): if cls._config_scanned: return cls._config_scanned = True configs_dir = FSGSDirectories.get_configurations_dir() print("config_startup_scan", configs_dir) print(LauncherSettings.settings) settings_mtime = LauncherSettings.get("configurations_dir_mtime") dir_mtime = cls.get_dir_mtime_str(configs_dir) if settings_mtime == dir_mtime + "+" + str(Database.VERSION): print("... mtime not changed", settings_mtime, dir_mtime) return database = Database.get_instance() file_database = FileDatabase.get_instance() print("... database.find_local_configurations") local_configs = Database.get_instance().find_local_configurations() print("... walk configs_dir") for dir_path, dir_names, file_names in os.walk(configs_dir): for file_name in file_names: if not file_name.endswith(".fs-uae"): continue path = Paths.join(dir_path, file_name) if path in local_configs: local_configs[path] = None # already exists in database continue name, ext = os.path.splitext(file_name) # search = ConfigurationScanner.create_configuration_search( # name) scanner = ConfigurationScanner() print("[startup] adding config", path) file_database.delete_file(path=path) with open(path, "rb") as f: sha1 = hashlib.sha1(f.read()).hexdigest() file_database.add_file(path=path, sha1=sha1) game_id = database.add_configuration( path=path, name=scanner.create_configuration_name(name) ) database.update_game_search_terms( game_id, scanner.create_search_terms(name) ) for path, config_id in local_configs.items(): if config_id is not None: print("[startup] removing configuration", path) database.delete_game(id=config_id) file_database.delete_file(path=path) print("... commit") database.commit() LauncherSettings.set( "configurations_dir_mtime", cls.get_dir_mtime_str(configs_dir) + "+" + str(Database.VERSION), )
def config_startup_scan(cls): if cls._config_scanned: return cls._config_scanned = True configs_dir = FSGSDirectories.get_configurations_dir() print("config_startup_scan", configs_dir) print(LauncherSettings.settings) settings_mtime = LauncherSettings.get("configurations_dir_mtime") dir_mtime = cls.get_dir_mtime_str(configs_dir) if settings_mtime == dir_mtime + "+" + str(Database.VERSION): print("... mtime not changed", settings_mtime, dir_mtime) return database = Database.get_instance() file_database = FileDatabase.get_instance() print("... database.find_local_configurations") local_configs = Database.get_instance().find_local_configurations() print("... walk configs_dir") for dir_path, dir_names, file_names in os.walk(configs_dir): for file_name in file_names: if not file_name.endswith(".fs-uae"): continue path = Paths.join(dir_path, file_name) if path in local_configs: local_configs[path] = None # already exists in database continue name, ext = os.path.splitext(file_name) # search = ConfigurationScanner.create_configuration_search( # name) scanner = ConfigurationScanner() print("[startup] adding config", path) file_database.delete_file(path=path) with open(path, "rb") as f: sha1 = hashlib.sha1(f.read()).hexdigest() file_database.add_file(path=path, sha1=sha1) game_id = database.add_configuration( path=path, name=scanner.create_configuration_name(name)) database.update_game_search_terms( game_id, scanner.create_search_terms(name)) for path, config_id in local_configs.items(): if config_id is not None: print("[startup] removing configuration", path) database.delete_game(id=config_id) file_database.delete_file(path=path) print("... commit") database.commit() LauncherSettings.set( "configurations_dir_mtime", cls.get_dir_mtime_str(configs_dir) + "+" + str(Database.VERSION), )
def update_search(self): search = LauncherSettings.get("config_search").strip().lower() print("search for", search) words = [] special = [] for word in search.split(" "): word = word.strip() if not word: continue if ":" in word[1:-1]: special.append(word) else: words.append(word) terms = GameNameUtil.extract_search_terms(" ".join(words)) terms.update(special) database = Database.get_instance() try: have = int(LauncherSettings.get("database_show_games")) except ValueError: # default is show all downloadable and locally available games have = 1 items = database.find_games_new( " ".join(terms), have=have, list_uuid=LauncherSettings.get("game_list_uuid"), ) self.set_items(items)
def scan_thread(cls): try: with Database.get_instance() as database: cls._scan_thread(database) except Exception as e: cls.error = str(e) traceback.print_exc() # else: # if cls.on_status: # cls.on_status(("", _("Committing data..."))) # database.commit() def on_done(): # FIXME: these should be removed soon LauncherSettings.set("last_scan", str(time.time())) LauncherSettings.set("__config_refresh", str(time.time())) # this must be called from main, since callbacks are broadcast # when settings are changed LauncherSignal.broadcast("scan_done") LauncherConfig.update_kickstart() # call on_done from main thread fsui.call_after(on_done) cls.running = False
def update_search(self): search = LauncherSettings.get("config_search").strip().lower() print("search for", search) words = [] special = [] for word in search.split(" "): word = word.strip() if not word: continue if ":" in word[1:-1]: special.append(word) else: words.append(word) terms = GameNameUtil.extract_search_terms(" ".join(words)) terms.update(special) database = Database.get_instance() try: have = int(LauncherSettings.get("database_show_games")) except ValueError: # default is show all downloadable and locally available games have = 1 items = database.find_games_new( " ".join(terms), have=have, list_uuid=LauncherSettings.get("game_list_uuid")) self.set_items(items)
def run(self): self.defragment(FileDatabase.get_instance(), "Files.sqlite") self.stop_check() self.defragment(LockerDatabase.instance(), "Locker.sqlite") self.stop_check() self.defragment(fsgs.get_game_database(), "Amiga.sqlite") self.stop_check() self.defragment(Database.get_instance(), "Database.sqlite")
def load_configuration(self, item): if item[str("uuid")]: LauncherSettings.set("parent_uuid", item[str("uuid")]) else: config_path = Database.get_instance().decode_path( item[str("path")]) print("load config from", config_path) LauncherConfig.load_file(config_path) LauncherSettings.set("parent_uuid", "")
def temp_fix_configs(self, item): from fsgs.Database import Database local_game_database = Database.get_instance() game_database = fsgs.get_game_database() variants = local_game_database.find_game_variants_new( game_uuid=item.uuid) print(variants) ordered_list = [] for variant in variants: variant["like_rating"], variant["work_rating"] = \ game_database.get_ratings_for_game(variant["uuid"]) variant["personal_rating"], ignored = \ local_game_database.get_ratings_for_game(variant["uuid"]) # user_rating = variant[5] or 0 # global_rating = variant[3] or 0 # user_rating = 0 # global_rating = 0 variant_uuid = variant["uuid"] # variant[2] variant_name = variant["name"] # variant[1] 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, variant["database"]))) ordered_list.sort() print("ordered variant list:") for variant in ordered_list: print("-", variant[1][1]) item.configurations = [co[1] for co in ordered_list]
def update_list(self, game_uuid): print("VariantsBrowser.update_list, game_uuid=", game_uuid) database = Database.get_instance() items = database.find_game_variants_new(game_uuid, have=0) # items = database.search_configurations(self.search) # FIXME: Merge code with FSGameSystemContext.py sortable_items = [] for i, variant in enumerate(items): name = variant["name"] name = name.replace("\nAmiga \u00b7 ", "\n") # print(name, variant[3]) # name = name.replace("\nCD32 \u00b7 ", "\n") # name = variant[1].replace("\n", " \u00b7 ") # only show variant name (without game name) name = name.split("\n", 1)[-1] game_database = fsgs.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"]) sort_key = (0, 1000000 - variant["like_rating"], 1000000 - variant["work_rating"], name) sortable_items.append((sort_key, i, variant)) # print(sortable_items) self.items = [x[2] for x in sorted(sortable_items)] self.update() # self.set_items(self.items) # self.set_item_count(len(self.items)) self.select_item(None, signal=False) select_index = None list_uuid = LauncherSettings.get("game_list_uuid") if list_uuid: list_variant_uuid = database.get_variant_for_list_and_game( list_uuid, game_uuid) print("game list", list_uuid, "override variant", list_variant_uuid) else: list_variant_uuid = None if list_variant_uuid: # override variant selection from list if possible for i, variant in enumerate(self.items): print(variant["uuid"], variant["name"], list_variant_uuid) if variant["uuid"] == list_variant_uuid: select_index = i print("override select index", select_index) break if select_index is None: # default index selection for i, variant in enumerate(self.items): if variant["personal_rating"] == 5: select_index = i break else: for i, variant in enumerate(self.items): if variant["have"] >= 3: select_index = i break else: for i, variant in enumerate(self.items): if variant["have"] >= 1: select_index = i break else: if len(self.items) > 0: select_index = 0 # self.clear() # for i, variant in enumerate(self.items): # self.add_item(variant["name"], icon=self.get_item_icon(i)) self.enable(len(self.items) > 0) if select_index is not None: print("selecting variant index", select_index) self.select_item(select_index) else: ConfigGroup.new_config()
def on_select_item(self, index): # index = self.get_index() database = Database.get_instance() info = database.get_game_info(self.items[index][0]) self.set_game_info(info)
def search(self, search): print("search for", search) database = Database.get_instance() items = database.search_games(search) self.set_items(items)
def update_list(self, game_uuid): print("VariantsBrowser.update_list, game_uuid=", game_uuid) database = Database.get_instance() items = database.find_game_variants_new(game_uuid, have=0) # items = database.search_configurations(self.search) # FIXME: Merge code with # FSGameSystemContext.py:get_ordered_game_variants sortable_items = [] for i, variant in enumerate(items): name = variant["name"] # assert "\n" not in name # only show variant name (without game name) # name = name.split("\n", 1)[-1] game_database = fsgs.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"]) 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)) # print(sortable_items) self.items = [x[2] for x in sorted(sortable_items)] self.update() # self.set_items(self.items) # self.set_item_count(len(self.items)) self.select_item(None, signal=False) select_index = None list_uuid = LauncherSettings.get("game_list_uuid") if list_uuid: list_variant_uuid = database.get_variant_for_list_and_game( list_uuid, game_uuid ) print( "game list", list_uuid, "override variant", list_variant_uuid ) else: list_variant_uuid = None if list_variant_uuid: # override variant selection from list if possible for i, variant in enumerate(self.items): print(variant["uuid"], variant["name"], list_variant_uuid) if variant["uuid"] == list_variant_uuid: select_index = i print("override select index", select_index) break if select_index is None: # default index selection for i, variant in enumerate(self.items): if variant["personal_rating"] == 5: if variant["have"] >= 3: select_index = i break else: # FIXME: Add warning here that the favorite variant # could not be selected. pass else: for i, variant in enumerate(self.items): if variant["have"] >= 3: select_index = i break else: for i, variant in enumerate(self.items): if variant["have"] >= 1: select_index = i break else: if len(self.items) > 0: select_index = 0 # self.clear() # for i, variant in enumerate(self.items): # self.add_item(variant["name"], icon=self.get_item_icon(i)) self.enable(len(self.items) > 0) if select_index is not None: print("selecting variant index", select_index) self.select_item(select_index) else: ConfigGroup.new_config()
def save_config(): print("SaveButton.save_config") database = Database.get_instance() name = LauncherSettings.get("config_name").strip() if not name: print("no config_name") # FIXME: notify user return file_name = name + ".fs-uae" path = os.path.join(FSGSDirectories.get_configurations_dir(), file_name) with io.open(path, "w", encoding="UTF-8") as f: f.write("# FS-UAE configuration saved by FS-UAE Launcher\n") f.write("# Last saved: {0}\n".format( datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"))) f.write("\n[fs-uae]\n") keys = sorted(fsgs.config.values.keys()) for key in keys: value = LauncherConfig.get(key) if key.startswith("__"): continue if key in LauncherConfig.no_save_keys_set: continue # elif key == "joystick_port_2_mode" and value == "nothing": # continue # elif key == "joystick_port_3_mode" and value == "nothing": # continue if value == LauncherConfig.default_config.get(key, ""): continue if value: f.write("{0} = {1}\n".format(key, value)) # scanner = ConfigurationScanner() # search = ConfigurationScanner.create_configuration_search(name) # name = scanner.create_configuration_name(name) # print("adding", path) # # deleting the path from the database first in case it already exists # database.delete_configuration(path=path) # database.delete_file(path=path) # database.add_file(path=path) # database.add_configuration( # path=path, uuid="", name=name, scan=0, search=search) file_database = FileDatabase.get_instance() scanner = ConfigurationScanner() print("[save config] adding config", path) file_database.delete_file(path=path) with open(path, "rb") as f: sha1 = hashlib.sha1(f.read()).hexdigest() file_database.add_file(path=path, sha1=sha1) game_id = database.add_configuration( path=path, name=scanner.create_configuration_name(name)) database.update_game_search_terms(game_id, scanner.create_search_terms(name)) database.commit() file_database.commit() LauncherSettings.set("__config_refresh", str(time.time())) # Settings.set("config_changed", "0") LauncherConfig.set("__changed", "0")
def update_list(self, game_uuid): print("VariantsBrowser.update_list, game_uuid=", game_uuid) database = Database.get_instance() items = database.find_game_variants_new(game_uuid, have=0) # items = database.search_configurations(self.search) sortable_items = [] for i, item in enumerate(items): name = item["name"] name = name.replace("\nAmiga \u00b7 ", "\n") # print(name, item[3]) # name = name.replace("\nCD32 \u00b7 ", "\n") # name = item[1].replace("\n", " \u00b7 ") # only show variant name (without game name) name = name.split("\n", 1)[-1] game_database = fsgs.game_database(item["database"]) item["like_rating"], item["work_rating"] = game_database\ .get_ratings_for_game(item["uuid"]) item["personal_rating"], ignored = database.get_ratings_for_game( item["uuid"]) sort_key = (0, 1000000 - item["like_rating"], 1000000 - item["work_rating"], name) sortable_items.append( (sort_key, i, item)) # print(sortable_items) self.items = [x[2] for x in sorted(sortable_items)] self.update() # self.set_items(self.items) # self.set_item_count(len(self.items)) self.select_item(None, signal=False) select_index = None list_uuid = LauncherSettings.get("game_list_uuid") if list_uuid: list_variant_uuid = database.get_variant_for_list_and_game( list_uuid, game_uuid) print("game list", list_uuid, "override variant", list_variant_uuid) else: list_variant_uuid = None if list_variant_uuid: # override variant selection from list if possible for i, item in enumerate(self.items): print(item["uuid"], item["name"], list_variant_uuid) if item["uuid"] == list_variant_uuid: select_index = i print("override select index", select_index) break if select_index is None: # default index selection for i, item in enumerate(self.items): if item["personal_rating"] == 5: select_index = i break else: for i, item in enumerate(self.items): if item["have"] >= 3: select_index = i break else: for i, item in enumerate(self.items): if item["have"] >= 1: select_index = i break else: if len(self.items) > 0: select_index = 0 # self.clear() # for i, item in enumerate(self.items): # self.add_item(item["name"], icon=self.get_item_icon(i)) self.enable(len(self.items) > 0) if select_index is not None: print("selecting variant index", select_index) self.select_item(select_index) else: ConfigGroup.new_config()
def run(self): with Database.get_instance() as database: self._run(database)
def on_quit_signal(self): database = Database.get_instance() for key, value in self.cache.items(): database.set_last_game_variant(key, value) database.commit()
def update_list(self, game_uuid): print("VariantsBrowser.update_list, game_uuid=", game_uuid) database = Database.get_instance() items = database.find_game_variants_new(game_uuid, have=0) # items = database.search_configurations(self.search) # FIXME: Merge code with # FSGameSystemContext.py:get_ordered_game_variants sortable_items = [] for i, variant in enumerate(items): name = variant["name"] # assert "\n" not in name # only show variant name (without game name) # name = name.split("\n", 1)[-1] game_database = fsgs.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"]) 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)) # print(sortable_items) self.items = [x[2] for x in sorted(sortable_items)] self.update() # self.set_items(self.items) # self.set_item_count(len(self.items)) self.select_item(None, signal=False) select_index = None list_uuid = LauncherSettings.get("game_list_uuid") if list_uuid: list_variant_uuid = database.get_variant_for_list_and_game( list_uuid, game_uuid) print("game list", list_uuid, "override variant", list_variant_uuid) else: list_variant_uuid = None if list_variant_uuid: # override variant selection from list if possible for i, variant in enumerate(self.items): print(variant["uuid"], variant["name"], list_variant_uuid) if variant["uuid"] == list_variant_uuid: select_index = i print("override select index", select_index) break if select_index is None: # default index selection for i, variant in enumerate(self.items): if variant["personal_rating"] == 5: if variant["have"] >= 3: select_index = i break else: # FIXME: Add warning here that the favorite variant # could not be selected. pass else: for i, variant in enumerate(self.items): if variant["have"] >= 3: select_index = i break else: for i, variant in enumerate(self.items): if variant["have"] >= 1: select_index = i break else: if len(self.items) > 0: select_index = 0 # self.clear() # for i, variant in enumerate(self.items): # self.add_item(variant["name"], icon=self.get_item_icon(i)) self.enable(len(self.items) > 0) if select_index is not None: print("selecting variant index", select_index) self.select_item(select_index) else: ConfigGroup.new_config()
def save_config(): print("SaveButton.save_config") database = Database.get_instance() name = LauncherSettings.get("config_name").strip() if not name: print("no config_name") # FIXME: notify user return file_name = name + ".fs-uae" path = os.path.join( FSGSDirectories.get_configurations_dir(), file_name) with io.open(path, "w", encoding="UTF-8") as f: f.write("# FS-UAE configuration saved by FS-UAE Launcher\n") f.write("# Last saved: {0}\n".format( datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"))) f.write("\n[fs-uae]\n") keys = sorted(fsgs.config.values.keys()) for key in keys: value = LauncherConfig.get(key) if key.startswith("__"): continue if key in LauncherConfig.no_save_keys_set: continue # elif key == "joystick_port_2_mode" and value == "nothing": # continue # elif key == "joystick_port_3_mode" and value == "nothing": # continue if value == LauncherConfig.default_config.get(key, ""): continue if value: f.write("{0} = {1}\n".format(key, value)) # scanner = ConfigurationScanner() # search = ConfigurationScanner.create_configuration_search(name) # name = scanner.create_configuration_name(name) # print("adding", path) # # deleting the path from the database first in case it already exists # database.delete_configuration(path=path) # database.delete_file(path=path) # database.add_file(path=path) # database.add_configuration( # path=path, uuid="", name=name, scan=0, search=search) file_database = FileDatabase.get_instance() scanner = ConfigurationScanner() print("[save config] adding config", path) file_database.delete_file(path=path) with open(path, "rb") as f: sha1 = hashlib.sha1(f.read()).hexdigest() file_database.add_file(path=path, sha1=sha1) game_id = database.add_game( path=path, name=scanner.create_configuration_name(name)) database.update_game_search_terms( game_id, scanner.create_search_terms(name)) database.commit() file_database.commit() LauncherSettings.set("__config_refresh", str(time.time())) # Settings.set("config_changed", "0") LauncherConfig.set("__changed", "0")