def custom_database_names(): custom_dir = os.path.join(FSGSDirectories.databases_dir(), "Custom") custom_databases = [] if os.path.exists(custom_dir): for item in os.listdir(custom_dir): if item.endswith(".sqlite"): custom_databases.append("Custom/" + item[:-7]) custom_dir = os.path.join(FSGSDirectories.databases_dir(), "User") custom_databases = [] if os.path.exists(custom_dir): for item in os.listdir(custom_dir): if item.endswith(".sqlite"): custom_databases.append("User/" + item[:-7]) return custom_databases
def write_retroarch_config(self, f): """ joypad_autoconfig_dir = "~/.config/retroarch/autoconfig" """ f.write('screenshot_directory = "{}"\n'.format( FSGSDirectories.screenshots_output_dir())) f.write('system_directory = "{}"\n'.format(self.system_dir.path)) # noinspection SpellCheckingInspection f.write('savefile_directory = "{}"\n'.format( self.save_handler.emulator_save_dir())) f.write('savestate_directory = "{}"\n'.format( self.save_handler.emulator_state_dir())) assets_dir = "" f.write('assets_directory = "{}"\n'.format(assets_dir)) # FIXME: Maybe enable autosave to save .srm while running the emulator # and not only on shutdown? # f.write("autosave_interval = 60\n") f.write("pause_nonactive = false\n") f.write("video_font_enable = false\n") f.write("rgui_show_start_screen = false\n") f.write("all_users_control_menu = true\n") f.write("video_gpu_screenshot = false\n")
def default_openretro_server_from_file(): server = None p = os.path.join(FSGSDirectories.get_data_dir(), "Settings", "database-server") if os.path.exists(p): with open(p, "r", encoding="UTF-8") as f: server = f.read().strip() return server
def uuid_save_dir_path(self): saves_dir = FSGSDirectories.saves_dir() # FIXME: Correct? variant_uuid = self.get("variant_uuid").upper() if variant_uuid: save_dir = os.path.join(saves_dir, variant_uuid[:1], variant_uuid[:2], variant_uuid) return save_dir return None
def insert_floppy(self, drive, path, sha1=None): if sha1 is None: sha1 = ChecksumTool().checksum(path) default_dir = FSGSDirectories.get_floppies_dir() path = Paths.contract_path(path, default_dir) self.set_config([ ("floppy_drive_{0}".format(drive), path), ("x_floppy_drive_{0}_sha1".format(drive), sha1), ])
def insert_cd(self, drive, path, sha1=None): if sha1 is None: sha1 = "" print("FIXME: not calculating CD checksum just yet") default_dir = FSGSDirectories.get_cdroms_dir() path = Paths.contract_path(path, default_dir) self.set_config([ ("cdrom_drive_{0}".format(drive), path), ("x_cdrom_drive_{0}_sha1".format(drive), sha1), ])
def get_settings_path(self): settings_ini = os.path.join(FSGSDirectories.get_data_dir(), "Settings.ini") if not os.path.exists(settings_ini): migrate_list = [ os.path.join(FSGSDirectories.get_data_dir(), "FS-UAE Launcher.ini") ] portable_ini = os.path.join(FSGSDirectories.get_base_dir(), "Portable.ini") # move the highest-priority settings file if present for migrate in migrate_list: if os.path.exists(migrate): shutil.move(migrate, settings_ini) break # remove all old settings files for migrate in migrate_list: if os.path.exists(migrate): os.remove(migrate) return settings_ini
def load_plugins(cls): if cls._plugins_loaded: return cls._plugins_loaded = True plugins_dir = FSGSDirectories.get_plugins_dir() if plugins_dir: dont_write_bytecode = sys.dont_write_bytecode try: cls._load_plugins(plugins_dir) finally: sys.dont_write_bytecode = dont_write_bytecode
def multi_select(cls, parent=None, *, config): default_dir = FSGSDirectories.get_cdroms_dir() dialog = LauncherFilePicker( parent, gettext("Select multiple CD-ROMs"), "cd", multiple=True ) if not dialog.show_modal(): return paths = dialog.get_paths() paths.sort() # checksum_tool = ChecksumTool(parent) for i, path in enumerate(paths): # sha1 = checksum_tool.checksum(path) sha1 = "" print("FIXME: not calculating CD checksum just yet") path = Paths.contract_path(path, default_dir) if i < 1: config.set_multiple( [ ("cdrom_drive_{0}".format(i), path), ("x_cdrom_drive_{0}_sha1".format(i), sha1), ] ) config.set_multiple( [ ("cdrom_image_{0}".format(i), path), ("x_cdrom_image_{0}_sha1".format(i), sha1), ] ) # blank the rest of the drives for i in range(len(paths), 1): config.set_multiple( [ ("cdrom_drive_{0}".format(i), ""), ("x_cdrom_drive_{0}_sha1".format(i), ""), ] ) # Config.set("x_cdrom_drive_{0}_sha1".format(i), "") # Config.set("x_cdrom_drive_{0}_name".format(i), "") # blank the rest of the image list for i in range(len(paths), Amiga.MAX_CDROM_IMAGES): config.set_multiple( [ ("cdrom_image_{0}".format(i), ""), ("x_cdrom_image_{0}_sha1".format(i), ""), ] )
def configure_gus(self, f): f.write("\n[gus]\n") if self.options[Option.DOSBOX_GUS_GUS].lower() == "true": f.write("gus=true\n") f.write("ultradir=U:\\ULTRASND\n") ultrasnd_drive = os.path.join(self.drives_dir.path, "U") source_dir = os.path.join(FSGSDirectories.get_data_dir(), "ULTRASND") dest_dir = os.path.join(ultrasnd_drive, "ULTRASND") if os.path.exists(source_dir): shutil.copytree(source_dir, dest_dir) else: # FIXME: ADD ULTRASND WARNING pass
def insert_multiple_floppies(self, insert_paths): paths = [] for path in insert_paths: embedded_files = [] if path.endswith(".zip"): archive = Archive(path) files = archive.list_files() for file in files: name, ext = os.path.splitext(file) # FIXME: get list of floppy extensions from a central # place if ext in [".adf", ".ipf"]: embedded_files.append(file) if len(embedded_files) > 0: embedded_files.sort() print("found embedded floppy images:") print(embedded_files) for file in embedded_files: paths.append(file) else: paths.append(path) default_dir = FSGSDirectories.get_floppies_dir() checksum_tool = ChecksumTool() for i, path in enumerate(paths): sha1 = checksum_tool.checksum(path) path = Paths.contract_path(path, default_dir) if i < 4: self.set_config([ ("floppy_drive_{0}".format(i), path), ("x_floppy_drive_{0}_sha1".format(i), sha1), ]) self.set_config([ ("floppy_image_{0}".format(i), path), ("x_floppy_image_{0}_sha1".format(i), sha1), ]) # blank the rest of the drives for i in range(len(paths), 4): self.set_config([ ("floppy_drive_{0}".format(i), ""), ("x_floppy_drive_{0}_sha1".format(i), ""), ]) # blank the rest of the image list for i in range(len(paths), 20): self.set_config([ ("floppy_image_{0}".format(i), ""), ("x_floppy_image_{0}_sha1".format(i), ""), ])
def browse(self, dir_mode): default_dir = FSGSDirectories.get_hard_drives_dir() dialog = LauncherFilePicker( self.get_window(), gettext("Choose Hard Drive"), "hd", get_config(self).get(self.config_key), dir_mode=dir_mode, ) if not dialog.show_modal(): dialog.destroy() return path = dialog.get_path() dialog.destroy() checksum_tool = ChecksumTool(self.get_window()) sha1 = "" if dir_mode: print("not calculating HD checksums for directories") else: size = os.path.getsize(path) if size < 64 * 1024 * 1024: sha1 = checksum_tool.checksum(path) else: print("not calculating HD checksums HD files > 64MB") full_path = path # FIXME: use contract function dir_path, file = os.path.split(path) self.text_field.set_text(file) if os.path.normcase(os.path.normpath(dir_path)) == os.path.normcase( os.path.normpath(default_dir)): path = file self.text_field.set_text(path) values = [(self.config_key, path), (self.config_key_sha1, sha1)] if self.index == 0: # whdload_args = "" # dummy, ext = os.path.splitext(path) # if not dir_mode and ext.lower() in Archive.extensions: # try: # whdload_args = self.calculate_whdload_args(full_path) # except Exception: # traceback.print_exc() # values.append(("x_whdload_args", whdload_args)) values.extend( whdload.generate_config_for_archive( full_path, model_config=False).items()) get_config(self).set_multiple(values)
def get_search_path(cls): paths = FSGSDirectories.get_default_search_path() search_path = LauncherSettings.get("search_path") for p in search_path.split(";"): p = p.strip() if not p: continue elif p[0] == "-": p = p[1:] if p in paths: paths.remove(p) else: if p not in paths: paths.append(p) # The Configurations dir is always scanned on startup (whenever # modification time has changed). If we don't include it here too # always, the result will be that the configs sometimes appear (on # startup) and disappear (on scan). if not FSGSDirectories.get_configurations_dir() in paths: paths.append(FSGSDirectories.get_configurations_dir()) # Likewise, we force the Kickstarts directory to always be scanned. if not FSGSDirectories.get_kickstarts_dir() in paths: paths.append(FSGSDirectories.get_kickstarts_dir()) return paths
def on_remove_button(self): path = self.list_view.get_item(self.list_view.index()) search_path = LauncherSettings.get("search_path") search_path = [x.strip() for x in search_path.split(";") if x.strip()] for i in range(len(search_path)): if search_path[i].startswith("-"): if path == search_path[i][1:]: # Already removed. break else: if search_path[i] == path: search_path.remove(search_path[i]) break default_paths = FSGSDirectories.get_default_search_path() if path in default_paths: search_path.append("-" + path) LauncherSettings.set("search_path", ";".join(search_path))
def kickstart_startup_scan(cls): if cls._kickstart_scanned: return cls._kickstart_scanned = True print("kickstart_startup_scan") kickstarts_dir = FSGSDirectories.get_kickstarts_dir() if LauncherSettings.get("kickstarts_dir_mtime" ) == cls.get_dir_mtime_str(kickstarts_dir): print("... mtime not changed") else: file_database = FileDatabase.get_instance() print("... database.find_local_roms") local_roms = file_database.find_local_roms() print("... walk kickstarts_dir") for dir_path, dir_names, file_names in os.walk(kickstarts_dir): for file_name in file_names: if not file_name.lower().endswith( ".rom") and not file_name.lower().endswith(".bin"): continue path = Paths.join(dir_path, file_name) if path in local_roms: local_roms[path] = None # already exists in database continue print("[startup] adding kickstart", path) ROMManager.add_rom_to_database(path, file_database) print(local_roms) for path, file_id in local_roms.items(): if file_id is not None: print("[startup] removing kickstart", path) file_database.delete_file(id=file_id) print("... commit") file_database.commit() LauncherSettings.set("kickstarts_dir_mtime", cls.get_dir_mtime_str(kickstarts_dir)) amiga = Amiga.get_model_config("A500") for sha1 in amiga["kickstarts"]: if fsgs.file.find_by_sha1(sha1=sha1): break else: file_database = FileDatabase.get_instance() cls.amiga_forever_kickstart_scan() file_database.commit()
def on_add_button(self): search_path = LauncherSettings.get("search_path") search_path = [x.strip() for x in search_path.split(";") if x.strip()] path = fsui.pick_directory(parent=self.get_window()) if path: for i in range(len(search_path)): if search_path[i].startswith("-"): if path == search_path[i][1:]: search_path.remove(search_path[i]) break else: if search_path[i] == path: # Already added. break else: default_paths = FSGSDirectories.get_default_search_path() if path not in default_paths: search_path.append(path) LauncherSettings.set("search_path", ";".join(search_path))