Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bulk RARC import support #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gcft_ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def get_open_func_and_tab_name_for_file_path(self, file_path):
return (self.gcm_tab.import_gcm_by_path, "GCM ISOs")
elif file_ext in RARC_FILE_EXTS:
return (self.rarc_tab.import_rarc_by_path, "RARC Archives")
elif os.path.isdir(file_path):
return (self.rarc_tab.import_all_rarcs_from_folder, "RARC Archives")
elif file_ext in BTI_FILE_EXTS:
return (self.bti_tab.import_bti_by_path, "BTI Images")
elif file_ext in [".png"]:
Expand Down
94 changes: 94 additions & 0 deletions gcft_ui/rarc_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,100 @@ def extract_all_files_from_rarc_folder(self):
file_type="RARC"
)


def import_all_rarcs_from_folder(
self,
folder_of_rarcs_path,
recursive=True,
base_path="",
debug=True, rtn_counter=False,
swallow_assertion_errors=True
):

NO_RECURSION_DIRECTORIES = ["GCFTUnpacked","HomeBTN","\\res\\HomeBTN"] # FIles in HomeBTN throws some strange AssertionError
DrewWing marked this conversation as resolved.
Show resolved Hide resolved
item_counter = 0

#if base_path != "":
# # This is a recursion
# #if debug:
# # print("| "*recursion_guess+f"Base path is still {base_path}")
if base_path == "":
base_path = folder_of_rarcs_path

if not os.path.isdir(base_path+"\\GCFTUnpacked"):
os.mkdir(base_path+"\\GCFTUnpacked")

subfolder_path = folder_of_rarcs_path.replace(base_path,"")
recursion_guess = subfolder_path.count("\\") + 1
#print('subfolder path: '+str(subfolder_path))

if debug:
print("| "*recursion_guess+"Importing all rarcs from a folder.")
print("| "*recursion_guess+f"Path: {folder_of_rarcs_path}")


for object in os.listdir(folder_of_rarcs_path):
object_path = folder_of_rarcs_path+"\\"+object


if debug:
print("| "*recursion_guess+" - Object "+subfolder_path+"\\"+object, end='')

file_ext = os.path.splitext(object)[1]

if os.path.isdir(object_path) and recursive and not (object in NO_RECURSION_DIRECTORIES):
if debug:
print(" Folder found. Making directory and recursing...")

os.mkdir(base_path+"\\GCFTUnpacked"+subfolder_path+"\\"+object) # make copy directory in the unpacked section

item_counter += self.import_all_rarcs_from_folder(object_path, base_path=base_path, debug=debug, rtn_counter=True)

elif (not os.path.isdir(object_path)) and (file_ext in [".arc"]):
item_counter += 1

if debug:
print(" Valid RARC found. Importing. ",end='')
#extract and export
try:
self.import_rarc_by_path(object_path)

except AssertionError as e:
print("!!! Some assertion error occured while importing RARC file!!! "+str(e))
if not swallow_assertion_errors:
raise e

else:
return 1 # Needed to stop the extracting, otherwise more errors crop up

if debug:
print("Extracting. ")
#input(base_path+"\\GCFTUnpacked\\"+object)
#self.extract_all_files_from_rarc()

#print("new path: "+str(new_path))
export_path = base_path+"\\GCFTUnpacked"+subfolder_path+"\\"+object

#print("export path: "+str(export_path))
#self.extract_all_files_from_rarc_folder()

#node = self.ui.actionExtractAllFilesFromRARCFolder.data()
self.rarc.extract_all_files_to_disk(export_path)
#self.extract_all_files_from_rarc_folder_by_path(base_path+"\\GCFTUnpacked\\"+object)

elif debug:
print()

# If this is the "main" thread - not inside of a recursion
if base_path == folder_of_rarcs_path and debug:
print(f" -- Successfully de-RARC'd {item_counter} files. --")

if rtn_counter:
return item_counter




def dump_all_rarc_textures(self):
self.window().generic_do_gui_file_operation(
op_callback=self.dump_all_rarc_textures_by_path,
Expand Down