def _filter_sets_by_crcs(self, source_set): """ "_filter_sets_by_crcs" is a method that will build a dictionary of ROMs with unique crcs Args: source_set, type list, the source list of directories Returns: filtered list of dictionaries of ROM names with CRC and source file name Raises: None """ crc_names = [] index_id = 0 for source_group in source_set: if os.path.isdir(source_group): rom_names = os.listdir(source_group) num_of_roms = len(rom_names) msg = "Found {} files in {}".format(num_of_roms, source_group) logger.info(msg) for rom_file in rom_names: source_file = os.path.join(source_group, rom_file) if os.path.isfile(source_file): c = Compressor(src_file=source_file) try: rom_crc_list = c.get_crc() except: msg = "Error with file: {}".format(rom_file) logger.debug(msg) for rom_name in rom_crc_list: rom_name["name"] = source_file crc_names.append(rom_name) else: msg = "{} not a valid directory".format(source_group) logger.debug(msg) msg = "Found {} ROMs in the folders".format(len(crc_names)) logger.info(msg) # Filter out duplicate CRCs crcs_all = [] final_crcs = [] for i in range(len(crc_names)): crc = crc_names[i]['crc'] if crc not in crcs_all: crcs_all.append(crc) final_crcs.append(crc_names[i]) return final_crcs
def _build_theme(self): msg = "Building Main Menu Theme for {}".format(self.system) logger.info(msg) main_bg = os.path.join("assets", "background.png") main_theme = os.path.join("assets", "main theme.xml") main_console = os.path.join("assets", "consoles", "{}.png".format(self.system)) main_theme_dst = os.path.join(self.hs_path, "Media", "Main Menu", "Themes") temp_dir = os.path.join(main_theme_dst, self.system) if not os.path.isdir(temp_dir): os.makedirs(os.path.join(temp_dir)) if os.path.isfile(main_bg): shutil.copy(main_bg, os.path.join(temp_dir, "Background.png")) if os.path.isfile(main_theme): shutil.copy(main_theme, os.path.join(temp_dir, "Theme.xml")) if os.path.isfile(main_console): img = Image.open(main_console) if img.size[0] > 250: self.resize_width(src=main_console, dst=os.path.join(temp_dir, "Artwork2.png"), width=250) else: shutil.copy(main_console, os.path.join(temp_dir, "Artwork2.png")) if os.path.isfile(os.path.join(main_theme_dst, "{}.zip".format(self.system))): os.remove(os.path.join(main_theme_dst, "{}.zip".format(self.system))) c = Compressor(src_file=temp_dir) c.compress_dir(dst_file=os.path.join(main_theme_dst, "{}.zip".format(self.system))) msg = "Building System Theme for {}".format(self.system) logger.info(msg) system_bg = os.path.join("assets", "system background.png") system_theme = os.path.join("assets", "system theme.xml") system_logo_em = os.path.join(self.emu_movies_path, self.emu_movies_name, "System_Logo", "system_logo.png") system_logo = os.path.join(self.hs_path, "Media", "Main Menu", "Images", "Wheel", "{}.png".format(self.system)) system_theme_dst = os.path.join(self.hs_path, "Media", self.system, "Themes") temp_sys_dir = os.path.join(system_theme_dst, "_Temp") if not os.path.isdir(temp_sys_dir): os.makedirs(os.path.join(temp_sys_dir)) if os.path.isfile(system_bg): shutil.copy(system_bg, os.path.join(temp_sys_dir, "Background.png")) if os.path.isfile(system_theme): shutil.copy(system_theme, os.path.join(temp_sys_dir, "Theme.xml")) if os.path.isfile(system_logo_em): shutil.copy(system_logo_em, os.path.join(temp_sys_dir, "Artwork1.png")) elif os.path.isfile(system_logo): shutil.copy(system_logo, os.path.join(temp_sys_dir, "Artwork1.png")) if os.path.isfile(os.path.join(system_theme_dst, "default.zip".lower())): os.remove(os.path.join(system_theme_dst, "default.zip".lower())) c = Compressor(src_file=temp_sys_dir) c.compress_dir(dst_file=os.path.join(system_theme_dst, "Default.zip"))
def _extract_archive(self): """ "extract_archive" is a method that unzips the install archives for HyperSpin Args: self Returns: None Raises: None """ cf = Compressor(self.hyperspin_archive) cf.extract_all(self.hs_path) cf = Compressor(self.hyperspin_upgrade_archive) cf.extract_all(self.hs_path)
def _extract_archive(self): """ "extract_archive" is a method that unzips the archives Args: self Returns: None Raises: None """ cf = Compressor(self.rocket_launcher_archive) cf.extract_all(self.rl_path, password="******") cf = Compressor(self.rocket_launcher_media_archive) cf.extract_all(self.rl_path)
def __init__(self, system=None, name=None): Paths.__init__(self) Compressor.__init__(self, os.path.join(self.rom_path, system, name)) self.name = name self.system = system
def set_up_media(self, action="copy"): """ "set_up_media" copies any EmuMovies content into the appropriate folders in RocketLauncher, for Pause, Fade and etc. Args: "action" (optional, default=copy): Sets the action to take, [copy, move, link] Returns: None Raises: None """ xml = os.path.join(self.rl_path, "RocketLauncherUI", "Databases", self.system, self.system + ".xml") src_path = os.path.join(self.emu_movies_path, self.emu_movies_name) hs = Databases(system=self.system) header, db = hs.read_system_xml(db=xml) media_paths = os.listdir(src_path) # If Linking files, remove the old file before appending the new symlinks links = [] batch_file = os.path.join( self.temp_path, "{}_RL_Media_Links_run_as_Admin.bat".format(self.system)) if os.path.isfile(batch_file): os.remove(batch_file) for path in media_paths: src_dir = os.path.join(src_path, path) if action == "copy": msg = "Copying files from {}".format(src_dir) elif action == "move": msg = "Moving files from {}".format(src_dir) elif action == "link": msg = "Creating symbolic link from {}".format(src_dir) else: msg = "Action {} not permitted".format(action) logger.info(msg) files = os.listdir(src_dir) final_files = [] for rom in db: for file in files: if rom["name"] == os.path.basename( os.path.splitext(file)[0]): final_files.append(file) for file in final_files: file = os.path.splitext(file) if path == "Advert": dst = os.path.join(self.artwork_path, file[0], "Advertisement" + file[1]) elif path == "Artwork Preview": dst = os.path.join(self.artwork_path, file[0], "Preview" + file[1]) elif path == "Background": dst = os.path.join(self.backgrounds_path, file[0], "Background" + file[1]) elif path == "Banner": dst = os.path.join(self.artwork_path, file[0], "Banner" + file[1]) elif path == "Box": dst = os.path.join(self.artwork_path, file[0], "Box", "Box Art Front" + file[1]) elif path == "Box_3D": dst = os.path.join(self.artwork_path, file[0], "Box", "Box Art 3D" + file[1]) elif path == "Box_Full": dst = os.path.join(self.artwork_path, file[0], "Box", "Box Art Full" + file[1]) elif path == "Box_Spine": dst = os.path.join(self.artwork_path, file[0], "Box", "Box Art Spine" + file[1]) elif path == "BoxBack": dst = os.path.join(self.artwork_path, file[0], "Box", "Box Art Back" + file[1]) elif path == "Cart": dst = os.path.join(self.artwork_path, file[0], "Cartridge", "Cartridge" + file[1]) elif path == "Cart_3D": dst = os.path.join(self.artwork_path, file[0], "Cartridge", "Cartridge 3D" + file[1]) elif path == "CartTop": dst = os.path.join(self.artwork_path, file[0], "Cartridge", "Cartridge Top" + file[1]) elif path == "Cabinet": dst = os.path.join(self.artwork_path, file[0], "Cabinet" + file[1]) elif path == "CD": dst = os.path.join(self.artwork_path, file[0], "Media" + file[1]) elif path == "Controls": dst = os.path.join(self.controller_path, file[0], "Controls" + file[1]) elif path == "CP": dst = os.path.join(self.controller_path, file[0], "Control Panel" + file[1]) elif path == "Disc": dst = os.path.join(self.artwork_path, file[0], "Disc" + file[1]) elif path == "GameOver": dst = os.path.join(self.artwork_path, file[0], "Game Over" + file[1]) elif path == "Icon": dst = os.path.join(self.artwork_path, file[0], "Icon" + file[1]) elif path == "Logos": dst = os.path.join(self.logos_path, file[0], "Logo" + file[1]) elif path == "Map": dst = os.path.join(self.guides_path, file[0], "Map" + file[1]) elif path == "Marquee": dst = os.path.join(self.artwork_path, file[0], "Marquee" + file[1]) elif path == "Overlay": dst = os.path.join(self.artwork_path, file[0], "Overlay" + file[1]) elif path == "PCB": dst = os.path.join(self.artwork_path, file[0], "PCB" + file[1]) elif path == "Score": dst = os.path.join(self.artwork_path, file[0], "Score" + file[1]) elif path == "Select": dst = os.path.join(self.artwork_path, file[0], "Select" + file[1]) elif path == "Snap": dst = os.path.join(self.artwork_path, file[0], "Snapshot" + file[1]) elif path == "Title": dst = os.path.join(self.artwork_path, file[0], "Title Screen" + file[1]) elif path == "Manual": dst = os.path.join(self.manuals_path, file[0], "Game Manual" + file[1]) elif path == "Music": dst = os.path.join(self.music_path, file[0], file[0] + file[1]) elif path == "Video_Advert_MP4": dst = os.path.join(self.video_path, file[0], "Commercial" + file[1]) elif path == "Video_Review_MP4": dst = os.path.join(self.video_path, file[0], "Review" + file[1]) else: dst = "" src = os.path.join(src_dir, file[0] + file[1]) # Check if the file is the same by validating the CRC src_c = Compressor(src) src_crc = src_c.get_crc() try: dst_c = Compressor(dst) dst_crc = dst_c.get_crc() except FileNotFoundError: dst_crc = None try: if action == "copy": if dst_crc and src_crc[0]["crc"] != dst_crc[0][ "crc"]: # Check if CRCs Match if not os.path.exists(os.path.dirname(dst)): os.makedirs( os.path.dirname(dst) ) # Create directory path if it doesn't exist shutil.copy(src, dst) elif not dst_crc: if not os.path.exists(os.path.dirname(dst)): os.makedirs( os.path.dirname(dst) ) # Create directory path if it doesn't exist shutil.copy(src, dst) else: msg = "RL: {} CRCs match".format( os.path.basename(src)) logger.debug(msg) elif action == "move": if dst_crc and src_crc[0]["crc"] != dst_crc[0][ "crc"]: # Check if CRCs Match if not os.path.exists(os.path.dirname(dst)): os.makedirs( os.path.dirname(dst) ) # Create directory path if it doesn't exist shutil.copy(src, dst) elif dst_crc is None: if not os.path.exists(os.path.dirname(dst)): os.makedirs( os.path.dirname(dst) ) # Create directory path if it doesn't exist shutil.move(src, dst) else: msg = "RL: {} CRCs match".format( os.path.basename(src)) logger.debug(msg) elif action == "link": if not os.path.exists(os.path.dirname(dst)): os.makedirs( os.path.dirname(dst) ) # Create directory path if it doesn't exist links.append('mklink "{}" "{}"\n'.format(dst, src)) else: print("Action: {} not permitted".format(action)) except FileNotFoundError as e: msg = "RL: {} will not be moved: {}".format( file[0] + file[1], e) logger.info(msg) if len(links) > 0: with open(batch_file, mode="a") as f: for link in links: f.write(link)
def _copy_rom(self, src_file, rename=True, compress=True): """ "_copy_rom" is a method that will copy or extract the ROM file from its source to it's destination and rename the extension and re-compress Args: src_file: Dictionary of values that have the source, destination rename: Boolean, if true, renames the extension compress: Boolean, if true, compresses the file Returns: None Raises: None """ c = Compressor(src_file["src"]) try: c.extract(src_file["extract"], dst_dir=os.path.join(self.rom_path, self.system)) src = os.path.join(self.rom_path, self.system, src_file["extract"]) dst = os.path.join(self.rom_path, self.system, src_file["db_name"]) # Rename the ROM to the RocketLauncher Database Name os.rename(src, dst) # Compress if rename: r = Rom(name=dst, system=self.system) new_dst = r.rename_extension(self.extensions) if compress: c = Compressor(new_dst) c.compress(ext="zip") elif compress: c = Compressor(dst) c.compress(ext="zip") except FileExistsError: msg = "File Exists - {}".format(src_file["extract"]) logger.debug(msg)