Skip to content

Commit

Permalink
Support drag-and-drop opening .szs and .szp compressed RARCs
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Dec 26, 2024
1 parent 34dc573 commit 9b8ed36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gcft_ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import yaml

GCM_FILE_EXTS = [".iso", ".gcm"]
RARC_FILE_EXTS = [".arc"]
# RARC_FILE_EXTS = [".arc"] # Has special logic to check .szs and .szp in addition to .arc
BTI_FILE_EXTS = [".bti"]
J3D_FILE_EXTS = [
".bmd",
Expand Down Expand Up @@ -105,7 +105,7 @@ def get_open_func_and_tab_name_for_file_path(self, file_path):

if file_ext in GCM_FILE_EXTS:
return (self.gcm_tab.import_gcm_by_path, "GCM ISOs")
elif file_ext in RARC_FILE_EXTS:
elif self.rarc_tab.check_file_path_is_rarc(file_path):
return (self.rarc_tab.import_rarc_by_path, "RARC Archives")
elif file_ext in BTI_FILE_EXTS:
return (self.bti_tab.import_bti_by_path, "BTI Images")
Expand Down
28 changes: 28 additions & 0 deletions gcft_ui/rarc_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,34 @@ def remove_folder_from_files_tree(self, dir_entry: RARCFileEntry):
# When removing one row, the model automatically takes care of recursively deleting all children.
parent_dir_item.removeRow(dir_item.index().row())

# See: GCM.check_file_is_rarc
def check_file_path_is_rarc(self, file_path: str) -> bool:
try:
_, file_ext = os.path.splitext(os.path.basename(file_path))
if file_ext == ".arc":
with open(file_path, "rb") as f:
file_data = BytesIO(f.read(4))
if RARC.check_file_is_rarc(file_data):
return True
elif file_ext == ".szs":
with open(file_path, "rb") as f:
file_data = BytesIO(f.read(0x15))
if Yaz0.check_is_compressed(file_data):
magic = fs.read_str(file_data, 0x11, 4)
if magic == "RARC":
return True
elif file_ext == ".szp":
with open(file_path, "rb") as f:
file_data = BytesIO(f.read())
if Yay0.check_is_compressed(file_data):
chunk_offset = fs.read_u32(file_data, 0xC)
magic = fs.read_str(file_data, chunk_offset, 4)
if magic == "RARC":
return True
except Exception as e:
pass
return False


def rarc_file_tree_item_changed(self, top_left_index: QModelIndex, bottom_right_index: QModelIndex):
if top_left_index != bottom_right_index:
Expand Down

0 comments on commit 9b8ed36

Please sign in to comment.