def extract_all(self): if self.file_widget.filename: out_dir = QtWidgets.QFileDialog.getExistingDirectory( self, 'Output folder', self.cfg.get("dir_extract", "C://"), ) if out_dir: self.cfg["dir_extract"] = out_dir # create output dir try: os.makedirs(out_dir, exist_ok=True) archive = self.ovl_data.ovs_files[0] error_files, skip_files = extract.extract( archive, out_dir, self.show_temp_files, progress_callback=self.update_progress) self.skip_messages(error_files, skip_files) self.update_progress("Operation completed!", value=1, vmax=1) except Exception as ex: traceback.print_exc() widgets.showdialog(str(ex)) print(ex) else: widgets.showdialog( "You must open an OVL file before you can extract files!")
def load(self): if self.file_widget.filepath: self.file_widget.dirty = False start_time = time.time() self.update_progress("Reading OVL " + self.file_widget.filepath, value=0, vmax=0) try: self.ovl_data.load(self.file_widget.filepath, commands=self.commands, hash_table=self.hash_table) except Exception as ex: traceback.print_exc() widgets.showdialog(str(ex)) print(ex) data = [] # dic = {} print(f"Loading {len(self.ovl_data.files)} files into gui...") for file_w in self.ovl_data.files: name = f"{file_w.name}.{file_w.ext}" line = [ name, file_w.ext, to_hex_str(file_w.file_hash), str(file_w.unkn_0), str(file_w.unkn_1) ] data.append(line) # dic[file_w.file_hash] = name # print(dic) # print(self.ovl_data) print("loading gui") self.table.set_data(data) print(f"Done in {time.time()-start_time:.2f} seconds!") self.update_progress("Operation completed!", value=1, vmax=1)
def hasher(self): if self.ovl_name: names = [ (tup[0].text(), tup[1].text()) for tup in self.e_name_pairs ] for archive in self.ovl_data.archives: hasher.dat_hasher(archive, names, self.ovl_data.header.files,self.ovl_data.header.textures) else: widgets.showdialog( "You must open an OVL file before you can extract files!" )
def check_version(): is_64bits = sys.maxsize > 2**32 if not is_64bits: widgets.showdialog( "Either your operating system or your python installation is not 64 bits.\n" "Large OVLs will crash unexpectedly!") if sys.version_info[0] != 3 or sys.version_info[1] < 7 or ( sys.version_info[1] == 7 and sys.version_info[2] < 6): widgets.showdialog("Python 3.7.6+ x64 bit is expected!")
def inject_text(self): if self.ovl_name: source_path = QtWidgets.QFileDialog.getOpenFileName(self, "Inject text", filter="Text files (*.txt)")[0] if source_path: try: inject.inject_localization(self.ovl_data, source_path) except Exception as ex: traceback.print_exc() widgets.showdialog(str(ex)) print(ex) else: widgets.showdialog( "You must open an OVL file before you can inject text!" )
def extract_text(self): if self.ovl_name: target_path = QtWidgets.QFileDialog.getSaveFileName(self, 'Save text', filter="Text files (*.txt)")[0] if target_path: try: extract.extract_for_localization(self.ovl_data.archives, target_path) except Exception as ex: traceback.print_exc() widgets.showdialog( str(ex) ) print(ex) else: widgets.showdialog( "You must open an OVL file before you can extract text!")
def write(self): file_out = QtWidgets.QFileDialog.getSaveFileName(self, 'Save Average EQ', self.cfg["dir_out"], "XML files (*.xml)")[0] file_base = ".".join(file_out.split(".")[:-1]) if file_out: try: self.cfg["dir_out"], eq_name = os.path.split(file_out) write_eq_xml(file_base+"_AV.xml", self.freqs_av, np.mean(self.av, axis=0)) write_eq_xml(file_base+"_L.xml", self.freqs_av, self.av[0]) write_eq_xml(file_base+"_R.xml", self.freqs_av, self.av[1]) write_eq_txt(file_base+".txt", self.freqs_av, np.mean(self.av, axis=0)) except PermissionError: widgets.showdialog("Could not write files - do you have writing permissions there?")
def inject(self): if self.ovl_name: files = QtWidgets.QFileDialog.getOpenFileNames(self, 'Inject files', self.cfg["dir_inject"], self.filter)[0] if files: self.cfg["dir_inject"] = os.path.dirname(files[0]) try: inject.inject( self.ovl_data, files, self.write_dds ) self.file_widget.dirty = True except Exception as ex: traceback.print_exc() widgets.showdialog( str(ex) ) print("Done!") else: widgets.showdialog( "You must open an OVL file before you can inject files!" )
def load_ovl(self): if self.file_widget.filepath: self.file_widget.dirty = False self.cfg["dir_ovls_in"], ovl_name = os.path.split(self.file_widget.filepath) start_time = time.time() try: with open(self.file_widget.filepath, "rb") as ovl_stream: self.ovl_data.read(ovl_stream, file=self.file_widget.filepath, commands=self.commands) self.file_widget.setText(ovl_name) except Exception as ex: traceback.print_exc() widgets.showdialog( str(ex) ) print(ex) print(f"Done in {time.time()-start_time:.2f} seconds!")
def skip_messages(self, error_files, skip_files): error_count = len(error_files) skip_count = len(skip_files) if error_count: print("Files not extracted due to error:") for ef in error_files: print("\t", ef) if skip_count: print("Unsupported files not extracted:") for sf in skip_files: print("\t", sf) if error_count or skip_count: message = f"{error_count + skip_count} files were not extracted from the archive and may be missing from the output folder. {skip_count} were unsupported, while {error_count} produced errors." widgets.showdialog(message)
def load_fgm(self): if self.file_src: for w in self.widgets: w.deleteLater() self.cfg["dir_fgms_in"], fgm_name = os.path.split(self.file_src) try: with open(self.file_src, "rb") as fgm_stream: self.fgm_data.read(fgm_stream, file=self.file_src) game = self.fgm_data.game print("from game", game) self.game_container.entry.setText(game) # also for self.game_changed() self.fgm_container.entry.setText(fgm_name) self.shader_container.entry.setText(self.fgm_data.shader_name) # delete existing widgets self.clear_layout(self.tex_grid) self.clear_layout(self.attrib_grid) self.tex_grid = self.create_grid() self.attrib_grid = self.create_grid() self.tex_container.setLayout(self.tex_grid) self.attrib_container.setLayout(self.attrib_grid) line_i = 0 for tex in self.fgm_data.fgm_header.textures: w = widgets.VectorEntry(tex, self.tooltips) # form.addRow(w.label, w.data) # w = QtWidgets.QLabel(tex.name) # self.tex_grid.addWidget(w, line_i, 0) self.tex_grid.addWidget(w.label, line_i, 0) self.tex_grid.addWidget(w.data, line_i, 1) line_i += 1 line_i = 0 for attrib in self.fgm_data.fgm_header.attributes: w = widgets.VectorEntry(attrib, self.tooltips) self.attrib_grid.addWidget(w.label, line_i, 0) self.attrib_grid.addWidget(w.data, line_i, 1) line_i += 1 except Exception as ex: widgets.showdialog(str(ex)) print(ex) print("Done!")
def extract_all(self): if self.ovl_name: self.cfg["dir_extract"] = QtWidgets.QFileDialog.getExistingDirectory(self, 'Output folder', self.cfg["dir_extract"], ) if self.cfg["dir_extract"]: dir = self.cfg["dir_extract"] # create output dir try: os.makedirs(dir, exist_ok=True) for archive in self.ovl_data.archives: archive.dir = dir extract.extract(archive, self.write_dds) print("Done!") except Exception as ex: traceback.print_exc() widgets.showdialog( str(ex) ) print(ex) else: widgets.showdialog( "You must open an OVL file before you can extract files!" )
def extract_names(archive, names, out_dir, show_temp_files=False, progress_callback=None): def out_dir_func(n): """Helper function to generate temporary output file name""" return os.path.normpath(os.path.join(out_dir, n)) print("Extracting by name...") # the temporary file paths that are passed to windows to move the files to their final destination paths = [] print("\nExtracting from archive", archive.archive_index) entry_dict = {entry.name: entry for entry in archive.sized_str_entries} # export all selected files for file_index, file in enumerate(names): print(file_index, file) basename, ext = os.path.splitext(file) if ext[1:] in IGNORE_TYPES: print(f"Ignoring {file}, as it is not a standalone file!") continue if file in entry_dict: print("Found name", file) entry = entry_dict[file] try: extract_kernel(paths, entry, archive, out_dir_func, show_temp_files, progress_callback) except BaseException as error: print(f"\nAn exception occurred while extracting {entry.name}") traceback.print_exc() widgets.showdialog(str(error)) else: print(f"ERROR: file {file} not found in archive") if progress_callback: progress_callback(f"Extracting {file}", value=file_index + 1, vmax=len(names)) return paths
def load_ovl(self): if self.file_widget.filepath: self.file_widget.dirty = False self.cfg["dir_ovls_in"], ovl_name = os.path.split( self.file_widget.filepath) start_time = time.time() self.update_progress("Reading OVL " + self.file_widget.filepath, value=0, vmax=0) try: with open(self.file_widget.filepath, "rb") as ovl_stream: self.ovl_data.read(ovl_stream, file=self.file_widget.filepath, commands=self.commands) self.file_widget.setText(ovl_name) except Exception as ex: traceback.print_exc() widgets.showdialog(str(ex)) print(ex) print(f"Done in {time.time()-start_time:.2f} seconds!") self.update_progress("Operation completed!", value=1, vmax=1)
def extract_all(self): if self.ovl_name: self.cfg[ "dir_extract"] = QtWidgets.QFileDialog.getExistingDirectory( self, 'Output folder', self.cfg["dir_extract"], ) if self.cfg["dir_extract"]: dir = self.cfg["dir_extract"] # create output dir try: os.makedirs(dir, exist_ok=True) error_files = [] skip_files = [] da_max = len(self.ovl_data.archives) for da_index, archive in enumerate(self.ovl_data.archives): self.update_progress("Extracting archives", value=da_index, vmax=da_max) archive.dir = dir error_files_new, skip_files_new = extract.extract( archive, self.write_dds, progress_callback=self.update_progress) error_files += error_files_new skip_files += skip_files_new self.skip_messages(error_files, skip_files) self.update_progress("Operation completed!", value=1, vmax=1) except Exception as ex: traceback.print_exc() widgets.showdialog(str(ex)) print(ex) else: widgets.showdialog( "You must open an OVL file before you can extract files!")
def load(self): if self.file_widget.filepath: for w in self.widgets: w.deleteLater() try: self.fgm_data.load(self.file_widget.filepath) game = get_game(self.fgm_data) print("from game", game) self.game_container.entry.setText(game) # also for self.game_changed() self.shader_container.entry.setText(self.fgm_data.shader_name) # delete existing widgets self.clear_layout(self.tex_grid) self.clear_layout(self.attrib_grid) self.tex_grid = self.create_grid() self.attrib_grid = self.create_grid() self.tex_container.setLayout(self.tex_grid) self.attrib_container.setLayout(self.attrib_grid) for line_i, tex in enumerate(self.fgm_data.textures): w = widgets.VectorEntry(tex, self.tooltips) self.tex_grid.addWidget(w.delete, line_i, 0) self.tex_grid.addWidget(w.label, line_i, 1) self.tex_grid.addWidget(w.data, line_i, 2) for line_i, attrib in enumerate(self.fgm_data.attributes): w = widgets.VectorEntry(attrib, self.tooltips) self.attrib_grid.addWidget(w.delete, line_i, 0) self.attrib_grid.addWidget(w.label, line_i, 1) self.attrib_grid.addWidget(w.data, line_i, 2) except Exception as ex: widgets.showdialog(str(ex)) print(ex) print("Done!")
def load_materialcollection(self): if self.file_src: for w in self.widgets: w.deleteLater() self.cfg["dir_materialcollections_in"], materialcollection_name = os.path.split(self.file_src) try: self.matcol_data.load(self.file_src) game = self.matcol_data.game print("from game", game) self.game_container.entry.setText(game) self.materialcollection_container.entry.setText( materialcollection_name ) # delete existing widgets self.clear_layout(self.tex_grid) self.clear_layout(self.attrib_grid) self.tex_grid = self.create_grid() self.attrib_grid = self.create_grid() self.tex_container.setLayout(self.tex_grid) self.attrib_container.setLayout(self.attrib_grid) line_i = 0 for i, tex in enumerate(self.matcol_data.texture_wrapper.textures): # w = widgets.VectorEntry(tex, self.tooltips) # form.addRow(w.label, w.data) box = widgets.CollapsibleBox(f"Slot {i}") # box = QtWidgets.QGroupBox(f"Slot {i}") self.tex_grid.addWidget(box, line_i, 0) line_i += 1 lay = self.create_grid() a = QtWidgets.QLabel("texture type") b = QtWidgets.QLabel("texture suffix") x = QtWidgets.QLineEdit(tex.texture_type) y = QtWidgets.QLineEdit(tex.texture_suffix) combo = widgets.LabelCombo("First FGM:", self.default_fgms, tex, "fgm_name") lay.addWidget(a, 0, 0) lay.addWidget(b, 1, 0) lay.addWidget(x, 0, 1) lay.addWidget(y, 1, 1) lay.addWidget(combo.label, 2, 0) lay.addWidget(combo.entry, 2, 1) box.setLayout(lay) line_i = 0 for i, attrib in enumerate(self.matcol_data.layered_wrapper.layers): box = widgets.CollapsibleBox(f"Slot {i}") # box = QtWidgets.QGroupBox(attrib.name) self.attrib_grid.addWidget(box, line_i, 0) line_i += 1 lay = self.create_grid() combo = widgets.LabelCombo("FGM:", self.default_fgms, attrib, "name") lay.addWidget(combo.label, 0, 0) lay.addWidget(combo.entry, 0, 1) l = 1 for infow in attrib.infos: w = widgets.MatcolInfo(infow, self.tooltips) lay.addWidget(w.label, l, 0) lay.addWidget(w.data, l, 1) l+=1 box.setLayout(lay) line_i = 0 for zstr in self.matcol_data.variant_wrapper.materials: a = QtWidgets.QLabel("variant fgm") b = QtWidgets.QLineEdit(zstr) self.attrib_grid.addWidget(a, line_i, 0) self.attrib_grid.addWidget(b, line_i, 1) line_i += 1 except Exception as ex: widgets.showdialog(str(ex)) print(traceback.print_exc()) print("Done!")