def get_cover_path(self): sha1 = LauncherConfig.get("front_sha1") if sha1: return "sha1:" + sha1 path = self.get_override_path("cover_image") if path and os.path.exists(path): return path if self.uuid: paths = FSGSDirectories.get_images_dirs() for dir_ in paths: p = os.path.join( dir_, self.platform, "Images", self.uuid[:2], self.uuid, "front.png", ) if os.path.exists(p): return p p = os.path.join( dir_, self.platform, "Thumbnails", self.uuid[:2], self.uuid, "front.png", ) if os.path.exists(p): return p letter = self.get_letter(self.name) if not letter: return None name = self.name override_dir = LauncherConfig.get("covers_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_covers_dirs() for dir_ in paths: path = os.path.join(dir_, letter, name + ".jpg") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, name + ".jpg") if os.path.exists(path): return path path = os.path.join(dir_, name + ".png") if os.path.exists(path): return path return None
def convert_uri(cls, uri, prefer_path=False): if uri.startswith("sha1://"): return cls.open_sha1_uri(uri) elif uri.startswith("db://"): # old name for sha1:// return cls.open_sha1_uri(uri) elif is_http_url(uri): return cls.open_url(uri) elif uri.startswith("locker://"): return open_locker_uri(uri) else: if uri.startswith("$"): uri = Paths.expand_path(uri) if prefer_path and os.path.exists(uri): # return helper object so isinstance does not match with str return File(uri) return Archive(uri).open(uri)
def expand_default_path(self, src, default_dir): if "://" in src: return src, None src = Paths.expand_path(src, default_dir) archive = Archive(src) # if not archive.exists(src): # dirs = [default_dir] # for dir in dirs: # path = os.path.join(dir, src) # print("checking", repr(path)) # archive = Archive(path) # if archive.exists(path): # #if os.path.exists(path): # src = path # break # else: # raise Exception("Cannot find path for " + repr(src)) return src, archive
def prepare_hard_drives(self): print("LaunchHandler.prepare_hard_drives") current_task.set_progress(gettext("Preparing hard drives...")) # self.on_progress(gettext("Preparing hard drives...")) for i in range(0, 10): key = "hard_drive_{0}".format(i) src = self.config.get(key, "") dummy, ext = os.path.splitext(src) ext = ext.lower() if is_http_url(src): name = src.rsplit("/", 1)[-1] name = urllib.parse.unquote(name) self.on_progress(gettext("Downloading {0}...".format(name))) dest = os.path.join(self.temp_dir, name) Downloader.install_file_from_url(src, dest) src = dest elif src.startswith("hd://game/"): self.unpack_game_hard_drive(i, src) self.disable_save_states() return elif src.startswith("hd://template/workbench/"): self.prepare_workbench_hard_drive(i, src) self.disable_save_states() return elif src.startswith("hd://template/empty/"): self.prepare_empty_hard_drive(i, src) self.disable_save_states() return if ext in Archive.extensions: print("zipped hard drive", src) self.unpack_hard_drive(i, src) self.disable_save_states() elif src.endswith("HardDrive"): print("XML-described hard drive", src) self.unpack_hard_drive(i, src) self.disable_save_states() else: src = Paths.expand_path(src) self.config[key] = src
def convert_uri(self, uri, prefer_path=False): if uri.startswith("sha1://"): return self.open_sha1_uri(uri) elif uri.startswith("db://"): # old name for sha1:// return self.open_sha1_uri(uri) elif is_http_url(uri): return self.open_url(uri) elif uri.startswith("locker://"): return open_locker_uri( uri, opener_cache_dict=self.opener_cache_dict ) else: if uri.startswith("$"): uri = Paths.expand_path(uri) if prefer_path and os.path.exists(uri): # return helper object so isinstance does not match with str return File(uri) return Archive(uri).open(uri)
def get_cover_path(self): sha1 = LauncherConfig.get("front_sha1") if sha1: return "sha1:" + sha1 path = self.get_override_path("cover_image") if path and os.path.exists(path): return path if self.uuid: paths = FSGSDirectories.get_images_dirs() for dir_ in paths: p = os.path.join(dir_, self.platform, "Images", self.uuid[:2], self.uuid, "front.png") if os.path.exists(p): return p p = os.path.join(dir_, self.platform, "Thumbnails", self.uuid[:2], self.uuid, "front.png") if os.path.exists(p): return p letter = self.get_letter(self.name) if not letter: return None name = self.name override_dir = LauncherConfig.get("covers_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_covers_dirs() for dir_ in paths: path = os.path.join(dir_, letter, name + ".jpg") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, name + ".jpg") if os.path.exists(path): return path path = os.path.join(dir_, name + ".png") if os.path.exists(path): return path return None
def fix_file_checksum(sha1_key, key, base_dir, is_rom=False): path = config.get(key, "") # hack to synchronize URLs # print(repr(path)) if path.startswith("http://") or path.startswith("https://"): sha1 = path config[sha1_key] = sha1 return path = Paths.expand_path(path) sha1 = config.get(sha1_key, "") if not path: return if sha1: # assuming sha1 is correct return if not os.path.exists(path): print(repr(path), "does not exist") path = os.path.join(base_dir, path) if not os.path.exists(path): print(repr(path), "does not exist") return if os.path.isdir(path): # could set a fake checksum here or something, to indicate # that it isn't supposed to be set.. return print("checksumming", repr(path)) size = os.path.getsize(path) if size > 64 * 1024 * 1024: # not checksumming large files right now print("not checksumming large file") return if is_rom: sha1 = checksum_tool.checksum_rom(path) else: sha1 = checksum_tool.checksum(path) config[sha1_key] = sha1
def prepare_roms(self): print("LaunchHandler.prepare_roms") current_task.set_progress(gettext("Preparing kickstart ROMs...")) amiga_model = self.config.get("amiga_model", "A500") model_config = Amiga.get_model_config(amiga_model) roms = [("kickstart_file", model_config["kickstarts"])] if self.config["kickstart_ext_file"] or model_config["ext_roms"]: # not all Amigas have extended ROMs roms.append(("kickstart_ext_file", model_config["ext_roms"])) if amiga_model.lower() == "cd32/fmv": roms.append(("fvm_rom", [CD32_FMV_ROM])) if self.config["graphics_card"].lower().startswith("picasso-iv"): roms.append(("graphics_card_rom", [PICASSO_IV_74_ROM])) if self.config["accelerator"].lower() == "cyberstorm-ppc": roms.append(("accelerator_rom", ["cyberstormppc.rom"])) if self.config["freezer_cartridge"] == "action-replay-2": # Ideally, we would want to recognize ROMs based on zeroing the # first four bytes, but right now we simply recognize a common # additional version. freezer_cartridge_rom isn't a real option, # we just want to copy the rom file and let FS-UAE find it roms.append(("[freezer_cartridge]", [ACTION_REPLAY_MK_II_2_14_ROM.sha1, ACTION_REPLAY_MK_II_2_14_MOD_ROM.sha1])) elif self.config["freezer_cartridge"] == "action-replay-3": roms.append(("[freezer_cartridge]", [ACTION_REPLAY_MK_III_3_17_ROM.sha1, ACTION_REPLAY_MK_III_3_17_MOD_ROM.sha1])) for config_key, default_roms in roms: print("ROM:", config_key, default_roms) src = self.config[config_key] if not src: for sha1 in default_roms: if is_sha1(sha1): rom_src = self.fsgs.file.find_by_sha1(sha1) if rom_src: src = rom_src break else: # roms_dir = FSGSDirectories.get_kickstarts_dir() # src = os.path.join(roms_dir, sha1) # if os.path.exists(src): # break # loop up file in roms dir instead src = sha1 elif src == "internal": continue elif src: src = Paths.expand_path(src) if not src: raise TaskFailure( gettext("Did not find required Kickstart or " "ROM for {}. Wanted one of these files: {}".format( config_key, repr(default_roms)))) use_temp_kickstarts_dir = False dest = os.path.join(self.temp_dir, os.path.basename(src)) archive = Archive(src) stream = None if not archive.exists(src): dirs = [self.fsgs.amiga.get_kickstarts_dir()] for dir in dirs: path = os.path.join(dir, src) print("checking", repr(path)) archive = Archive(path) if archive.exists(path): src = path break else: try: stream = self.fsgs.file.open(src) if stream is None: raise FileNotFoundError(src) except FileNotFoundError: raise TaskFailure(gettext( "Cannot find required ROM " "file: {name}".format(name=repr(src)))) with open(dest, "wb") as f: if stream: f.write(stream.read()) else: ROMManager.decrypt_archive_rom(archive, src, file=f) if use_temp_kickstarts_dir: self.config[config_key] = os.path.basename(src) else: self.config[config_key] = dest if use_temp_kickstarts_dir: self.config["kickstarts_dir"] = self.temp_dir
def get_screenshot_path(self, number): if number == 0: sha1 = LauncherConfig.get("title_sha1") else: sha1 = LauncherConfig.get("screen{0}_sha1".format(number)) if sha1: return "sha1:" + sha1 if number == 0: path = self.get_override_path("title_image") else: path = self.get_override_path("screen{0}_image".format(number)) if path and os.path.exists(path): return path if self.uuid: if number == 0: name = "title.png" else: name = "screen{0}.png".format(number) paths = FSGSDirectories.get_images_dirs() for dir_ in paths: p = os.path.join(dir_, self.platform, "Images", self.uuid[:2], self.uuid, name) if os.path.exists(p): return p p = os.path.join(dir_, self.platform, "Thumbnails", self.uuid[:2], self.uuid, name) if os.path.exists(p): return p letter = self.get_letter(self.name) if not letter: return None name = self.name if number == 0: override_dir = LauncherConfig.get("titles_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_titles_dirs() else: override_dir = LauncherConfig.get("screenshots_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_screenshots_dirs() if number >= 2: name = "{0}_{1}".format(name, number) for dir_ in paths: path = os.path.join(dir_, letter, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".gif") if os.path.exists(path): return path path = os.path.join(dir_, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".gif") if os.path.exists(path): return path return None
def get_override_path(name): path = LauncherConfig.get(name) if not path: return "" path = Paths.expand_path(path) return path
def expand_default_path(src, default_dir): if "://" in src: return src, None src = Paths.expand_path(src, default_dir) archive = Archive(src) return src, archive
def prepare_roms(self): print("LaunchHandler.prepare_roms") current_task.set_progress(gettext("Preparing kickstart ROMs...")) amiga_model = self.config.get("amiga_model", "A500") model_config = Amiga.get_model_config(amiga_model) roms = [("kickstart_file", model_config["kickstarts"])] if self.config["kickstart_ext_file"] or model_config["ext_roms"]: # not all Amigas have extended ROMs roms.append(("kickstart_ext_file", model_config["ext_roms"])) if amiga_model.lower() == "cd32/fmv": roms.append(("fvm_rom", [CD32_FMV_ROM])) if self.config["graphics_card"].lower().startswith("picasso-iv"): roms.append(("graphics_card_rom", [PICASSO_IV_74_ROM])) if self.config["accelerator"].lower() == "cyberstorm-ppc": roms.append(("accelerator_rom", ["cyberstormppc.rom"])) if self.config["freezer_cartridge"] == "action-replay-2": # Ideally, we would want to recognize ROMs based on zeroing the # first four bytes, but right now we simply recognize a common # additional version. freezer_cartridge_rom isn't a real option, # we just want to copy the rom file and let FS-UAE find it roms.append( ( "[freezer_cartridge]", [ ACTION_REPLAY_MK_II_2_14_ROM.sha1, ACTION_REPLAY_MK_II_2_14_MOD_ROM.sha1, ], ) ) elif self.config["freezer_cartridge"] == "action-replay-3": roms.append( ( "[freezer_cartridge]", [ ACTION_REPLAY_MK_III_3_17_ROM.sha1, ACTION_REPLAY_MK_III_3_17_MOD_ROM.sha1, ], ) ) use_temp_kickstarts_dir = False for config_key, default_roms in roms: print("[ROM]", config_key, default_roms) src = self.config[config_key] print("[ROM]", src) if not src: for sha1 in default_roms: print("[ROM] Trying", sha1) if is_sha1(sha1): rom_src = self.fsgs.file.find_by_sha1(sha1) if rom_src: src = rom_src print("[ROM] Found", rom_src) break else: # roms_dir = FSGSDirectories.get_kickstarts_dir() # src = os.path.join(roms_dir, sha1) # if os.path.exists(src): # break # loop up file in roms dir instead src = sha1 elif src == "internal": continue elif src: src = Paths.expand_path(src) if not src: raise TaskFailure( gettext( "Did not find required Kickstart or " "ROM for {}. Wanted one of these files: {}".format( config_key, repr(default_roms) ) ) ) dest = os.path.join(self.temp_dir, os.path.basename(src)) def lookup_rom_from_src(src): parts = src.split(":", 1) if len(parts) == 2 and len(parts[0]) > 1: # src has a scheme (not a Windows drive letter). Assume # we can find this file. return src archive = Archive(src) if archive.exists(src): return src dirs = [self.fsgs.amiga.get_kickstarts_dir()] for dir_ in dirs: path = os.path.join(dir_, src) print("[ROM] Checking", repr(path)) archive = Archive(path) if archive.exists(path): return path return None org_src = src src = lookup_rom_from_src(src) if not src and org_src == "cyberstormppc.rom": src = lookup_rom_from_src( "ralphschmidt-cyberstorm-ppc-4471.rom" ) if not src: for ( dir_ ) in FSGSDirectories.get_amiga_forever_directories(): path = os.path.join( dir_, "Shared", "rom", "ralphschmidt-cyberstorm-ppc-4471.rom", ) if os.path.exists(path): src = path print("[ROM] Found", path) break else: print("[ROM] Trying", path) stream = None # FIXME: prepare_roms should be rewritten, it's kind of crap. # Rom patching and decryption should be handled differently. Should # use file database filters, and decryption via rom.key should only # be supported when using uncompressed files directly on disk. if not src or not os.path.exists(src): try: stream = self.fsgs.file.open(src) if stream is None: raise FileNotFoundError(src) except FileNotFoundError: raise TaskFailure( gettext( "Cannot find required ROM " "file: {name}".format(name=repr(org_src)) ) ) with open(dest, "wb") as f: if stream: print("[ROM] From stream => {}".format(dest)) rom = {} rom["data"] = stream.read() rom["sha1"] = hashlib.sha1(rom["data"]).hexdigest() ROMManager.patch_rom(rom) f.write(rom["data"]) else: archive = Archive(src) ROMManager.decrypt_archive_rom(archive, src, file=f) if use_temp_kickstarts_dir: self.config[config_key] = os.path.basename(src) else: self.config[config_key] = dest if use_temp_kickstarts_dir: self.config["kickstarts_dir"] = self.temp_dir
def get_screenshot_path(self, number): if number == 0: sha1 = LauncherConfig.get("title_sha1") else: sha1 = LauncherConfig.get("screen{0}_sha1".format(number)) if sha1: return "sha1:" + sha1 if number == 0: path = self.get_override_path("title_image") else: path = self.get_override_path("screen{0}_image".format(number)) if path and os.path.exists(path): return path if self.uuid: if number == 0: name = "title.png" else: name = "screen{0}.png".format(number) paths = FSGSDirectories.get_images_dirs() for dir_ in paths: p = os.path.join( dir_, self.platform, "Images", self.uuid[:2], self.uuid, name, ) if os.path.exists(p): return p p = os.path.join( dir_, self.platform, "Thumbnails", self.uuid[:2], self.uuid, name, ) if os.path.exists(p): return p letter = self.get_letter(self.name) if not letter: return None name = self.name if number == 0: override_dir = LauncherConfig.get("titles_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_titles_dirs() else: override_dir = LauncherConfig.get("screenshots_dir") if override_dir: paths = [Paths.expand_path(override_dir)] else: paths = FSGSDirectories.get_screenshots_dirs() if number >= 2: name = "{0}_{1}".format(name, number) for dir_ in paths: path = os.path.join(dir_, letter, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".gif") if os.path.exists(path): return path path = os.path.join(dir_, name + ".png") if os.path.exists(path): return path path = os.path.join(dir_, letter, name + ".gif") if os.path.exists(path): return path return None