def write_mame_xml(): if not system.path_exists(MAME_CACHE_DIR): system.create_folder(MAME_CACHE_DIR) if not system.path_exists(MAME_XML_PATH): logger.info("Getting full game list from MAME...") mame_inst = mame() mame_inst.write_xml_list()
def makeconfig(path, drives, commands): system.create_folder(os.path.dirname(path)) with open(path, 'w') as config_file: config_file.write('[autoexec]\n') for drive in drives: config_file.write("mount {} \"{}\"\n".format(drive, drives[drive])) for command in commands: config_file.write("{}\n".format(command))
def on_runner_installed(*args): mapping_path = system.create_folder("~/.reicast/mappings") mapping_source = os.path.join(settings.RUNNER_DIR, "reicast/mappings") for mapping_file in os.listdir(mapping_source): shutil.copy(os.path.join(mapping_source, mapping_file), mapping_path) system.create_folder("~/.reicast/data") NoticeDialog(_("You have to copy valid BIOS files to ~/.reicast/data before playing"))
def makeconfig(path, drives, commands): system.create_folder(os.path.dirname(path)) with open(path, "w") as config_file: config_file.write("[autoexec]\n") for drive in drives: config_file.write('mount {} "{}"\n'.format(drive, drives[drive])) for command in commands: config_file.write("{}\n".format(command))
def decompress_gog(file_path, destination_path): innoextract_path = get_innoextract_path() if not innoextract_path: raise OSError("innoextract is not found in the lutris runtime or on the system") system.create_folder(destination_path) # innoextract cannot do mkdir -p return_code = subprocess.call([innoextract_path, "-m", "-g", "-d", destination_path, "-e", file_path]) if return_code != 0: raise RuntimeError("innoextract failed to extract GOG setup file")
def on_runner_installed(*args): mapping_path = system.create_folder('~/.reicast/mappings') mapping_source = os.path.join(settings.RUNNER_DIR, 'reicast/mappings') for mapping_file in os.listdir(mapping_source): shutil.copy(os.path.join(mapping_source, mapping_file), mapping_path) system.create_folder('~/.reicast/data') NoticeDialog("You have to copy valid BIOS files to ~/.reicast/data " "before playing")
def write_mame_xml(): if not system.path_exists(MAME_CACHE_DIR): system.create_folder(MAME_CACHE_DIR) if not system.path_exists(MAME_XML_PATH): logger.info("Getting full game list from MAME...") mame_inst = mame() if not mame_inst.is_installed(): logger.info("MAME isn't installed, can't retrieve systems list.") return [] mame_inst.write_xml_list()
def write_mame_xml(force=False): if not system.path_exists(MAME_CACHE_DIR): system.create_folder(MAME_CACHE_DIR) if system.path_exists(MAME_XML_PATH, exclude_empty=True) and not force: return False logger.info("Writing full game list from MAME to %s", MAME_XML_PATH) mame_inst = mame() mame_inst.write_xml_list() if system.get_disk_size(MAME_XML_PATH) == 0: logger.warning("MAME did not write anything to %s", MAME_XML_PATH) return False return True
def on_runner_installed(*args): bios_path = system.create_folder('~/.pcsxr/bios') dlg = QuestionDialog({ 'question': ("Do you want to select a Playstation BIOS file?\n\n" "The BIOS is the core code running the machine.\n" "PCSX-Reloaded includes an emulated BIOS, but it is " "still incomplete. \n" "Using an original BIOS avoids some bugs and reduced " "compatibility \n" "with some games."), 'title': "Use BIOS file?", }) if dlg.result == dlg.YES: bios_dlg = FileDialog("Select a BIOS file") bios_src = bios_dlg.filename shutil.copy(bios_src, bios_path) # Save bios in config bios_path = os.path.join(bios_path, os.path.basename(bios_src)) config = LutrisConfig(runner_slug='pcsxr') config.raw_runner_config.update({'bios': bios_path}) config.save() if callback: callback()
def dosexec(config_file=None, executable=None, args=None, exit=True, working_dir=None): """Execute Dosbox with given config_file.""" if config_file: run_with = "config {}".format(config_file) if not working_dir: working_dir = os.path.dirname(config_file) elif executable: run_with = "executable {}".format(executable) if not working_dir: working_dir = os.path.dirname(executable) else: raise ValueError("Neither a config file or an executable were provided") logger.debug("Running dosbox with {}".format(run_with)) working_dir = system.create_folder(working_dir) dosbox_runner = dosbox() command = [dosbox_runner.get_executable()] if config_file: command += ['-conf', config_file] if executable: if not os.path.exists(executable): raise OSError("Can't find file {}".format(executable)) command += [executable] if args: command += args.split() if exit: command.append('-exit') system.execute(command, cwd=working_dir)
def dosexec(config_file=None, executable=None, args=None, close_on_exit=True, working_dir=None): """Execute Dosbox with given config_file.""" if config_file: run_with = "config {}".format(config_file) if not working_dir: working_dir = os.path.dirname(config_file) elif executable: run_with = "executable {}".format(executable) if not working_dir: working_dir = os.path.dirname(executable) else: raise ValueError( "Neither a config file or an executable were provided") logger.debug("Running dosbox with %s", run_with) working_dir = system.create_folder(working_dir) dosbox = import_runner("dosbox") dosbox_runner = dosbox() command = [dosbox_runner.get_executable()] if config_file: command += ["-conf", config_file] if executable: if not system.path_exists(executable): raise OSError("Can't find file {}".format(executable)) command += [executable] if args: command += args.split() if close_on_exit: command.append("-exit") system.execute(command, cwd=working_dir, env=runtime.get_env())
def init_dirs(): """Creates Lutris directories""" directories = [ settings.CONFIG_DIR, os.path.join(settings.CONFIG_DIR, "runners"), os.path.join(settings.CONFIG_DIR, "games"), settings.DATA_DIR, os.path.join(settings.DATA_DIR, "covers"), settings.ICON_PATH, os.path.join(settings.DATA_DIR, "banners"), os.path.join(settings.DATA_DIR, "coverart"), os.path.join(settings.DATA_DIR, "runners"), os.path.join(settings.DATA_DIR, "lib"), settings.RUNTIME_DIR, settings.CACHE_DIR, os.path.join(settings.CACHE_DIR, "installer"), os.path.join(settings.CACHE_DIR, "tmp"), ] for directory in directories: create_folder(directory)
def on_runner_installed(*args): config_path = system.create_folder('~/.vice') lib_dir = os.path.join(settings.RUNNER_DIR, 'vice/lib/vice') if not os.path.exists(lib_dir): lib_dir = os.path.join(settings.RUNNER_DIR, 'vice/lib64/vice') if not os.path.exists(lib_dir): logger.error('Missing lib folder in the Vice runner') else: system.merge_folders(lib_dir, config_path) if callback: callback()
def check_config(force_wipe=False): """Check if initial configuration is correct.""" directories = [ settings.CONFIG_DIR, join(settings.CONFIG_DIR, "runners"), join(settings.CONFIG_DIR, "games"), settings.DATA_DIR, join(settings.DATA_DIR, "covers"), settings.ICON_PATH, join(settings.DATA_DIR, "banners"), join(settings.DATA_DIR, "runners"), join(settings.DATA_DIR, "lib"), settings.RUNTIME_DIR, settings.CACHE_DIR, join(settings.CACHE_DIR, "installer"), join(settings.CACHE_DIR, "tmp") ] for directory in directories: create_folder(directory) if force_wipe: os.remove(settings.PGA_DB) pga.syncdb() pga.set_config_paths()
def check_config(): """Check if initial configuration is correct.""" directories = [ settings.CONFIG_DIR, join(settings.CONFIG_DIR, "runners"), join(settings.CONFIG_DIR, "games"), settings.DATA_DIR, join(settings.DATA_DIR, "covers"), settings.ICON_PATH, join(settings.DATA_DIR, "banners"), join(settings.DATA_DIR, "runners"), join(settings.DATA_DIR, "lib"), settings.RUNTIME_DIR, settings.CACHE_DIR, join(settings.CACHE_DIR, "installer"), join(settings.CACHE_DIR, "tmp"), ] for directory in directories: create_folder(directory) pga.syncdb()
def check_config(force_wipe=False): """Check if initial configuration is correct.""" directories = [settings.CONFIG_DIR, join(settings.CONFIG_DIR, "runners"), join(settings.CONFIG_DIR, "games"), settings.DATA_DIR, join(settings.DATA_DIR, "covers"), settings.ICON_PATH, join(settings.DATA_DIR, "banners"), join(settings.DATA_DIR, "runners"), join(settings.DATA_DIR, "lib"), settings.RUNTIME_DIR, settings.CACHE_DIR, join(settings.CACHE_DIR, "installer"), join(settings.CACHE_DIR, "tmp")] for directory in directories: create_folder(directory) if force_wipe: os.remove(settings.PGA_DB) pga.syncdb() pga.set_config_paths()
def on_runner_installed(*args): config_path = system.create_folder("~/.atari800") bios_archive = os.path.join(config_path, "atari800-bioses.zip") dlg = DownloadDialog(self.bios_url, bios_archive) dlg.run() if not system.path_exists(bios_archive): ErrorDialog("Could not download Atari800 BIOS archive") return extract.extract_archive(bios_archive, config_path) os.remove(bios_archive) config = LutrisConfig(runner_slug="atari800") config.raw_runner_config.update({"bios_path": config_path}) config.save() if callback: callback()
def on_runner_installed(*args): # pylint: disable=unused-argument config_path = system.create_folder("~/.atari800") bios_archive = os.path.join(config_path, "atari800-bioses.zip") dlg = DownloadDialog(self.bios_url, bios_archive) dlg.run() if not system.path_exists(bios_archive): ErrorDialog(_("Could not download Atari 800 BIOS archive")) return extract.extract_archive(bios_archive, config_path) os.remove(bios_archive) config = LutrisConfig(runner_slug="atari800") config.raw_runner_config.update({"bios_path": config_path}) config.save() if callback: callback()
def on_runner_installed(*args): config_path = system.create_folder("~/.atari800") bios_archive = os.path.join(config_path, 'atari800-bioses.zip') dlg = DownloadDialog(self.bios_url, bios_archive) dlg.run() if not system.path_exists(bios_archive): ErrorDialog("Could not download Atari800 BIOS archive") return extract.extract_archive(bios_archive, config_path) os.remove(bios_archive) config = LutrisConfig(runner_slug='atari800') config.raw_runner_config.update({'bios_path': config_path}) config.save() if callback: callback()
def on_runner_installed(*args): bios_path = system.create_folder('~/.hatari/bios') dlg = QuestionDialog({ 'question': "Do you want to select an Atari ST BIOS file?", 'title': "Use BIOS file?", }) if dlg.result == dlg.YES: bios_dlg = FileDialog("Select a BIOS file") bios_filename = bios_dlg.filename if not bios_filename: return shutil.copy(bios_filename, bios_path) bios_path = os.path.join(bios_path, os.path.basename(bios_filename)) config = LutrisConfig(runner_slug='hatari') config.raw_runner_config.update({'bios_file': bios_path}) config.save() if callback: callback()
def prelaunch(self): if not self.game_config.get("main_file") and self.is_installed(): return True if os.path.exists(os.path.join(settings.RUNNER_DIR, "pico8/cartridges", "tmp.p8.png")): os.remove(os.path.join(settings.RUNNER_DIR, "pico8/cartridges", "tmp.p8.png")) # Don't download cartridge if using web backend and cart is url if self.is_native or not self.game_config.get("main_file").startswith("http"): if not os.path.exists(self.game_config.get("main_file")) and ( self.game_config.get("main_file").isdigit() or self.game_config.get("main_file").startswith("http") ): if not self.game_config.get("main_file").startswith("http"): pid = int(self.game_config.get("main_file")) num = math.floor(pid / 10000) downloadUrl = ("https://www.lexaloffle.com/bbs/cposts/" + str(num) + "/" + str(pid) + ".p8.png") else: downloadUrl = self.game_config.get("main_file") cartPath = self.cart_path system.create_folder(os.path.dirname(cartPath)) downloadCompleted = False def on_downloaded_cart(): nonlocal downloadCompleted # If we are offline we don't want an empty file to overwrite the cartridge if dl.downloaded_size: shutil.move(cartPath + ".download", cartPath) else: os.remove(cartPath + ".download") downloadCompleted = True dl = Downloader( downloadUrl, cartPath + ".download", True, callback=on_downloaded_cart, ) dl.start() # Wait for download to complete or continue if it exists (to work in offline mode) while not os.path.exists(cartPath): if downloadCompleted or dl.state == Downloader.ERROR: logger.error("Could not download cartridge from %s", downloadUrl) return False sleep(0.1) # Download js engine if not self.is_native and not os.path.exists(self.runner_config.get("engine")): enginePath = os.path.join( settings.RUNNER_DIR, "pico8/web/engines", self.runner_config.get("engine") + ".js", ) if not os.path.exists(enginePath): downloadUrl = ("https://www.lexaloffle.com/bbs/" + self.runner_config.get("engine") + ".js") system.create_folder(os.path.dirname(enginePath)) downloadCompleted = False def on_downloaded_engine(): nonlocal downloadCompleted downloadCompleted = True dl = Downloader(downloadUrl, enginePath, True, callback=on_downloaded_engine) dl.start() dl.thread.join() # Doesn't actually wait until finished # Waits for download to complete while not os.path.exists(enginePath): if downloadCompleted or dl.state == Downloader.ERROR: logger.error("Could not download engine from %s", downloadUrl) return False sleep(0.1) return True
def prelaunch(self): if os.path.exists( os.path.join(settings.RUNNER_DIR, "pico8/cartridges", "tmp.p8.png") ): os.remove( os.path.join(settings.RUNNER_DIR, "pico8/cartridges", "tmp.p8.png") ) # Don't download cartridge if using web backend and cart is url if self.is_native or not self.game_config.get("main_file").startswith("http"): if not os.path.exists(self.game_config.get("main_file")) and ( self.game_config.get("main_file").isdigit() or self.game_config.get("main_file").startswith("http") ): if not self.game_config.get("main_file").startswith("http"): pid = int(self.game_config.get("main_file")) num = math.floor(pid / 10000) downloadUrl = ( "https://www.lexaloffle.com/bbs/cposts/" + str(num) + "/" + str(pid) + ".p8.png" ) else: downloadUrl = self.game_config.get("main_file") cartPath = self.cart_path system.create_folder(os.path.dirname(cartPath)) downloadCompleted = False def on_downloaded_cart(): nonlocal downloadCompleted # If we are offline we don't want an empty file to overwrite the cartridge if dl.downloaded_size: shutil.move(cartPath + ".download", cartPath) else: os.remove(cartPath + ".download") downloadCompleted = True dl = downloader.Downloader( downloadUrl, cartPath + ".download", True, callback=on_downloaded_cart, ) dl.start() # Wait for download to complete or continue if it exists (to work in offline mode) while not os.path.exists(cartPath): if downloadCompleted or dl.state == downloader.Downloader.ERROR: logger.error("Could not download cartridge from " + downloadUrl) return False sleep(0.1) # Download js engine if not self.is_native and not os.path.exists(self.runner_config.get("engine")): enginePath = os.path.join( settings.RUNNER_DIR, "pico8/web/engines", self.runner_config.get("engine") + ".js", ) if not os.path.exists(enginePath): downloadUrl = ( "https://www.lexaloffle.com/bbs/" + self.runner_config.get("engine") + ".js" ) system.create_folder(os.path.dirname(enginePath)) downloadCompleted = False def on_downloaded_engine(): nonlocal downloadCompleted downloadCompleted = True dl = downloader.Downloader( downloadUrl, enginePath, True, callback=on_downloaded_engine ) dl.start() dl.thread.join() # Doesn't actually wait until finished # Waits for download to complete while not os.path.exists(enginePath): if downloadCompleted or dl.state == downloader.Downloader.ERROR: logger.error("Could not download engine from " + downloadUrl) return False sleep(0.1) return True