You've already forked PythonLib
mirror of
https://github.com/lifebottle/PythonLib.git
synced 2026-02-13 15:25:50 -08:00
Rewrite iso extraction
Old code worried too much about all file systems, parsing udf works for our current purposes, also adds some fancy progress bars!
This commit is contained in:
@@ -1107,65 +1107,31 @@ class ToolsTales:
|
||||
|
||||
#Insert the text translated and repack the files at the correct place
|
||||
self.insertAll()
|
||||
|
||||
#
|
||||
def extract_Iso(self, umd_iso):
|
||||
|
||||
def extract_Iso(self, umd_iso: Path) -> None:
|
||||
|
||||
print("Extracting ISO files")
|
||||
print("Extracting ISO files...")
|
||||
|
||||
iso = pycdlib.PyCdlib()
|
||||
iso.open(umd_iso)
|
||||
start_path = "/"+os.path.dirname(umd_iso)
|
||||
extract_to = "../Data/{}/Disc/Original".format(self.repo_name)
|
||||
iso.open(str(umd_iso))
|
||||
|
||||
extract_to = Path(f"../Data/{self.repo_name}/Disc/Original/")
|
||||
shutil.rmtree(extract_to)
|
||||
os.mkdir(extract_to)
|
||||
pathname = ''
|
||||
if iso.has_udf():
|
||||
pathname = 'udf_path'
|
||||
elif iso.has_rock_ridge():
|
||||
pathname = 'rr_path'
|
||||
elif iso.has_joliet():
|
||||
pathname = 'joliet_path'
|
||||
else:
|
||||
pathname = 'iso_path'
|
||||
|
||||
root_entry = iso.get_record(**{pathname: start_path})
|
||||
|
||||
dirs = collections.deque([root_entry])
|
||||
while dirs:
|
||||
dir_record = dirs.popleft()
|
||||
ident_to_here = iso.full_path_from_dirrecord(dir_record,
|
||||
rockridge=pathname == 'rr_path')
|
||||
|
||||
if self.repo_name == "Tales-Of-Rebirth":
|
||||
relname = ident_to_here[1:]
|
||||
else:
|
||||
relname = ident_to_here[len(start_path):]
|
||||
|
||||
if relname and relname[0] == '/':
|
||||
relname = relname[1:]
|
||||
|
||||
if dir_record.is_dir():
|
||||
if relname != '':
|
||||
os.makedirs(os.path.join(extract_to, relname))
|
||||
child_lister = iso.list_children(**{pathname: ident_to_here})
|
||||
|
||||
for child in child_lister:
|
||||
if child is None or child.is_dot() or child.is_dotdot():
|
||||
continue
|
||||
dirs.append(child)
|
||||
else:
|
||||
if dir_record.is_symlink():
|
||||
fullpath = os.path.join(extract_to, relname)
|
||||
local_dir = os.path.dirname(fullpath)
|
||||
local_link_name = os.path.basename(fullpath)
|
||||
old_dir = os.getcwd()
|
||||
os.chdir(local_dir)
|
||||
os.symlink(dir_record.rock_ridge.symlink_path(), local_link_name)
|
||||
os.chdir(old_dir)
|
||||
else:
|
||||
iso.get_file_from_iso(os.path.join(extract_to, relname), **{pathname: ident_to_here})
|
||||
files = []
|
||||
for dirname, _, filelist in iso.walk(iso_path="/"):
|
||||
files += [dirname + x for x in filelist]
|
||||
|
||||
for file in files:
|
||||
out_path = extract_to / file[1:]
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with iso.open_file_from_iso(iso_path=file) as f, open(str(out_path).split(";")[0], "wb+") as output:
|
||||
with tqdm(total=f.length(), desc=f"Extracting {file[1:].split(';')[0]}", unit="B", unit_divisor=1024, unit_scale=True, leave=False) as pbar:
|
||||
while data := f.read(2048):
|
||||
output.write(data)
|
||||
pbar.update(len(data))
|
||||
|
||||
iso.close()
|
||||
|
||||
if self.repo_name == "Narikiri-Dungeon-X":
|
||||
|
||||
Reference in New Issue
Block a user